Skip to content

Commit

Permalink
Configurable stats intervals for link usage
Browse files Browse the repository at this point in the history
* use configurable stats intervals for link usage too
* fix label in top AS when short_open_tag is off
* refactor statsfile/label handling
  • Loading branch information
Manuel Kasper committed Sep 11, 2014
1 parent 77bc8aa commit 586834f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 41 deletions.
20 changes: 20 additions & 0 deletions www/func.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
18 changes: 10 additions & 8 deletions www/headermenu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ if($showpeeras == true){
endif;
}

echo "<span>Link usage:</span> ";
foreach ($top_intervals as $interval) {
echo '<a href="linkusage.php?numhours=' . $interval['hours'] . '"';
if ($dpagename == "linkusage" && @$_GET['numhours'] == $interval['hours'])
echo ' class="selected"';
echo '>' . $interval['label'] . '</a> | ';
}

if ($dpagename == "history"):
?><a href="history.php" class="selected">View an AS</a> | <?php
else:
Expand All @@ -25,15 +33,9 @@ endif;


if ($dpagename == "asset"):
?><a href="asset.php" class="selected">View an AS-SET</a> | <?php
else:
?><a href="asset.php">View an AS-SET</a> | <?php
endif;

if ($dpagename == "linkusage"):
?><a href="linkusage.php" class="selected">Link usage</a><?php
?><a href="asset.php" class="selected">View an AS-SET</a><?php
else:
?><a href="linkusage.php">Link usage</a><?php
?><a href="asset.php">View an AS-SET</a><?php
endif;

?>
13 changes: 11 additions & 2 deletions www/linkgraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 ";
Expand Down
16 changes: 11 additions & 5 deletions www/linkusage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@

$knownlinks = getknownlinks();

$hours = 24;
if (@$_GET['numhours'])
$hours = (int)$_GET['numhours'];

$label = statsLabelForHours($hours);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Refresh" content="300" />
<title>Link usage</title>
<title>Link usage (<?php echo $label ?>)</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>

<div id="nav"><?php include('headermenu.inc'); ?></div>
<div class="pgtitle">Link usage - top 10 AS per link</div>
<div class="pgtitle">Link usage - top 10 AS per link (<?php echo $label ?>)</div>

<table class="astable">

Expand All @@ -40,10 +46,10 @@
<?php endif; ?>
<td>
<?php if ($showv6): ?>
<img alt="link graph" src="linkgraph.php?link=<?php echo $link['tag']; ?>&amp;width=<?php echo $linkusage_graph_width ?>&amp;height=<?php echo $linkusage_graph_height ?>&amp;v=4&amp;dname=<?php echo rawurlencode($link['descr'] . " - IPV4"); ?>" width="<?php echo $linkusage_graph_width ?>" height="<?php echo $linkusage_graph_height ?>" border="0" />
<img alt="link graph" src="linkgraph.php?link=<?php echo $link['tag']; ?>&amp;width=<?php echo $linkusage_graph_width ?>&amp;height=<?php echo $linkusage_graph_height ?>&amp;v=6&amp;dname=<?php echo rawurlencode($link['descr'] . " - IPV6"); ?>" width="<?php echo $linkusage_graph_width ?>" height="<?php echo $linkusage_graph_height ?>" border="0" />
<img alt="link graph" src="linkgraph.php?link=<?php echo $link['tag']; ?>&amp;numhours=<?php echo $hours ?>&amp;width=<?php echo $linkusage_graph_width ?>&amp;height=<?php echo $linkusage_graph_height ?>&amp;v=4&amp;dname=<?php echo rawurlencode($link['descr'] . " - IPV4"); ?>" width="<?php echo $linkusage_graph_width ?>" height="<?php echo $linkusage_graph_height ?>" border="0" />
<img alt="link graph" src="linkgraph.php?link=<?php echo $link['tag']; ?>&amp;numhours=<?php echo $hours ?>width=<?php echo $linkusage_graph_width ?>&amp;height=<?php echo $linkusage_graph_height ?>&amp;v=6&amp;dname=<?php echo rawurlencode($link['descr'] . " - IPV6"); ?>" width="<?php echo $linkusage_graph_width ?>" height="<?php echo $linkusage_graph_height ?>" border="0" />
<?php else: ?>
<img alt="link graph" src="linkgraph.php?link=<?php echo $link['tag']; ?>&amp;width=<?php echo $linkusage_graph_width ?>&amp;height=<?php echo $linkusage_graph_height ?>&amp;dname=<?php echo rawurlencode($link['descr'] . ""); ?>" width="<?php echo $linkusage_graph_width ?>" height="<?php echo $linkusage_graph_height ?>" border="0" />
<img alt="link graph" src="linkgraph.php?link=<?php echo $link['tag']; ?>&amp;numhours=<?php echo $hours ?>width=<?php echo $linkusage_graph_width ?>&amp;height=<?php echo $linkusage_graph_height ?>&amp;dname=<?php echo rawurlencode($link['descr'] . ""); ?>" width="<?php echo $linkusage_graph_width ?>" height="<?php echo $linkusage_graph_height ?>" border="0" />
<?php endif; ?>
</td>
</tr>
Expand Down
38 changes: 12 additions & 26 deletions www/top.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
Expand All @@ -51,7 +37,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Refresh" content="300" />
<title>Top <?php echo $ntop; ?> AS<?php if($peerusage) echo " peer"; ?> (<?=$label?>)</title>
<title>Top <?php echo $ntop; ?> AS<?php if($peerusage) echo " peer"; ?> (<?php echo $label?>)</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

Expand All @@ -65,7 +51,7 @@
<?php include('headermenu.inc'); ?>
</form>
</div>
<div class="pgtitle">Top <?php echo $ntop; ?> AS<?php if($peerusage) echo " peer"; ?> (<?=$label?>)</div>
<div class="pgtitle">Top <?php echo $ntop; ?> AS<?php if($peerusage) echo " peer"; ?> (<?php echo $label?>)</div>

<table class="astable">

Expand All @@ -86,10 +72,10 @@
AS<?php echo $as; ?>: <?php echo $asinfo['descr']; ?>
</div>
<div class="small">IPv4: ~ <?php echo format_bytes($nbytes[0]); ?> in /
<?php echo format_bytes($nbytes[1]); ?> out in the last <?=$label?></div>
<?php echo format_bytes($nbytes[1]); ?> out in the last <?php echo $label?></div>
<?php if ($showv6): ?>
<div class="small">IPv6: ~ <?php echo format_bytes($nbytes[2]); ?> in /
<?php echo format_bytes($nbytes[3]); ?> out in the last <?=$label?></div>
<?php echo format_bytes($nbytes[3]); ?> out in the last <?php echo $label?></div>
<?php endif; ?>

<?php if (!empty($customlinks)): ?>
Expand Down

0 comments on commit 586834f

Please sign in to comment.