admin/monitoring: tooltip for the sent/got display #608
Massimo Melina committed
Jun 8, 2024 at 16:16 UTC
438a3cde2d03b7ea25074e73d2898346e8639c69
4 files changed
+10
-6
admin/src/MonitorPage.ts
+1
@@ -43,6 +43,7 @@ function MoreInfo() {
43
}),
44
(allInfo || sm) && pair('sent_got', {
45
render: x => ({ Sent: formatBytes(x[0]), Got: formatBytes(x[1]) }),
46
+ title: x => "Since: " + formatTimestamp(x[2]),
47
onDelete: () => apiCall('clear_persistent', { k: ['totalSent', 'totalGot'] })
48
.then(() => alertDialog("Done", 'success'), alertDialog)
49
}),
package.json
+1
-1
@@ -71,7 +71,7 @@
71
"dependencies": {
72
"@koa/router": "^12.0.1",
73
"@node-rs/crc32": "^1.6.0",
74
- "@rejetto/kvstorage": "^0.9.3",
74
+ "@rejetto/kvstorage": "^0.9.7",
75
"acme-client": "^5.2.0",
76
"basic-auth": "^2.0.1",
77
"buffer-crc32": "^0.2.13",
src/api.monitor.ts
+4
-1
@@ -87,7 +87,7 @@ export default {
87
yield {
88
outSpeed: totalOutSpeed,
89
inSpeed: totalInSpeed,
90
- sent_got: [totalSent.get(), totalGot.get()],
90
+ sent_got: [totalSent.get(), totalGot.get(), totalGotSentResetTime.get()],
91
connections: filtered.length,
92
ips: _.uniqBy(filtered, x => x.ip).length,
93
}
@@ -97,6 +97,7 @@ export default {
97
98
async clear_persistent({ k }) {
99
apiAssertTypes({ string_array: { k } })
100
+ totalGotSentResetTime.set(new Date)
101
for (const x of wantArray(k))
102
void storedMap.del(x)
103
},
@@ -113,3 +114,5 @@ function getConnAddress(conn: Connection) {
114
port: conn.socket.remotePort,
115
}
116
}
117
+
118
+const totalGotSentResetTime = storedMap.singleSync<Date>('totalGotSentResetTime', new Date)
src/throttler.ts
+4
-4
@@ -65,7 +65,7 @@ export const throttler: Koa.Middleware = async (ctx, next) => {
65
conn[SymTimeout] = setTimeout(update, DELAY)
66
}, DELAY, { leading: true, maxWait:DELAY })
67
ts.on('sent', (n: number) => {
68
- totalSent.set(x => (x || 0) + n)
68
+ totalSent.set(x => x + n)
69
update()
70
})
71
@@ -97,8 +97,8 @@ export function roundSpeed(n: number) {
97
return _.round(n, 1) || _.round(n, 3) // further precision if necessary
98
}
99
100
-export let totalSent = storedMap.singleSync<number>('totalSent', 0)
101
-export let totalGot = storedMap.singleSync<number>('totalGot', 0)
100
+export const totalSent = storedMap.singleSync<number>('totalSent', 0)
101
+export const totalGot = storedMap.singleSync<number>('totalGot', 0)
102
export let totalOutSpeed = 0
103
export let totalInSpeed = 0
104
@@ -123,4 +123,4 @@ setInterval(() => {
123
124
events.on('connection', (c: Connection) =>
125
c.socket.on('data', data =>
126
- totalGot.set(x => (x || 0) + data.length) ))
126
+ totalGot.set(x => x + data.length) ))