Fix graph sizing, improve config

Use full-size-graph option in recent RRDTool versions to avoid scaled
graphs. Introduce config defaults file to avoid hairy isset() logic for
new options. Make graph sizes configurable.
This commit is contained in:
Manuel Kasper 2014-06-17 17:33:50 +02:00
parent e69a14a878
commit 18deb09a3a
8 changed files with 72 additions and 26 deletions

View File

@ -121,10 +121,10 @@ if ( $action == "clearall" ) {
if (file_exists($rrdfile)): ?>
<?php if ($showv6): ?>
<a href="history.php?as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=500&amp;height=150&amp;v=4&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . " - IPV4"); ?>" width="597" height="207" border="0" /></a>
<a href="history.php?as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=500&amp;height=150&amp;v=6&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . " - IPV6"); ?>" width="597" height="207" border="0" /></a>
<a href="history.php?as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=<?php echo $asset_graph_width ?>&amp;height=<?php echo $asset_graph_height ?>&amp;v=4&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . " - IPV4"); ?>" width="<?php echo $asset_graph_width ?>" height="<?php echo $asset_graph_height ?>" border="0" /></a>
<a href="history.php?as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=<?php echo $asset_graph_width ?>&amp;height=<?php echo $asset_graph_height ?>&amp;v=6&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . " - IPV6"); ?>" width="<?php echo $asset_graph_width ?>" height="<?php echo $asset_graph_height ?>" border="0" /></a>
<?php else: ?>
<a href="history.php?as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=500&amp;height=150&amp;v=4&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . ""); ?>" width="597" height="207" border="0" /></a>
<a href="history.php?as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=<?php echo $asset_graph_width ?>&amp;height=<?php echo $asset_graph_height ?>&amp;v=4&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . ""); ?>" width="<?php echo $asset_graph_width ?>" height="<?php echo $asset_graph_height ?>" border="0" /></a>
<?php endif; ?>
<?php else: ?>
<p><center>No data found for AS<?php echo $as; ?></center></p>
@ -147,7 +147,7 @@ foreach ($knownlinks as $link) {
echo "<tr><td style=\"border: 4px solid #fff;\">";
echo "<table style=\"border-collapse: collapse; margin: 0; padding: 0\"><tr>";
if (!isset($brighten_negative) || $brighten_negative) {
if ($brighten_negative) {
echo "<td width=\"9\" height=\"18\" style=\"background-color: #{$link['color']}\">&nbsp;</td>";
echo "<td width=\"9\" height=\"18\" style=\"opacity: 0.73; background-color: #{$link['color']}\">&nbsp;</td>";
} else {

View File

@ -14,15 +14,15 @@ $show95th = true;
$ntop = 20;
$showv6 = true;
$showtitledetail = true;
$hidelinkusagename = true; # $showtitledetail will need to be true to allow this
$hidelinkusagename = true; # $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
$whois = "/usr/bin/whois";
$assetpath = "asset";
$asset_cache_life = "604800"; # 604800 seconds = 7 days
$asset_cache_life = "604800"; # 604800 seconds = 7 days
$compat_rrdtool12 = false; # compatibility with RRDtool 1.2 (show95th will not work if this is set)
$brighten_negative = true; # brighten the "negative" part of graphs
$compat_rrdtool12 = false; # compatibility with RRDtool 1.2 (show95th will not work if this is set)
/* Custom links to be shown for each AS. You can use %as% as a
placeholder for the ASN. */

23
www/config_defaults.inc Normal file
View File

@ -0,0 +1,23 @@
<?php
/* DO NOT EDIT THIS FILE - override these variables in config.inc instead */
/* Default graph size if no parameters are specified */
$default_graph_width = 600;
$default_graph_height = 360;
/* Size of graphs on top N AS page */
$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;
/* Defaults for other settings, introduced in recent versions */
$vertical_label = true; # vertical IN/OUT label in graph
$brighten_negative = true; # brighten the "negative" part of graphs

View File

@ -5,6 +5,7 @@
* written by Manuel Kasper <mk@neon1.net> for Monzoon Networks AG
*/
require_once("config_defaults.inc");
require_once('config.inc');
/* make sure we have enough memory, as some pages can be quite memory intensive */

View File

@ -13,8 +13,8 @@ if (!preg_match("/^[0-9a-zA-Z]+$/", $as))
header("Content-Type: image/png");
$width = 500;
$height = 300;
$width = $default_graph_width;
$height = $default_graph_height;
if (isset($_GET['width']))
$width = (int)$_GET['width'];
if (isset($_GET['height']))
@ -26,14 +26,27 @@ if (@$_GET['v'] == 6)
$knownlinks = getknownlinks();
$rrdfile = getRRDFileForAS($as);
if ($compat_rrdtool12) {
/* cannot use full-size-mode - must estimate height/width */
$height -= 65;
$width -= 81;
if ($vertical_label)
$width -= 16;
}
$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 ";
if($outispositive)
$cmd .= "--vertical-label '<- IN | OUT ->' ";
else
$cmd .= "--vertical-label '<- OUT | IN ->' ";
if (!$compat_rrdtool12)
$cmd .= "--full-size-mode ";
if ($vertical_label) {
if($outispositive)
$cmd .= "--vertical-label '<- IN | OUT ->' ";
else
$cmd .= "--vertical-label '<- OUT | IN ->' ";
}
if($showtitledetail && $_GET['dname'] != "")
$cmd .= "--title " . escapeshellarg($_GET['dname']) . " ";
@ -107,7 +120,7 @@ if ($compat_rrdtool12) {
/* generate graph area/stack for inbound */
$i = 0;
foreach ($knownlinks as $link) {
if ($outispositive && (!isset($brighten_negative) || $brighten_negative))
if ($outispositive && $brighten_negative)
$col = $link['color'] . "BB";
else
$col = $link['color'];
@ -122,7 +135,7 @@ foreach ($knownlinks as $link) {
/* generate graph area/stack for outbound */
$i = 0;
foreach ($knownlinks as $link) {
if ($outispositive || !(!isset($brighten_negative) || $brighten_negative))
if ($outispositive || !$brighten_negative)
$col = $link['color'];
else
$col = $link['color'] . "BB";

View File

@ -58,8 +58,8 @@ foreach ($asstats as $as => $totaldata) {
/* now make a beautiful graph :) */
header("Content-Type: image/png");
$width = 500;
$height = 300;
$width = $default_graph_width;
$height = $default_graph_height;
if ($_GET['width'])
$width = (int)$_GET['width'];
if ($_GET['height'])
@ -67,10 +67,19 @@ if ($_GET['height'])
$knownlinks = getknownlinks();
if ($compat_rrdtool12) {
/* cannot use full-size-mode - must estimate height/width */
$height -= 205;
$width -= 81;
}
$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 ";
if (!$compat_rrdtool12)
$cmd .= "--full-size-mode ";
if($showtitledetail && $_GET['dname'] != "")
$cmd .= "--title " . escapeshellarg($_GET['dname']) . " ";
else

View File

@ -40,10 +40,10 @@ $class = (($i % 2) == 0) ? "even" : "odd";
<?php endif; ?>
<td>
<?php if ($showv6): ?>
<img alt="link graph" src="linkgraph.php?link=<?php echo $link['tag']; ?>&amp;width=500&amp;height=300&amp;v=4&amp;dname=<?php echo rawurlencode($link['descr'] . " - IPV4"); ?>" width="581" height="499" border="0" />
<img alt="link graph" src="linkgraph.php?link=<?php echo $link['tag']; ?>&amp;width=500&amp;height=300&amp;v=6&amp;dname=<?php echo rawurlencode($link['descr'] . " - IPV4"); ?>" width="581" height="499" 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=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'] . " - IPV4"); ?>" 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=500&amp;height=300&amp;dname=<?php echo rawurlencode($link['descr'] . ""); ?>" width="581" height="481" 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;dname=<?php echo rawurlencode($link['descr'] . ""); ?>" width="<?php echo $linkusage_graph_width ?>" height="<?php echo $linkusage_graph_height ?>" border="0" />
<?php endif; ?>
</td>
</tr>

View File

@ -89,10 +89,10 @@ echo join(" | ", $htmllinks);
</th>
<td>
<?php if ($showv6): ?>
<a href="history.php?v=4&amp;as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=500&amp;height=150&amp;v=4&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . " - IPV4"); ?>&amp;start=<?php echo $start; ?>&amp;end=<?php echo $end; ?>" width="597" height="207" border="0" /></a>
<a href="history.php?v=6&amp;as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=500&amp;height=150&amp;v=6&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . " - IPV6"); ?>&amp;start=<?php echo $start; ?>&amp;end=<?php echo $end; ?>" width="597" height="207" border="0" /></a>
<a href="history.php?v=4&amp;as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=<?php echo $top_graph_width ?>&amp;height=<?php echo $top_graph_height ?>&amp;v=4&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . " - IPV4"); ?>&amp;start=<?php echo $start; ?>&amp;end=<?php echo $end; ?>" width="<?php echo $top_graph_width ?>" height="<?php echo $top_graph_height ?>" border="0" /></a>
<a href="history.php?v=6&amp;as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=<?php echo $top_graph_width ?>&amp;height=<?php echo $top_graph_height ?>&amp;v=6&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . " - IPV6"); ?>&amp;start=<?php echo $start; ?>&amp;end=<?php echo $end; ?>" width="<?php echo $top_graph_width ?>" height="<?php echo $top_graph_height ?>" border="0" /></a>
<?php else: ?>
<a href="history.php?as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=500&amp;height=150&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . ""); ?>&amp;start=<?php echo $start; ?>&amp;end=<?php echo $end; ?>" width="581" height="189" border="0" /></a>
<a href="history.php?as=<?php echo $as; ?>" target="_blank"><img alt="AS graph" src="gengraph.php?as=<?php echo $as; ?>&amp;width=<?php echo $top_graph_width ?>&amp;height=<?php echo $top_graph_height ?>&amp;nolegend=1&amp;dname=<?php echo rawurlencode("AS" . $as . " - " . $asinfo['descr'] . ""); ?>&amp;start=<?php echo $start; ?>&amp;end=<?php echo $end; ?>" width="<?php echo $top_graph_width ?>" height="<?php echo $top_graph_height ?>" border="0" /></a>
<?php endif; ?>
</td>
</tr>
@ -108,7 +108,7 @@ foreach ($knownlinks as $link) {
echo "<tr><td style=\"border: 4px solid #fff;\">";
echo "<table style=\"border-collapse: collapse; margin: 0; padding: 0\"><tr>";
if (!isset($brighten_negative) || $brighten_negative) {
if ($brighten_negative) {
echo "<td width=\"9\" height=\"18\" style=\"background-color: #{$link['color']}\">&nbsp;</td>";
echo "<td width=\"9\" height=\"18\" style=\"opacity: 0.73; background-color: #{$link['color']}\">&nbsp;</td>";
} else {