-
Notifications
You must be signed in to change notification settings - Fork 0
/
xlxd_stats.pl
executable file
·64 lines (49 loc) · 1.21 KB
/
xlxd_stats.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl -w
#
use strict;
use warnings;
use experimental 'smartmatch';
use IO::Socket;
use JSON;
use RRDTool::OO;
$| = 1;
my $remote = "localhost";
my $port = 10001;
my $proto = "udp";
my $rrdfile = "/usr/share/xlxd/statistics.rrd";
my $rrd = RRDTool::OO->new(file => $rrdfile );
my $socket = IO::Socket::INET->new(PeerAddr => $remote,
PeerPort => $port,
Proto => $proto,
Type => SOCK_DGRAM)
or die "Connection to $remote:$port failed; $@\n";
$socket->blocking(1);
$socket->send("hello\n");
my $datagram;
my $json;
while ($socket->recv($datagram, 65535)) {
$json = $datagram;
if ($datagram =~ "}]}") {
last;
}
}
$socket->send("bye\n");
close ($socket);
my $decoded = decode_json($json);
my @nodes = @{ $decoded->{'nodes'} };
my $i = 0;
my @peers;
foreach my $n ( @nodes ) {
if ($n->{'module'} =~ '\w') {
$i++;
}
if ($n->{'module'} =~ ' ') {
unless ($n->{'callsign'} ~~ @peers) {
push @peers, $n->{'callsign'};
}
}
}
$rrd->update(values => { "nodes" => $i,
"peers" => scalar @peers
});
exit 0;