function GraphTraffic($rrd, $t) { global $errlbl, $trflbl, $debug, $stalbl; $c = 0; $drawin = ''; $drawout = ''; $outdir = ''; $odef = ''; $idef = ''; $inmod = 'AREA'; $n = count($rrd); if ($t == 'trf') { $idef = 'inoct'; $odef = 'outoct'; $tit = $_SESSION['gbit'] ? "{$trflbl} [Bit/s]" : "{$trflbl} [Byte/s]"; } elseif ($t == 'err') { $idef = 'inerr'; $odef = 'outerr'; $tit = "{$errlbl}/s"; } elseif ($t == 'dsc') { $idef = 'indisc'; $odef = 'outdisc'; $tit = 'Discards/s'; } elseif ($t == 'sta') { $tit = "IF {$stalbl}"; } else { $idef = 'inbcast'; $tit = 'Broadcasts/s'; } if ($_SESSION['gneg']) { $outdir = '-'; $outmod = 'AREA'; } else { $outmod = 'LINE2'; } foreach (array_keys($rrd) as $i) { $c++; $eol = $c == $n ? "\\l" : ""; $il = str_replace(":", "\\:", $i); if ($t == 'sta') { $drawin .= "DEF:sta{$c}={$rrd[$i]}:status:AVERAGE "; $drawin .= "CDEF:sh{$c}=sta{$c},0,EQ {$inmod}:sh{$c}#cc8844: "; $drawin .= "CDEF:dn{$c}=sta{$c},1,2,LIMIT,1,0,IF {$inmod}:dn{$c}#cccc44: "; #TODO remove $inmod and just multiply by $c to avoid stacking problem? $drawin .= "CDEF:up{$c}=sta{$c},2,GT {$inmod}:up{$c}#44cc44: "; $drawin .= "CDEF:un{$c}=sta{$c},UN {$inmod}:un{$c}#cccccc:\"{$il} "; } elseif ($t == 'trf' and $_SESSION['gbit']) { $drawin .= "DEF:inbyte{$c}={$rrd[$i]}:{$idef}:AVERAGE "; $drawin .= "CDEF:{$idef}{$c}=inbyte{$c},8,* {$inmod}:{$idef}{$c}" . GetCol($t, $c, 0) . ":\"{$il} in "; $drawout .= "DEF:outbyte{$c}={$rrd[$i]}:{$odef}:AVERAGE "; $drawout .= "CDEF:{$odef}{$c}=outbyte{$c},{$outdir}8,* {$outmod}:{$odef}{$c}" . GetCol($t, $c, 3) . ":\"{$il} out"; } else { $drawin .= "DEF:{$idef}{$c}={$rrd[$i]}:{$idef}:AVERAGE {$inmod}:{$idef}{$c}" . GetCol($t, $c, 0) . ":\"{$il} in "; $drawout .= "DEF:outgr{$c}={$rrd[$i]}:{$odef}:AVERAGE "; $drawout .= "CDEF:{$odef}{$c}=outgr{$c},{$outdir}1,* {$outmod}:{$odef}{$c}" . GetCol($t, $c, 3) . ":\"{$il} out"; } if ($t == 'trf' and $n == 1) { #and !$_SESSION['gneg']){# Couldn't figure out yet, why 95% is incorrect on negative traffic??!? $drawin .= "\" VDEF:tio95={$idef}{$c},95,PERCENT GPRINT:tio95:\"%7.2lf%s\" HRULE:tio95#ffcc44:\"95%\" "; $drawout .= "\" VDEF:too95={$odef}{$c},95,PERCENT GPRINT:too95:\"%7.2lf%s\" HRULE:too95#ff4444:\"95%\" "; $drawin .= "GPRINT:{$idef}{$c}:MIN:\" %7.2lf%s min\" GPRINT:{$idef}{$c}:MAX:\" %7.2lf%s max\" GPRINT:{$idef}{$c}:AVERAGE:\" %7.2lf%s avg "; $drawout .= "GPRINT:{$odef}{$c}:MIN:\" %7.2lf%s min\" GPRINT:{$odef}{$c}:MAX:\" %7.2lf%s max\" GPRINT:{$odef}{$c}:AVERAGE:\" %7.2lf%s avg "; } $drawin .= "{$eol}\" "; $drawout .= "{$eol}\" "; if ($debug) { $drawin .= "\n\t"; $drawout .= "\n\t"; } $inmod = 'STACK'; $outmod = 'STACK'; } if ($t == 'brc' or $t == 'sta') { return array($drawin, $tit); } else { return array($drawin . $drawout, $tit); } }
function NodOS($ina, $opa, $sta, $lim, $ord) { global $link, $modgroup, $self, $stslbl, $srtlbl, $typlbl, $qtylbl; ?> <table class="full fixed"><tr><td class="helper"> <h2>OS <?php echo $stslbl; ?> </h2> <canvas id="nosdnt" style="display: block;margin: 0 auto;padding: 10px;" width="400" height="300"></canvas> <table class="content"><tr class="<?php echo $modgroup[$self]; ?> 2"> <th colspan="2"><img src="img/16/cbox.png"><br>OS</th> <th><img src="img/16/nods.png"><br>Nodes</th></tr> <?php if ($ord) { $ocol = "nodos"; $srt = "{$srtlbl}: OS"; } else { $ocol = "cnt desc"; $srt = "{$srtlbl}: {$qtylbl}"; } $query = GenQuery('nodes', 'g', 'nodos', $ocol, $lim, array($ina), array($opa), array($sta), array(), 'LEFT JOIN devices USING (device)'); $res = DbQuery($query, $link); if ($res) { $row = 0; $chd = array(); while ($r = DbFetchRow($res)) { if ($row % 2) { $bg = "txta"; $bi = "imga"; } else { $bg = "txtb"; $bi = "imgb"; } $row++; if ($r[0]) { $uo = urlencode($r[0]); $op = "="; } else { $uo = "^\$"; $op = "~"; } $chd[] = array('value' => $r[1], 'color' => GetCol('231', $row, 3)); echo "<tr class=\"{$bg}\"><th class=\"{$bi}\">{$row}</th>\n"; echo "<td>{$r['0']}</td><td nowrap>" . Bar($r[1], GetCol('231', $row, 3), 'ls') . " <a href=Nodes-List.php?in[]=nodos&op[]={$op}&st[]={$uo}>{$r['1']}</a></td></tr>\n"; } } ?> </table> <table class="content" > <tr class="<?php echo $modgroup[$self]; ?> 2"><td><?php echo $row; ?> OS, <?php echo $srt; ?> </td></tr> </table> <script language="javascript"> var data = <?php echo json_encode($chd, JSON_NUMERIC_CHECK); ?> var ctx = document.getElementById("nosdnt").getContext("2d"); var myNewChart = new Chart(ctx).Doughnut(data); </script> </td><td class="helper"> <h2><?php echo $typlbl; ?> <?php echo $stslbl; ?> </h2> <canvas id="ntydnt" style="display: block;margin: 0 auto;padding: 10px;" width="400" height="300"></canvas> <table class="content"><tr class="<?php echo $modgroup[$self]; ?> 2"> <th colspan="2"><img src="img/16/abc.png"><br><?php echo $typlbl; ?> </th> <th><img src="img/16/nods.png"><br>Nodes</th></tr> <?php if ($ord) { $ocol = "nodtype"; $srt = "{$srtlbl}: {$typlbl}"; } else { $ocol = "cnt desc"; $srt = "{$srtlbl}: {$qtylbl}"; } $query = GenQuery('nodes', 'g', 'nodtype', $ocol, $lim, array($ina), array($opa), array($sta), array(), 'LEFT JOIN devices USING (device)'); $res = DbQuery($query, $link); if ($res) { $row = 0; $chd = array(); while ($r = DbFetchRow($res)) { if ($row % 2) { $bg = "txta"; $bi = "imga"; } else { $bg = "txtb"; $bi = "imgb"; } $row++; if ($r[0]) { $uo = urlencode($r[0]); $op = "="; } else { $uo = "^\$"; $op = "~"; } $chd[] = array('value' => $r[1], 'color' => GetCol('123', $row, 3)); echo "<tr class=\"{$bg}\"><th class=\"{$bi}\">{$row}</th>\n"; echo "<td>{$r['0']}</td><td nowrap>" . Bar($r[1], GetCol('123', $row, 3), 'ls') . " <a href=Nodes-List.php?in[]=nodos&op[]={$op}&st[]={$uo}>{$r['1']}</a></td></tr>\n"; } } ?> </table> <table class="content" > <tr class="<?php echo $modgroup[$self]; ?> 2"><td><?php echo $row; ?> <?php echo $typlbl; ?> , <?php echo $srt; ?> </td></tr> </table> <script language="javascript"> var data = <?php echo json_encode($chd, JSON_NUMERIC_CHECK); ?> var ctx = document.getElementById("ntydnt").getContext("2d"); var myNewChart = new Chart(ctx).Doughnut(data); </script> </td></tr></table> <p> <?php }