Files
@ 9b0101067e80
Branch filter:
Location: FVDE/ennstatus/Scripts/traffic_statistics.pl - annotation
9b0101067e80
3.0 KiB
text/x-perl
Create filename early in check_server as it is needed anyway
aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 1caae561a67e 1caae561a67e 1caae561a67e 1caae561a67e aa70ef866179 aa70ef866179 aa70ef866179 1caae561a67e aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 1caae561a67e aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 1caae561a67e 1caae561a67e aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 1caae561a67e aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 aa70ef866179 1caae561a67e | #!/usr/bin/perl
=About
This perl scripts generates statistics about the servers traffic consumption
by virii
=cut
use HTTP::Tiny;
use IO::Socket;
use Chart::Clicker;
use Chart::Clicker::Context;
use Chart::Clicker::Data::DataSet;
use Chart::Clicker::Data::Marker;
use Chart::Clicker::Data::Series;
use Chart::Clicker::Renderer::Area;
use Geometry::Primitive::Rectangle;
use Graphics::Color::RGB;
############### [Which year] ###########################################
$select_year = 2014;
$select_year = shift if $ARGV[0] =~ /^\d{4}$/;
############### [Create new statistics image] ##########################
$cc = Chart::Clicker->new(width => 1248, height => 800);
$ds = Chart::Clicker::Data::DataSet->new();
@months = 1..12;
@series;
@traffix;
########################################################################
@nodes = qw(relay exit);
############### [Servername gathering via Ennstatus API] ###############
foreach $node (@nodes) {
print "[+] Checking for $node\n";
$gather_nodes = HTTP::Tiny->new->get('http://enn.lu/api/export/xml/' . $node) || die "[-] Cannot connect to $node API\n";
@xml_response = split(/\n/,$gather_nodes->{content});
foreach $xml_line (@xml_response) {
$counter++;
if ($xml_line =~ /\<server_name\>(\w+)\<\/server_name\>/i) {
$server_nick = $1;
if ($xml_response[$counter] =~ /\<server_status\>(\w+)\<\/server_status\>/i) {
push @servers, $server_nick if ($1 eq "Online"); # we want only those who are online
}
}
}
undef $counter;
}
####################### [Connect to each server] #######################
foreach $server_name (@servers) {
print "[+] Checking '$server_name'\n";
$server_response = HTTP::Tiny->new->get('http://' . $server_name . '.enn.lu/vnstat.xml');
die "[-] '$server_name' Failed!\n" unless $server_response->{success};
@xml_content = split(/\n/,$server_response->{content});
foreach $xml_line (@xml_content) {
if ($xml_line =~ /\<month id="(\d+)"\>\<date\>\<year\>($select_year)\<\/year\>\<month\>(\d+)\<\/month\>\<\/date\>\<rx\>(\d+)\<\/rx\>\<tx\>(\d+)\<\/tx\>\<\/month\>/ig) {
($id,$year,$month,$rx,$tx) = ($1,$2,$3,$4,$5,$6);
$rxtx = ($tx + $rx) * 10e-10;
$traffic = $1 if $rxtx =~ /^(\d+\.?\d{5})/;
push @traffix, $traffic;
}
}
for (scalar @traffix..11) {
push @traffix, 0 if $select_year == 2014;
unshift @traffix, 0 unless $select_year == 2014;
}
$ds->add_to_series(Chart::Clicker::Data::Series->new(
keys => \@months,
values => [@traffix],
name => $server_name
));
undef @traffix;
}
$cc->add_to_datasets($ds);
$def = $cc->get_context('default');
$def->range_axis->label('Tbit');
$def->domain_axis->label('Month');
$area = Chart::Clicker::Renderer::Area->new(opacity => .2);
$area->brush->width(3);
$def->renderer($area);
$def->range_axis->tick_values([qw(20 40 60 80 100 120 140 160 300)]);
$def->range_axis->format('%d');
$def->domain_axis->ticks(11);
$def->domain_axis->tick_labels([qw(January February Mars April June July August September October November December)]);
$def->domain_axis->format('%d');
$cc->write_output('stats.png');
|