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")
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:
if kind == pcFile:
result.size = result.size + getFileSize(path)
inc result.packets
while true:
var stats: tuple[rx: DirStats, tx: DirStats]
for kind, path in walkDir args[0]:
if kind == pcLinkToDir:
var nodeName = extractFilename path
if kind == pcDir:
block:
var rx = sumDir(path / "rx")
stdout.writeLine("""PUTVAL "$#/exec-nncp_$#/bytes-rx" interval=$# N:$#""" %
[hostname, nodeName, $interval, $rx.size])
stdout.writeLine("""PUTVAL "$#/exec-nncp_$#/pending_operations-rx" interval=$# N:$#""" %
[hostname, nodeName, $interval, $rx.packets])
stats.rx.size = stats.rx.size + rx.size
stats.rx.packets.inc rx.packets
block:
var tx = sumDir(path / "tx")
stdout.writeLine("""PUTVAL "$#/exec-nncp_$#/bytes-tx" interval=$# N:$#""" %
[hostname, nodeName, $interval, $tx.size])
stdout.writeLine("""PUTVAL "$#/exec-nncp_$#/pending_operations-tx" interval=$# N:$#""" %
[hostname, nodeName, $interval, $tx.packets])
stats.tx.size = stats.tx.size + tx.size
stats.tx.packets.inc tx.packets
stdout.writeLine("""PUTVAL "$#/exec-nncp/bytes-rx" interval=$# N:$#""" %
[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
sleep interval*1000