diff options
author | root <root@frank.tg14.gathering.org> | 2014-04-18 20:34:57 +0200 |
---|---|---|
committer | root <root@frank.tg14.gathering.org> | 2014-04-18 20:34:57 +0200 |
commit | 9921526800e5f2aced28381f07275b1c0693dd4f (patch) | |
tree | 37ba2d3d1154e1f487ce81167a64487191190346 | |
parent | 3f6378f9f87f13d64e514bbc6086007a74be0979 (diff) |
Fetch aggregated ports for clients + internet, print as JSON, so we can fetch it live.
-rwxr-xr-x | clients/update-public-speedometer.pl | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/clients/update-public-speedometer.pl b/clients/update-public-speedometer.pl new file mode 100755 index 0000000..7fd17df --- /dev/null +++ b/clients/update-public-speedometer.pl @@ -0,0 +1,37 @@ +#! /usr/bin/perl -I/root/tgmanage/include +use strict; +use warnings; +use lib 'include'; +use nms; +use Data::Dumper::Simple; + +my $dbh = nms::db_connect(); +$dbh->{AutoCommit} = 0; + +# D-Links +my $sth = $dbh->prepare("select sum(bytes_in) * 8 / 1048576.0 / 1024.0 as traffic_in, sum(bytes_out) * 8 / 1048576.0 / 1024.0 as traffic_out from get_current_datarate() natural join switches where switchtype like 'dlink3100%' and port < 45") + or die "Can't prepare query: $!"; +$sth->execute(); +my $total_traffic_dlink = $sth->fetchrow_hashref(); +$sth->finish(); + +# TeleGW +$sth = $dbh->prepare("select sum(bytes_in) * 8 / 1048576.0 / 1024.0 as traffic_in, sum(bytes_out) * 8 / 1048576.0 / 1024.0 as traffic_out from get_current_datarate() natural join switches where sysname like '%TeleGW%' and (port=64 or port=65 or port=69 or port=70)") + or die "Can't prepare query: $!"; +$sth->execute(); +my $total_traffic_telegw = $sth->fetchrow_hashref(); +$sth->finish(); + +$dbh->disconnect(); + +my $total = $total_traffic_dlink->{'traffic_in'} + $total_traffic_dlink->{'traffic_out'}; +$total += $total_traffic_telegw->{'traffic_in'} + $total_traffic_telegw->{'traffic_out'}; + +# Now we have summarized in+out for clients and in+out for internet-traffic +# We divide by two to get an average +$total = $total / 2; +my $nicetotal = sprintf ("%.2f", $total); + +# {"speed":19.12} +print qq({"speed":$nicetotal}); +exit 0 |