diff options
author | Steinar H. Gunderson <sgunderson@bigfoot.com> | 2014-04-24 01:15:58 +0200 |
---|---|---|
committer | Steinar H. Gunderson <sgunderson@bigfoot.com> | 2014-04-24 01:15:58 +0200 |
commit | f627e9c78241ea211391055aa5409c8f0fa5939a (patch) | |
tree | ccb10cd9b289dc0e3a4a40b8c7041377321e8e40 /tools | |
parent | b0de329aa165028f2f4bf19067f14c98287a0c5f (diff) |
Add a little graph-generating tool for use after the party.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/ping-graph.pl | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tools/ping-graph.pl b/tools/ping-graph.pl new file mode 100755 index 0000000..44b8250 --- /dev/null +++ b/tools/ping-graph.pl @@ -0,0 +1,62 @@ +#! /usr/bin/perl + +# Makes latency-against-time graphs, one per switch. + +use warnings; +use strict; +use DBI; +use lib '../include'; +use nms; + +BEGIN { + require "../include/config.pm"; + eval { + require "../include/config.local.pm"; + }; +} + +my $dbh = db_connect(); +my $switches = $dbh->selectall_hashref('SELECT sysname,switch FROM switches ORDER BY sysname', 'sysname'); +if (0) { + my %switchfds = (); + while (my ($sysname, $switch) = each %$switches) { + print "$sysname -> $switch->{switch}\n"; + open my $fh, ">", "$sysname.txt" + or die "$sysname.txt: $!"; + $switchfds{$switch->{'switch'}} = $fh; + } + + my $q = $dbh->prepare('SELECT switch,EXTRACT(EPOCH FROM updated),latency_ms FROM ping'); + $q->execute; + + my $i = 0; + while (my $ref = $q->fetchrow_arrayref) { + next if (!defined($ref->[2])); + my $fh = $switchfds{$ref->[0]}; + next if (!defined($fh)); + print $fh $ref->[1], " ", $ref->[2], "\n"; + if (++$i % 1000000 == 0) { + printf "%dM records...\n", int($i / 1000000); + } + } + + while (my ($sysname, $switch) = each %$switches) { + close $switchfds{$switch->{'switch'}}; + } +} + +while (my ($sysname, $switch) = each %$switches) { + print "$sysname -> $switch->{switch}\n"; + open my $gnuplot, "|-", "gnuplot" + or die "gnuplot: $!"; + print $gnuplot <<"EOF"; +set timefmt "%s" +set xdata time +set format x "%d/%m %H:%M" +set term png size 1280,720 +set output '$sysname.png' +set yrange [0:200] +plot "$sysname.txt" using (int(\$1)):2 ps 0.1 +EOF + close $gnuplot; +} |