Created
June 17, 2014 09:15
-
-
Save LeSpocky/25244f04a60d2c2543ef to your computer and use it in GitHub Desktop.
gather some data for http://www.netz39.de/wiki/projects:2014:freifunk_statistik_panel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
use JSON; | |
use LWP::Simple; | |
# init variables | |
my %sum = ( | |
'clients' => 0, | |
'nodes_online' => 0, | |
'nodes' => 0, | |
'mesh_links' => 0, | |
'n39_clients' => 0 | |
); | |
#my $sum_clientcount = 0; | |
#my $node_count = 0; | |
#my $sum_online_nodes = 0; | |
my %netz39_node = ( '12:fe:ed:ce:ae:be' => 0 ); | |
#my $sum_n39_clients = 0; | |
#my $sum_mesh_links = 0; | |
# get json | |
my $content = get('http://map.md.freifunk.net/nodes.json'); | |
die 'Could not get it!' unless defined $content; | |
my $nodes_ref = decode_json($content); | |
# iterate over nodes | |
foreach my $node ( @{ $nodes_ref->{'nodes'} } ) { | |
if ( !( $node->{'flags'}->{'gateway'} || $node->{'flags'}->{'client'} ) ) { | |
$sum{'nodes'}++; | |
$sum{'clients'} += $node->{'clientcount'}; | |
if ( $node->{'flags'}->{'online'} ) { $sum{'nodes_online'}++ } | |
} | |
foreach my $id ( keys %netz39_node ) { | |
if ( $id eq $node->{'id'} ) { | |
$netz39_node{$id} = $node->{'clientcount'}; | |
$sum{'n39_clients'} += $node->{'clientcount'}; | |
} | |
} | |
} | |
#print "$sum{'nodes_online'} of $sum{'nodes'} nodes online with $sum{'clients'} clients\n"; | |
#print "$sum{'n39_clients'} clients online on Netz39 nodes\n"; | |
# iterate over links | |
foreach my $link ( @{ $nodes_ref->{'links'} } ) { | |
if ( !defined $link->{'type'} ) { | |
$sum{'mesh_links'}++; | |
} | |
} | |
#print "$sum{'mesh_links'} mesh links in FFMD\n"; | |
my $json_text = encode_json( \%sum ); | |
print "$json_text\n"; | |
# vim: set ft=perl et sts=0 ts=4 sw=4 sr: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment