nncp: reduce NNCP stats to aggregate rx/tx

This is to avoid a permanent record of who transfers where.
This commit is contained in:
Ehmry - 2022-02-06 13:15:37 +01:00
parent 526a03e595
commit 7ae2243ff7
1 changed files with 17 additions and 11 deletions

View File

@ -15,27 +15,33 @@ let
doAssert(args.len == 1, "pass only the NNCP spool directry as an argument") doAssert(args.len == 1, "pass only the NNCP spool directry as an argument")
proc sumDir(path: string): tuple[size: BiggestInt, packets: int] = type DirStats = tuple[size: BiggestInt, packets: int]
proc sumDir(path: string): DirStats =
for kind, path in walkDir path: for kind, path in walkDir path:
if kind == pcFile: if kind == pcFile:
result.size = result.size + getFileSize(path) result.size = result.size + getFileSize(path)
inc result.packets inc result.packets
while true: while true:
var stats: tuple[rx: DirStats, tx: DirStats]
for kind, path in walkDir args[0]: for kind, path in walkDir args[0]:
if kind == pcLinkToDir: if kind == pcDir:
var nodeName = extractFilename path
block: block:
var rx = sumDir(path / "rx") var rx = sumDir(path / "rx")
stdout.writeLine("""PUTVAL "$#/exec-nncp_$#/bytes-rx" interval=$# N:$#""" % stats.rx.size = stats.rx.size + rx.size
[hostname, nodeName, $interval, $rx.size]) stats.rx.packets.inc rx.packets
stdout.writeLine("""PUTVAL "$#/exec-nncp_$#/pending_operations-rx" interval=$# N:$#""" %
[hostname, nodeName, $interval, $rx.packets])
block: block:
var tx = sumDir(path / "tx") var tx = sumDir(path / "tx")
stdout.writeLine("""PUTVAL "$#/exec-nncp_$#/bytes-tx" interval=$# N:$#""" % stats.tx.size = stats.tx.size + tx.size
[hostname, nodeName, $interval, $tx.size]) stats.tx.packets.inc tx.packets
stdout.writeLine("""PUTVAL "$#/exec-nncp_$#/pending_operations-tx" interval=$# N:$#""" % stdout.writeLine("""PUTVAL "$#/exec-nncp/bytes-rx" interval=$# N:$#""" %
[hostname, nodeName, $interval, $tx.packets]) [hostname, $interval, $stats.rx.size])
stdout.writeLine("""PUTVAL "$#/exec-nncp/pending_operations-rx" interval=$# N:$#""" %
[hostname, $interval, $stats.rx.packets])
stdout.writeLine("""PUTVAL "$#/exec-nncp/bytes-tx" interval=$# N:$#""" %
[hostname, $interval, $stats.tx.size])
stdout.writeLine("""PUTVAL "$#/exec-nncp/pending_operations-tx" interval=$# N:$#""" %
[hostname, $interval, $stats.tx.packets])
flushFile stdout flushFile stdout
sleep interval*1000 sleep interval*1000