From 11af3523fcff07d02833e4f6b28eecb23c97a3a7 Mon Sep 17 00:00:00 2001 From: Nicolas Debrigode Date: Mon, 3 Apr 2017 09:04:11 +0200 Subject: [PATCH] Update code to include this [d6c4c0ff951a6d8bf881177a4fa41245c6acc1dd](https://github.com/manuelkasper/AS-Stats/commit/d6c4c0ff951a6d8bf881177a4fa41245c6acc1dd#diff-4eae35f1b35977a00ebd8086c259d4c9) update from AS-Stats. --- config.inc | 17 +++--- config_defaults.inc | 4 -- func.inc | 141 ++++++++++++++++++-------------------------- gengraph.php | 15 +++++ index.php | 68 ++++++++++++++++----- 5 files changed, 133 insertions(+), 112 deletions(-) diff --git a/config.inc b/config.inc index 54e8e0e..009f89b 100644 --- a/config.inc +++ b/config.inc @@ -3,7 +3,7 @@ /* changes these values to suit your local configuration */ $rrdpath = "/data/asstats/rrd"; -$daystatsfile = "/data/asstats/asstats_day.txt"; +$daystatsfile = "/data/asstats/asstats/asstats_day.txt"; $rrdtool = "/usr/bin/rrdtool"; $daypeerstatsfile = "/data/asstats/peerasstats_day.txt"; @@ -11,13 +11,12 @@ $showpeeras = false; $asinfofile = "asinfo.txt"; $knownlinksfile = "/data/asstats/conf/knownlinks"; -$outispositive = false; +$outispositive = false; $show95th = true; -$ntop = 10; +$ntop = 20; $showv6 = true; $showtitledetail = true; -$hidelinkusagename = false; # $showtitledetail will need to be true to allow this $vertical_label = true; # vertical IN/OUT label in graph $brighten_negative = true; # brighten the "negative" part of graphs @@ -40,13 +39,13 @@ $customlinks = array( ); /* Custom time intervals for top N AS */ - -/*$top_intervals[] = array( +/* +$top_intervals[] = array( 'hours' => 7*24, - 'statsfile' => '/data/asstats/asstats_day.txt', + 'statsfile' => '/data/as-stats/asstats_week.txt', 'label' => '1 week' -);*/ -/*$top_intervals[] = array( +); +$top_intervals[] = array( 'hours' => 30*24, 'statsfile' => '/data/as-stats/asstats_month.txt', 'label' => '30 days' diff --git a/config_defaults.inc b/config_defaults.inc index 26c6919..835faa7 100644 --- a/config_defaults.inc +++ b/config_defaults.inc @@ -10,10 +10,6 @@ $default_graph_height = 360; $top_graph_width = 600; $top_graph_height = 220; -/* Size of graphs on link usage page */ -$linkusage_graph_width = 600; -$linkusage_graph_height = 480; - /* Size of graphs on AS-Set page */ $asset_graph_width = 600; $asset_graph_height = 200; diff --git a/func.inc b/func.inc index e545306..caa3d2e 100644 --- a/func.inc +++ b/func.inc @@ -78,49 +78,48 @@ function getknownlinks() { return $knownlinks; } -function getasstats_top($ntop, $statfile) { - /* first step: walk the data for all ASes to determine the top 5 for the given link */ - $fd = fopen($statfile, "r"); - if (!$fd) +function getasstats_top($ntop, $statfile, $selected_links) { + try{ + $db = new SQLite3($statfile); + }catch(Exception $e){ return array(); - $cols = explode("\t", trim(fgets($fd))); - - /* read in up to $ntop AS stats, sum up columns */ - while (!feof($fd)) { - $line = trim(fgets($fd)); - if (!$line) - continue; - - $els = explode("\t", $line); - - /* first element is the AS */ - $as = $els[0]; + } + if(sizeof($selected_links) == 0){ + $selected_links = array(); + foreach(getknownlinks() as $link) + $selected_links[] = $link['tag']; + } + $nlinks = 0; + $query_total = '0'; + $query_links = ''; + foreach($selected_links as $tag){ + $query_links .= "${tag}_in, ${tag}_out, ${tag}_v6_in, ${tag}_v6_out, "; + $nlinks += 4; + $query_total .= " + ${tag}_in + ${tag}_out + ${tag}_v6_in + ${tag}_v6_out"; + } + $query = "select asn, $query_links $query_total as total from stats order by total desc limit $ntop"; + $asn = $db->query($query); + $asstats = array(); + while($row = $asn->fetchArray()){ $tot_in = 0; $tot_out = 0; $tot_v6_in = 0; $tot_v6_out = 0; - - for ($i = 1; $i < count($els); $i++) { - if (strpos($cols[$i], "_in") !== false) { - if (strpos($cols[$i], "_v6_") !== false) - $tot_v6_in += $els[$i]; + foreach($row as $key => $value){ + if (strpos($key, '_in') !== false) { + if (strpos($key, '_v6_') !== false) + $tot_v6_in += $value; else - $tot_in += $els[$i]; - } else { - if (strpos($cols[$i], "_v6_") !== false) - $tot_v6_out += $els[$i]; + $tot_in += $value; + } else if (strpos($key, '_out') !== false) { + if (strpos($key, '_v6_') !== false) + $tot_v6_out += $value; else - $tot_out += $els[$i]; + $tot_out += $value; } } - - $asstats[$as] = array($tot_in, $tot_out, $tot_v6_in, $tot_v6_out); - - if (count($asstats) >= $ntop) - break; + $asstats[$row['asn']] = array($tot_in, $tot_out, $tot_v6_in, $tot_v6_out); } - fclose($fd); - return $asstats; } @@ -201,35 +200,30 @@ function clearCacheFileASSET($asset) { } # return the html used in top.php : -function getHTMLUrl($as, $ipversion, $desc, $start, $end, $peerusage){ - $result = ""; - - $img = getHTMLImg($as, $ipversion, $desc, $start, $end, $peerusage, '', '', false); - - if ( $img ) { - $result = "$img"; - } - +function getHTMLUrl($as, $ipversion, $desc, $start, $end, $peerusage, $selected_links = array()){ + $img = getHTMLImg($as, $ipversion, $desc, $start, $end, $peerusage, '', '', false, $selected_links); + $result = "$img"; return($result); } # return the html used in history.php (for example) : -function getHTMLImg($as, $ipversion, $desc, $start, $end, $peerusage, $alt, $class, $history = false){ +function getHTMLImg($as, $ipversion, $desc, $start, $end, $peerusage, $alt, $class, $history = false, $selected_links=array()){ global $top_graph_width; global $top_graph_height; - $result = ""; - - $rrdfile = getRRDFileForAS($as); - if (file_exists($rrdfile)) { - $dname = rawurlencode("AS$as - $desc - IPV$ipversion"); - $result = "$alt"; } -function menu() { +function menu($selected_links) { global $top_intervals; - + //debug($selected_links); //echo count($top_intervals); $dpagename = basename($_SERVER['PHP_SELF'], ".php"); $active_top = $dpagename == "index" ? "active": ""; $active_searchas = $dpagename == "history" ? 'class="active"' : ""; $active_searchasset = $dpagename == "asset" ? 'class="active"' : ""; - $active_linkusage = $dpagename == "linkusage" ? "active" : ""; $return = '
'; $return .= '