From 586834f7dfa2700553a60b2708157c4b0a18333f Mon Sep 17 00:00:00 2001 From: Manuel Kasper Date: Thu, 11 Sep 2014 18:38:33 +0200 Subject: [PATCH] Configurable stats intervals for link usage * use configurable stats intervals for link usage too * fix label in top AS when short_open_tag is off * refactor statsfile/label handling --- www/func.inc | 20 ++++++++++++++++++++ www/headermenu.inc | 18 ++++++++++-------- www/linkgraph.php | 13 +++++++++++-- www/linkusage.php | 16 +++++++++++----- www/top.php | 38 ++++++++++++-------------------------- 5 files changed, 64 insertions(+), 41 deletions(-) diff --git a/www/func.inc b/www/func.inc index 796639c..bbb0e13 100644 --- a/www/func.inc +++ b/www/func.inc @@ -245,3 +245,23 @@ function getHTMLImg($as, $ipversion, $desc, $start, $end, $peerusage, $alt, $cla $result .= "/>"; return($result); } + +function statsFileForHours($hours) { + global $top_intervals, $daystatsfile; + foreach ($top_intervals as $interval) { + if ($interval['hours'] == $hours && @$interval['statsfile']) { + return $interval['statsfile']; + } + } + return $daystatsfile; +} + +function statsLabelForHours($hours) { + global $top_intervals; + foreach ($top_intervals as $interval) { + if ($interval['hours'] == $hours && @$interval['label']) { + return $interval['label']; + } + } + return (int)$hours . " hours"; +} diff --git a/www/headermenu.inc b/www/headermenu.inc index db1829c..5d03455 100644 --- a/www/headermenu.inc +++ b/www/headermenu.inc @@ -17,6 +17,14 @@ if($showpeeras == true){ endif; } +echo "Link usage: "; +foreach ($top_intervals as $interval) { + echo '' . $interval['label'] . ' | '; +} + if ($dpagename == "history"): ?>View an AS | View an AS-SET | View an AS-SET | Link usageView an AS-SETLink usageView an AS-SET diff --git a/www/linkgraph.php b/www/linkgraph.php index 6bab59b..51f681a 100644 --- a/www/linkgraph.php +++ b/www/linkgraph.php @@ -17,8 +17,13 @@ if (@$_GET['v'] == 6) $link .= "_v6"; +$hours = 24; +if (@$_GET['numhours']) + $hours = (int)$_GET['numhours']; + /* first step: walk the data for all ASes to determine the top 5 for the given link */ -$fd = fopen($daystatsfile, "r"); +$statsfile = statsFileForHours($hours); +$fd = fopen($statsfile, "r"); $cols = explode("\t", trim(fgets($fd))); $asstats = array(); @@ -73,9 +78,13 @@ $width -= 81; } +$start = time() - $hours*3600; +$end = time(); + $cmd = "$rrdtool graph - " . "--slope-mode --alt-autoscale -u 0 -l 0 --imgformat=PNG --base=1000 --height=$height --width=$width " . - "--color BACK#ffffff00 --color SHADEA#ffffff00 --color SHADEB#ffffff00 "; + "--color BACK#ffffff00 --color SHADEA#ffffff00 --color SHADEB#ffffff00 " . + "--start " . $start . " --end " . $end . " "; if (!$compat_rrdtool12) $cmd .= "--full-size-mode "; diff --git a/www/linkusage.php b/www/linkusage.php index 6ed245c..e19487e 100644 --- a/www/linkusage.php +++ b/www/linkusage.php @@ -9,6 +9,12 @@ $knownlinks = getknownlinks(); +$hours = 24; +if (@$_GET['numhours']) + $hours = (int)$_GET['numhours']; + +$label = statsLabelForHours($hours); + ?> @@ -16,14 +22,14 @@ - Link usage + Link usage (<?php echo $label ?>) -
Link usage - top 10 AS per link
+
Link usage - top 10 AS per link ()
@@ -40,10 +46,10 @@ diff --git a/www/top.php b/www/top.php index 9824045..7a06d61 100644 --- a/www/top.php +++ b/www/top.php @@ -15,34 +15,20 @@ if ($ntop > 200) $ntop = 200; +$hours = 24; +if (@$_GET['numhours']) + $hours = (int)$_GET['numhours']; + if ($peerusage) $statsfile = $daypeerstatsfile; else { - $statsfile = $daystatsfile; - - /* find more appropriate file for this interval */ - foreach ($top_intervals as $interval) { - if ($interval['hours'] == @$_GET['numhours']) { - if (@$interval['statsfile']) - $statsfile = $interval['statsfile']; - if (@$interval['label']) - $label = $interval['label']; - } - } + $statsfile = statsFileForHours($hours); + $label = statsLabelForHours($hours); } $topas = getasstats_top($ntop, $statsfile); -if (@$_GET['numhours']) { - $start = time() - $_GET['numhours']*3600; - $end = time(); - if (!$label) - $label = htmlspecialchars($_GET['numhours']) . " hours"; -} else { - $start = ""; - $end = ""; - if (!$label) - $label = "24 hours"; -} +$start = time() - $hours*3600; +$end = time(); ?> - Top <?php echo $ntop; ?> AS<?php if($peerusage) echo " peer"; ?> (<?=$label?>) + Top <?php echo $ntop; ?> AS<?php if($peerusage) echo " peer"; ?> (<?php echo $label?>) @@ -65,7 +51,7 @@ -
Top AS ()
+
Top AS ()
- link graph" width="" height="" border="0" /> - link graph" width="" height="" border="0" /> + link graph" width="" height="" border="0" /> + link graph" width="" height="" border="0" /> - link graph" width="" height="" border="0" /> + link graph" width="" height="" border="0" />
@@ -86,10 +72,10 @@ AS:
IPv4: ~ in / - out in the last
+ out in the last
IPv6: ~ in / - out in the last
+ out in the last