summaryrefslogtreecommitdiffstats
path: root/static
diff options
context:
space:
mode:
authorUdo Walter2019-02-26 16:55:48 +0100
committerUdo Walter2019-02-26 16:55:48 +0100
commit654491988174d6e921d95269aa29494d5fee4dbd (patch)
tree8671fde2d2ccb6c546456bc14e70827281a57981 /static
parenttable.html: fix ?peak not working (diff)
downloaddnbd3-status-654491988174d6e921d95269aa29494d5fee4dbd.tar.gz
dnbd3-status-654491988174d6e921d95269aa29494d5fee4dbd.tar.xz
dnbd3-status-654491988174d6e921d95269aa29494d5fee4dbd.zip
table.html: fix everthing not working
Diffstat (limited to 'static')
-rw-r--r--static/table.html35
1 files changed, 17 insertions, 18 deletions
diff --git a/static/table.html b/static/table.html
index 83b8a39..3ff7a0c 100644
--- a/static/table.html
+++ b/static/table.html
@@ -133,11 +133,9 @@ var app = new Vue({
this.rawData.servers.forEach(serverData => {
// Update server
var server = this.serverMap[serverData.address]
- if (server) {
- Object.assign(server, serverData)
- } else {
+ if (!server) {
server = {
- ...serverData,
+ address: serverData.address,
log: [],
clientMap: {},
graphColor: this.graphColors.shift(),
@@ -146,19 +144,18 @@ var app = new Vue({
Vue.set(this.serverMap, serverData.address, server)
this.smoothie.addTimeSeries(server.graphLine, { lineWidth: 2, strokeStyle: server.graphColor })
}
- server.log.push(server)
- this.calcSpeed(server)
+ server.log.push(serverData)
+ this.calcSpeed(server, serverData)
server.graphLine.append(server.timestamp, server.uploadSpeed)
// Update clients
serverData.clients.forEach(clientData => {
clientData.timestamp = server.timestamp
var client = server.clientMap[clientData.address]
- if (client) server.clientMap[clientData.address] = { ...client, ...clientData }
- else Vue.set(server.clientMap, clientData.address, { ...clientData, log: [] })
+ if (!client) Vue.set(server.clientMap, clientData.address, { log: [] })
client = server.clientMap[clientData.address]
- client.log.push(client)
- this.calcSpeed(client)
+ client.log.push(clientData)
+ this.calcSpeed(client, clientData)
})
})
}
@@ -187,26 +184,28 @@ var app = new Vue({
this.rawData = await response.json()
setTimeout(this.updateData, 2000)
},
- calcSpeed (obj) {
+ calcSpeed (obj, objData) {
// Need a minimum of two values to calculate the speed
- if (obj.log.length <= 1) return
+ if (obj.log.length <= 1) return
// Calculate current speeds
var a = obj.log[obj.log.length - 2]
const b = obj.log[obj.log.length - 1]
var time = (b.timestamp - a.timestamp) / 1000
- obj.uploadSpeed = (b.bytesSent - a.bytesSent) / time
- obj.downloadSpeed = (b.bytesReceived - a.bytesReceived) / time
+ objData.uploadSpeed = (b.bytesSent - a.bytesSent) / time
+ objData.downloadSpeed = (b.bytesReceived - a.bytesReceived) / time
// Calculate peak speeds
- obj.peakUploadSpeed = Math.max(...obj.log.map(x => x.uploadSpeed || 0))
- obj.peakDownloadSpeed = Math.max(...obj.log.map(x => x.downloadSpeed || 0))
+ objData.peakUploadSpeed = Math.max(...obj.log.map(x => x.uploadSpeed || 0))
+ objData.peakDownloadSpeed = Math.max(...obj.log.map(x => x.downloadSpeed || 0))
// Calculate average speeds
a = obj.log[0]
time = (b.timestamp - a.timestamp) / 1000
- obj.avgUploadSpeed = (b.bytesSent - a.bytesSent) / time
- obj.avgDownloadSpeed = (b.bytesReceived - a.bytesReceived) / time
+ objData.avgUploadSpeed = (b.bytesSent - a.bytesSent) / time
+ objData.avgDownloadSpeed = (b.bytesReceived - a.bytesReceived) / time
+
+ Object.assign(obj, objData)
},
formatBytes (bytes) {
if (bytes < 1024) return bytes.toFixed(2) + ' B'