nncp: collect statistics
Publish the spool size and packet count for each neighbour.
This commit is contained in:
parent
3a521f7673
commit
36ac1fa602
|
@ -0,0 +1,41 @@
|
|||
import std/[os, strutils]
|
||||
|
||||
import posix
|
||||
|
||||
proc getFileSize(path: string): BiggestInt =
|
||||
var rawInfo: Stat
|
||||
if stat(path, rawInfo) < 0'i32:
|
||||
raiseOSError(osLastError(), path)
|
||||
rawInfo.st_size
|
||||
|
||||
let
|
||||
hostname = getEnv("COLLECTD_HOSTNAME", "localhost")
|
||||
interval = max(60, getEnv("COLLECTD_INTERVAL", "0").parseFloat.int)
|
||||
args = commandLineParams()
|
||||
|
||||
doAssert(args.len == 1, "pass only the NNCP spool directry as an argument")
|
||||
|
||||
proc sumDir(path: string): tuple[size: BiggestInt, packets: int] =
|
||||
for kind, path in walkDir path:
|
||||
if kind == pcFile:
|
||||
result.size = result.size + getFileSize(path)
|
||||
inc result.packets
|
||||
|
||||
while true:
|
||||
for kind, path in walkDir args[0]:
|
||||
if kind == pcLinkToDir:
|
||||
var nodeName = extractFilename path
|
||||
block:
|
||||
var rx = sumDir(path / "rx")
|
||||
stdout.writeLine("""PUTVAL "$#/nncp-$#/bytes-rx" interval=$# N:$#""" %
|
||||
[hostname, nodeName, $interval, $rx.size])
|
||||
stdout.writeLine("""PUTVAL "$#/nncp-$#/pending_operations-rx" interval=$# N:$#""" %
|
||||
[hostname, nodeName, $interval, $rx.packets])
|
||||
block:
|
||||
var tx = sumDir(path / "tx")
|
||||
stdout.writeLine("""PUTVAL "$#/nncp-$#/bytes-tx" interval=$# N:$#""" %
|
||||
[hostname, nodeName, $interval, $tx.size])
|
||||
stdout.writeLine("""PUTVAL "$#/nncp-$#/pending_operations-tx" interval=$# N:$#""" %
|
||||
[hostname, nodeName, $interval, $tx.packets])
|
||||
flushFile stdout
|
||||
sleep interval*1000
|
|
@ -4,6 +4,7 @@
|
|||
boot.loader.initScript.enable = lib.mkForce false;
|
||||
|
||||
c3d2.mergeNncpSettings = false;
|
||||
c3d2.hq.statistics.enable = true;
|
||||
|
||||
networking = {
|
||||
hostName = "nncp";
|
||||
|
@ -23,6 +24,17 @@
|
|||
};
|
||||
};
|
||||
|
||||
services.collectd.plugins.exec = let
|
||||
util =
|
||||
pkgs.runCommand "collectd_nncp" { nativeBuildInputs = [ pkgs.nim ]; } ''
|
||||
cp ${./collectd_nncp.nim} ./collectd_nncp.nim
|
||||
nim c --nimcache:. -o:$out ./collectd_nncp.nim
|
||||
'';
|
||||
in ''
|
||||
Exec "${config.services.collectd.user}" "${util}" "${config.programs.nncp.settings.spool}"
|
||||
'';
|
||||
users.groups.uucp.members = [ config.services.collectd.user ];
|
||||
|
||||
services.nncp = {
|
||||
caller.enable = false;
|
||||
daemon = {
|
||||
|
|
Loading…
Reference in New Issue