feat: bandwidth stats

Fixes #2935
This commit is contained in:
Richard Ramos 2021-07-23 11:08:52 -04:00 committed by Iuri Matias
parent 544b0aafc7
commit eb9734a72d
11 changed files with 166 additions and 28 deletions

View File

@ -32,4 +32,7 @@ proc init*(self: NodeController) =
self.status.events.on(SignalType.DiscoverySummary.event) do(e:Args):
self.status.network.peerSummaryChange(DiscoverySummarySignal(e).enodes)
self.status.events.on(SignalType.Stats.event) do (e:Args):
self.view.setStats(StatsSignal(e).stats)
self.view.init()

View File

@ -1,5 +1,6 @@
import NimQml, chronicles, strutils, json
import ../../status/[status, node, types, settings, accounts]
import ../../status/signals/types as signal_types
logScope:
topics = "node-view"
@ -11,6 +12,7 @@ QtObject:
lastMessage*: string
wakuBloomFilterMode*: bool
fullNode*: bool
stats*: Stats
proc setup(self: NodeView) =
self.QObject.setup
@ -122,4 +124,22 @@ QtObject:
let statusGoResult = self.status.settings.setBloomLevel(BloomFilterMode, FullNode)
if statusGoResult.error != "":
error "Error saving updated node config", msg=statusGoResult.error
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
proc statsChanged*(self: NodeView) {.signal.}
proc setStats*(self: NodeView, stats: Stats) =
self.stats = stats
self.statsChanged()
proc uploadRate*(self: NodeView): string {.slot.} = $self.stats.uploadRate
QtProperty[string] uploadRate:
read = uploadRate
notify = statsChanged
proc downloadRate*(self: NodeView): string {.slot.} = $self.stats.downloadRate
QtProperty[string] downloadRate:
read = downloadRate
notify = statsChanged

View File

@ -1,6 +1,6 @@
import NimQml, tables, json, chronicles, strutils, json_serialization
import ../types as status_types
import types, messages, discovery, whisperFilter, envelopes, expired, wallet, mailserver, communities
import types, messages, discovery, whisperFilter, envelopes, expired, wallet, mailserver, communities, stats
import ../status
import ../../eventemitter
@ -57,6 +57,7 @@ QtObject:
of SignalType.MailserverRequestCompleted: mailserver.fromCompletedEvent(jsonSignal)
of SignalType.MailserverRequestExpired: mailserver.fromExpiredEvent(jsonSignal)
of SignalType.CommunityFound: communities.fromEvent(jsonSignal)
of SignalType.Stats: stats.fromEvent(jsonSignal)
else: Signal()
if(signalType == SignalType.NodeLogin):

View File

@ -0,0 +1,13 @@
import json
import types
proc toStats(jsonMsg: JsonNode): Stats =
result = Stats(
uploadRate: uint64(jsonMsg{"uploadRate"}.getBiggestInt()),
downloadRate: uint64(jsonMsg{"downloadRate"}.getBiggestInt())
)
proc fromEvent*(event: JsonNode): Signal =
var signal:StatsSignal = StatsSignal()
signal.stats = event["event"].toStats
result = signal

View File

@ -66,3 +66,10 @@ type WhisperFilterSignal* = ref object of Signal
type DiscoverySummarySignal* = ref object of Signal
enodes*: seq[string]
type Stats* = object
uploadRate*: uint64
downloadRate*: uint64
type StatsSignal* = ref object of Signal
stats*: Stats

View File

@ -24,6 +24,7 @@ type SignalType* {.pure.} = enum
SubscriptionsError = "subscriptions.error"
WhisperFilterAdded = "whisper.filter.added"
CommunityFound = "community.found"
Stats = "stats"
Unknown
proc event*(self:SignalType):string =

View File

@ -3,6 +3,8 @@ import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import "../../../imports"
import "../../../shared"
import "../../../shared/status"
Item {
id: nodeView
@ -14,6 +16,10 @@ Item {
spacing: 0
anchors.fill: parent
Rate {
}
ColumnLayout {
id: messageContainer
Layout.fillHeight: true

View File

@ -0,0 +1,78 @@
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import "../../../imports"
import "../../../shared"
import "../../../shared/status"
Column {
spacing: 0
StatusSectionHeadline {
text: qsTr("Bandwidth")
topPadding: Style.current.bigPadding
bottomPadding: Style.current.padding
}
Row {
width: parent.width
spacing: 10
StyledText {
text: "Upload"
width: 250
anchors.verticalCenter: parent.verticalCenter
}
Item {
width: 140
height: 44
Input {
id: uploadRate
text: Math.round(parseInt(nodeModel.uploadRate, 10) / 1024 * 100) / 100
width: parent.width
readOnly: true
customHeight: 44
placeholderText: "0"
anchors.top: parent.top
}
StyledText {
color: Style.current.secondaryText
text: qsTrId("Kb/s")
anchors.verticalCenter: parent.verticalCenter
anchors.right: uploadRate.right
anchors.rightMargin: Style.current.padding
font.pixelSize: 15
}
}
StyledText {
text: "Download"
width: 273
anchors.verticalCenter: parent.verticalCenter
}
Item {
width: 140
height: 44
Input {
id: downloadRate
text: Math.round(parseInt(nodeModel.downloadRate, 10) / 1024 * 100) / 100
width: parent.width
readOnly: true
customHeight: 44
placeholderText: "0"
anchors.top: parent.top
}
StyledText {
color: Style.current.secondaryText
text: qsTrId("Kb/s")
anchors.verticalCenter: parent.verticalCenter
anchors.right: downloadRate.right
anchors.rightMargin: Style.current.padding
font.pixelSize: 15
}
}
}
}

View File

@ -125,6 +125,21 @@ Item {
}
}
StatusSettingsLineButton {
//% "Node Management"
text: qsTrId("node-management")
isSwitch: true
switchChecked: appSettings.nodeManagementEnabled
onClicked: {
if (!appSettings.nodeManagementEnabled) {
confirmationPopup.settingsProp = "nodeManagementEnabled"
confirmationPopup.open()
} else {
appSettings.nodeManagementEnabled = false
}
}
}
StatusSettingsLineButton {
id: onlineUsers
//% "Online users"
@ -153,6 +168,16 @@ Item {
}
}
StatusSettingsLineButton {
//% "GIF Widget"
text: qsTrId("gif-widget")
isSwitch: true
switchChecked: appSettings.isGifWidgetEnabled
onClicked: {
appSettings.isGifWidgetEnabled = !appSettings.isGifWidgetEnabled
}
}
StatusSectionHeadline {
//% "Bloom filter level"
text: qsTrId("bloom-filter-level")
@ -236,31 +261,6 @@ Item {
}
}
}
StatusSettingsLineButton {
//% "GIF Widget"
text: qsTrId("gif-widget")
isSwitch: true
switchChecked: appSettings.isGifWidgetEnabled
onClicked: {
appSettings.isGifWidgetEnabled = !appSettings.isGifWidgetEnabled
}
}
// StatusSettingsLineButton {
// //% "Node Management"
// text: qsTrId("node-management")
// isSwitch: true
// switchChecked: appSettings.nodeManagementEnabled
// onClicked: {
// if (!appSettings.nodeManagementEnabled) {
// confirmationPopup.settingsProp = "nodeManagementEnabled"
// confirmationPopup.open()
// } else {
// appSettings.nodeManagementEnabled = false
// }
// }
// }
}
NetworksModal {

View File

@ -230,6 +230,15 @@ StatusAppLayout {
onClicked: appMain.changeAppSection(Constants.timeline)
},
StatusNavBarTabButton {
enabled: isExperimental === "1" || appSettings.nodeManagementEnabled
visible: enabled
tooltip.text: qsTr("Node Management")
icon.name: "node"
checked: appView.currentIndex == Utils.getAppSectionIndex(Constants.node)
onClicked: appMain.changeAppSection(Constants.node)
},
StatusNavBarTabButton {
id: profileBtn
//% "Profile"

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 151edb36077cdbb9f1f2b89f32cd939ee873ed98
Subproject commit cdc7c5503001e2c987cf657dc707a3da81ea397e