@samitouri / QOSami-HFS / commits / 1f704ec4

CLI: status

Massimo Melina committed Jun 10, 2024 at 16:36 UTC 1f704ec4454c54b4ec741c4fc34cc3df5d972415
2 files changed +15 -2
src/api.monitor.ts
+1 -1
@@ -87,7 +87,7 @@ export default {
87 yield {
88 outSpeed: totalOutSpeed,
89 inSpeed: totalInSpeed,
90 - sent_got: [totalSent.get(), totalGot.get(), totalGotSentResetTime.get()],
90 + sent_got: [totalSent.get(), totalGot.get(), totalGotSentResetTime.get()] as const,
91 connections: filtered.length,
92 ips: _.uniqBy(filtered, x => x.ip).length,
93 }
src/commands.ts
+14 -1
@@ -11,7 +11,8 @@ import { createInterface } from 'readline'
11 import { getAvailablePlugins, mapPlugins, startPlugin, stopPlugin } from './plugins'
12 import { purgeFileAttr } from './fileAttr'
13 import { downloadPlugin } from './github'
14 -import { makeMatcher } from './cross'
14 +import { formatBytes, formatSpeed, formatTimestamp, makeMatcher } from './cross'
15 +import apiMonitor from './api.monitor'
16
17 if (!argv.updating)
18 try {
@@ -138,5 +139,17 @@ const commands = {
139 'purge-file-attr': {
140 params: '',
141 cb: purgeFileAttr,
142 + },
143 + status: {
144 + params: '',
145 + async cb() {
146 + const conn = (await apiMonitor.get_connection_stats().next()).value
147 + if (conn) {
148 + const {sent_got: sg} = conn
149 + console.log(`Speed ↑ ${formatSpeed(conn.outSpeed)} ↓ ${formatSpeed(conn.inSpeed)}`)
150 + console.log(`Transfered ↑ ${formatBytes(sg[0])} ↓ ${formatBytes(sg[1])} since ${formatTimestamp(sg[2])}`)
151 + console.log(`Connections ${conn.connections} (${conn.ips} IPs)`)
152 + }
153 + }
154 }
155 }