Changeset - 207c124454d0
[Not reviewed]
tip default
0 1 0
Tyler Durden (virii) - 7 years ago 2016-10-19 18:34:12
virii@c3l.lu
Edited file Exit-Network-Stats.pl via Kallithea
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
Exit-Network-Stats.pl
Show inline comments
 
@@ -7,49 +7,49 @@ use XML::LibXML;
 
use HTTP::Tiny;
 

	
 
use JSON::Parse qw(:all);
 
use List::UtilsBy qw( nsort_by );
 

	
 

	
 
my ($api, $api_request, $json, $nodes_in_numbers, $parser, $vnstat_xml, $query, $entry);
 
my ($rx, $tx, $rx_TiB, $tx_TiB, $rx_TiB_total, $tx_TiB_total, $argument);
 
my (@nodes_rand, @nodes_sorted);
 

	
 
$api         = HTTP::Tiny->new;
 
$api_request = $api->get('https://enn.lu/api/export/exit');
 
$json        = valid_json($api_request->{content});
 
$json        = parse_json($api_request->{content});
 

	
 

	
 
$nodes_in_numbers = scalar @$json;
 

	
 
push @nodes_rand, [$json->[$_]{ip}, $json->[$_]{name}, $json->[$_]{country}] for (0..$nodes_in_numbers -1);
 
@nodes_sorted = nsort_by { int $_->[0] } @nodes_rand;
 

	
 

	
 
format HEAD =
 
************************************************
 
    Country     RX      TX
 
    Country             RX              TX
 
************************************************
 
.
 
write HEAD;
 

	
 

	
 
for (0..$nodes_in_numbers -1) {
 
    unless ($nodes_sorted[$_][0] == $nodes_sorted[$_ +1][0]) {
 
            $api_request = $api->get('http://' . $nodes_sorted[$_][1] . '.enn.lu/vnstat.xml');
 
            $parser      = XML::LibXML->new();
 
            $vnstat_xml  = $parser->load_xml(string => $api_request->{content});
 

	
 
            $query = '/vnstat/interface/traffic/total';
 

	
 
            foreach $entry ($vnstat_xml->findnodes($query)) {
 
                    $rx = int $entry->findnodes('./rx');
 
                    $tx = int $entry->findnodes('./tx');
 
            }
 

	
 

	
 
        ($rx_TiB, $tx_TiB) = ($rx * (9.313 * 1.0E-10), $tx * (9.313 * 10E-10));
 
        ($rx_TiB, $tx_TiB) = (substr ($rx_TiB, 0, 4), substr ($tx_TiB, 0, 4));
 

	
 
        $rx_TiB_total += $rx_TiB;
 
        $tx_TiB_total += $tx_TiB;
0 comments (0 inline, 0 general)