Skip to content

Commit 815f32a

Browse files
author
Heath Raftery
committed
Initial commit
1 parent 4559345 commit 815f32a

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed

getStats.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
# can add -v for verbose (see headers)
4+
5+
curl -s --cookie "Authorization=Basic%20YWRtaW46MjEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzM%3D" "http://192.168.0.1/VXKQJFBBBVYUWYEA/userRpm/SystemStatisticRpm.htm?interval=5&autoRefresh=2&sortType=1&Num_per_page=20&Goto_page=1"
6+

liveplot.gnu

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
datafile = 'liveplot.dat'
2+
stats datafile skip 1 nooutput
3+
set xrange [0:100]
4+
set autoscale y
5+
set xlabel "Time (s)"
6+
set ylabel "kB/s"
7+
plot for [IDX=2:STATS_columns] datafile using 1:IDX with lines t columnheader(IDX)
8+
pause 5
9+
reread
10+

liveplot.pl

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/opt/local/bin/perl -w
2+
3+
use strict;
4+
use warnings;
5+
6+
use Storable;
7+
8+
my $TMP_FILE = 'liveplot.tmp';
9+
my $DAT_FILE = 'liveplot.dat';
10+
my $TIME_STEP = 5;
11+
12+
13+
#Retrieve the byte hash from last invocation
14+
my %oldBytes;
15+
%oldBytes = %{retrieve($TMP_FILE)} if -e $TMP_FILE;
16+
17+
while(<>)
18+
{
19+
last if $_ =~ /statList/; # don't do anything until we get to the statList array
20+
}
21+
22+
my %bytes;
23+
24+
while(<>)
25+
{
26+
last if $_ =~ /;/; # finish at the end of the statList array
27+
#Otherwise, pasrse each row which has content: index, IP, MAC, packets, bytes, etc.
28+
my @fields = split /, /;
29+
# print "$fields[1]\t$fields[4]\n";
30+
@bytes{substr $fields[1], 1, -1} = $fields[4];
31+
}
32+
33+
#print "\nMap\n";
34+
#print "$_ $bytes{$_}\n" for (sort keys %bytes);
35+
36+
#store for next invocation
37+
store \%bytes, $TMP_FILE;
38+
39+
#calculate delta between old bytes and this bytes
40+
my %deltaBytes;
41+
for (keys %bytes)
42+
{
43+
if(exists $oldBytes{$_})
44+
{
45+
$deltaBytes{$_} = ($bytes{$_} - $oldBytes{$_}) / (1024 * $TIME_STEP);
46+
}
47+
else
48+
{
49+
$deltaBytes{$_} = $bytes{$_} / (1024 * $TIME_STEP);
50+
}
51+
}
52+
53+
#print "\nDelta\n";
54+
#print "$_ $deltaBytes{$_}\n" for (sort keys %deltaBytes);
55+
56+
# Write or update the gnuplot dat file
57+
my $datf; # file handle
58+
my @dat; # file contents
59+
60+
if(-e $DAT_FILE)
61+
{
62+
open($datf, '<', $DAT_FILE);
63+
$dat[0] = [ split " ", <$datf> ]; # header contains all the ips
64+
shift @{ $dat[0] }; # get rid of the "time" column
65+
for(my $i = 1; <$datf>; $i++)
66+
{
67+
$dat[$i] = [ split ];
68+
shift @{ $dat[$i] }; # get rid of the "time" column
69+
}
70+
close($datf);
71+
}
72+
else # from existing dat file so start from scratch
73+
{
74+
@dat[0] = [ sort keys %deltaBytes ];
75+
}
76+
77+
#insert the new data
78+
unshift @dat, $dat[0]; #make room at the start but preseve the header row
79+
$dat[1] = [ () ]; #blank new row
80+
81+
for my $i ( 0 .. $#{$dat[0]} )
82+
{
83+
#print "pushing value ($deltaBytes{$dat[0][$i]}) for key ($dat[0][$i]).\n";
84+
push @{ $dat[1] }, $deltaBytes{$dat[0][$i]};
85+
}
86+
87+
pop @dat if $#dat > 21; # limit to last 21 values + header row
88+
89+
open $datf, '>', $DAT_FILE;
90+
91+
for my $i ( 0 .. $#dat )
92+
{
93+
if($i == 0)
94+
{
95+
print { $datf } "time(s) ";
96+
}
97+
else
98+
{
99+
print { $datf } ($i-1)*$TIME_STEP . " ";
100+
}
101+
102+
for my $j ( 0 .. $#{$dat[$i]} ) # oh Perl...
103+
{
104+
print { $datf } "$dat[$i][$j] ";
105+
#print "$dat[$i][$j] ";
106+
}
107+
print { $datf } "\n";
108+
#print "\n";
109+
}
110+
111+
close $datf;
112+

liveplot.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
rm liveplot.dat
3+
rm liveplot.tmp
4+
5+
echo "Initiasing data. Please wait 10 seconds..."
6+
7+
./resetStats.sh > /dev/null
8+
sleep 5
9+
10+
getdata()
11+
{
12+
while [ 1 ]
13+
do
14+
./getStats.sh | ./liveplot.pl
15+
# cat liveplot.dat
16+
sleep 5
17+
done
18+
}
19+
20+
getdata &
21+
# allow a couple of datapoints to arrive before plotting
22+
sleep 5
23+
24+
echo "Here comes the plot..."
25+
gnuplot liveplot.gnu
26+
27+
# kill getdata when we exit
28+
kill -- -$$
29+

resetStats.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
# can add -v for verbose (see headers)
4+
5+
curl -s --cookie "Authorization=Basic%20YWRtaW46MjEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzM%3D" "http://192.168.0.1/VXKQJFBBBVYUWYEA/userRpm/SystemStatisticRpm.htm?ResetAll=All&interval=5&autoRefresh=2&sortType=1&Num_per_page=20&Goto_page=1"
6+

0 commit comments

Comments
 (0)