Commit 4ff73f0d authored by 's avatar
Browse files

Added support for multiple host, which includes multiple interface support too.

Tested with new GUI (PHP); CGI GUI shows just first two hosts.

Flow is assigned to opposite sensor when it appears there too (same flow).
Unassigned flows are dropped, so filter has not to be exact,
something void like "greater 0" should work.

The differences against prev. impl. of multiple interface support
(subject to keep or change?):

prev.:
Usage: hostA:if1:if2, hostB... "filter"

now:
Usage: "hostA:if1, hostA:if2" "hostB..." "filter"

-more typing
+DiMAPI syntax
?no need to parse and store device names

prev.:
mapi_stats("hostA:if1", &(stats1->statstable[i%countA]))
mapi_stats("hostA:if2", &(stats1->statstable[++i%countA]))

now:
mapi_stats("host1:if1, host1:if2", &host[0].mapi_stats_dev).

-order of devices not guaranteed so reordering* is done via pointers
+less mapi function calls
?no need to store device names
?unique interface names required in case of reordering*
*)for now, order never changes

prev:
  for(i = 0; i < stats1.count;i++) { // host1
    stats = stats1.statstable[i];
    stats.hostname...
  for(i = 0; i < stats2.count;i++) { // host2
    ...

now:
  for(h = 0; h < hosts; h++) {
    for(d = 0; d < host[h].devices; d++) {
      stats = host[h].mapi_stats_dev[d];
      host[h].name...

parse_hosts() -- not a function (more simple as device names are not parsed and
stored, just counted)

get_mapi_stats() -- not a function (more simple because of prev. mentioned diffs)

GUI (CSV, PHP, JS) -- several updates



git-svn-id: file:///home/svn/mapi/trunk@1340 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 662258a4
......@@ -17,7 +17,7 @@ packetloss_top = "/path/to/packetloss/packetloss_top.csv"
# enable or disable tops
enable_packetloss_top
#enable_appmon_top
enable_protocol_top
# keep as is
output = "-"
......@@ -8,7 +8,7 @@ require_once "${DIR}lib/graph.php";
# }}}
$allowed_args = ",predefined,start,end,width,height,upperLimit,lowerLimit,onlyGraph,title,";
$allowed_args = ",host0rrddsid,host1rrddsid,predefined,start,end,width,height,upperLimit,lowerLimit,onlyGraph,title,";
foreach(array_keys($_GET) as $key) {
if(strpos($allowed_args,",$key,") !== false) {
......@@ -26,8 +26,8 @@ foreach(array_keys($_GET) as $key) {
//);
//$predefined = $predefinedarr[$predefined]; // filter values
if($predefined != "") $graph = new Graph("packetcount", $predefined, "", "", $width, $height);
else $graph = new Graph("packetcount", "", $start, $end, $width, $height, $title);
if($predefined != "") $graph = new Graph("packetcount", $host0rrddsid, $host1rrddsid, $predefined, "", "", $width, $height);
else $graph = new Graph("packetcount", $host0rrddsid, $host1rrddsid, "", $start, $end, $width, $height, $title);
//$graph->dry_run();
$graph->flush();
......
......@@ -8,7 +8,7 @@ require_once "${DIR}lib/graph.php";
# }}}
$allowed_args = ",predefined,start,end,width,height,upperLimit,lowerLimit,onlyGraph,title,";
$allowed_args = ",host0rrddsid,host1rrddsid,predefined,start,end,width,height,upperLimit,lowerLimit,onlyGraph,title,";
foreach(array_keys($_GET) as $key) {
if(strpos($allowed_args,",$key,") !== false) {
......@@ -26,8 +26,8 @@ foreach(array_keys($_GET) as $key) {
//);
//$predefined = $predefinedarr[$predefined]; // filter values
if($predefined != "") $graph = new Graph("packetloss", $predefined, "", "", $width, $height);
else $graph = new Graph("packetloss", "", $start, $end, $width, $height, $title);
if($predefined != "") $graph = new Graph("packetloss", $host0rrddsid, $host1rrddsid, $predefined, "", "", $width, $height);
else $graph = new Graph("packetloss", $host0rrddsid, $host1rrddsid, "", $start, $end, $width, $height, $title);
//$graph->dry_run();
$graph->flush();
......
......@@ -235,7 +235,6 @@ $form["time"] = new FormElement( // select - option (more selects)
clear: left;
margin-top: 2em;
border-top: 5px solid #F0F0F0;
color: gray;
}
.thetop {
margin-top: 2em;
......@@ -307,7 +306,7 @@ $form["time"] = new FormElement( // select - option (more selects)
echo <<<EOD
<div class="tr">
<span class="th"><label for="_$name_$key">$hostname</label></span>
<span class="td"><input id="_$name_$key" type="checkbox" name="${name}[]"$checked value="$key" disabled="disabled" /></span>
<span class="td"><input id="_$name_$key" type="checkbox" name="${name}[]"$checked value="$key" /></span>
</div>\n
EOD;
}
......@@ -525,86 +524,113 @@ $height = ($form["graph_size"]->isChecked("large") ? "300" : ($form["graph_size"
$widthpx = ($width + 97) . "px";
$heightpx = ($height + 93) . "px";
switch($form["time_type"]->selectedvals) {
case "predefined":
$name = $form["times"]->name;
foreach($form["times"]->elementvals as $key => $val) {
$checked = $form["times"]->isChecked($key);
if($checked) {
$aquery = arr2query(array(
"predefined" => $key,
"width" => 500,
"height" => 300
));
$iquery = arr2query(array(
"predefined" => $key,
"width" => $width,
"height" => $height
));
$name2 = $form["characteristics"]->name;
foreach($form["characteristics"]->elementvals as $key2 => $val2) {
foreach($form["subject"]->elementvals as $key0 => $val0) {
$checked0 = $form["subject"]->isChecked($key0);
$host0rrddsid = $val0["rrddsid"]["value"]; // key0
$host0name = $val0["hostname"]["value"];
if($checked0)
foreach($form["subject"]->elementvals as $key1 => $val1) {
$checked1 = $form["subject"]->isChecked($key1);
$host1rrddsid = $val1["rrddsid"]["value"]; // key1
$host1name = $val1["hostname"]["value"];
if($checked1) {
if($host1rrddsid == $host0rrddsid) break;
switch($form["time_type"]->selectedvals) {
case "predefined":
$name = $form["times"]->name;
foreach($form["times"]->elementvals as $key => $val) {
$checked = $form["times"]->isChecked($key);
if($checked) {
$aquery = arr2query(array(
"host0rrddsid" => $host0rrddsid,
"host1rrddsid" => $host1rrddsid,
"predefined" => $key,
"width" => 500,
"height" => 300
));
$iquery = arr2query(array(
"host0rrddsid" => $host0rrddsid,
"host1rrddsid" => $host1rrddsid,
"predefined" => $key,
"width" => $width,
"height" => $height
));
$name2 = $form["characteristics"]->name;
foreach($form["characteristics"]->elementvals as $key2 => $val2) {
echo <<<EOD
<div class="graph">
<a href="graph/$key2.php?$aquery" title="TODO"><img src="graph/$key2.php?$iquery" width="$widthpx" height="$heightpx" class="mirage" alt="TODO" title="TODO" /><br />
<span style="width: $widthpx; text-align: center;">$val ($val2)</span></a>
</div>\n
<div class="graph">
<a href="graph/$key2.php?$aquery" title="TODO"><img src="graph/$key2.php?$iquery" width="$widthpx" height="$heightpx" class="mirage" alt="TODO" title="TODO" /><br />
<span style="width: $widthpx; text-align: center;">$val ($val2)</span></a>
</div>\n
EOD;
}
}
}
break;
case "start_time":
$aquery = arr2query(array(
"start" => $gmseconds,
"end" => ($gmseconds + time_to_sec($form["time_length_number"]->selectedvals, $form["time_length_unit"]->selectedvals)),
"width" => 500,
"height" => 300
));
$iquery = arr2query(array(
"start" => $gmseconds,
"end" => ($gmseconds + time_to_sec($form["time_length_number"]->selectedvals, $form["time_length_unit"]->selectedvals)),
"width" => $width,
"height" => $height
));
$name2 = $form["characteristics"]->name;
foreach($form["characteristics"]->elementvals as $key2 => $val2) {
}
}
}
break;
case "start_time":
$aquery = arr2query(array(
"host0rrddsid" => $host0rrddsid,
"host1rrddsid" => $host1rrddsid,
"start" => $gmseconds,
"end" => ($gmseconds + time_to_sec($form["time_length_number"]->selectedvals, $form["time_length_unit"]->selectedvals)),
"width" => 500,
"height" => 300
));
$iquery = arr2query(array(
"host0rrddsid" => $host0rrddsid,
"host1rrddsid" => $host1rrddsid,
"start" => $gmseconds,
"end" => ($gmseconds + time_to_sec($form["time_length_number"]->selectedvals, $form["time_length_unit"]->selectedvals)),
"width" => $width,
"height" => $height
));
$name2 = $form["characteristics"]->name;
foreach($form["characteristics"]->elementvals as $key2 => $val2) {
echo <<<EOD
<div class="graph">
<a href="graph/$key2.php?$aquery" title="User Defined: From &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height.">
<img src="graph/$key2.php?$iquery" width="$widthpx" height="$heightpx" alt="User Defined: From &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height." title="—" />
</a>
</div>\n
<div class="graph">
<a href="graph/$key2.php?$aquery" title="User Defined: From &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height.">
<img src="graph/$key2.php?$iquery" width="$widthpx" height="$heightpx" alt="User Defined: From &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height." title="—" />
</a>
</div>\n
EOD;
}
break;
case "end_time":
$aquery = arr2query(array(
"start" => ($gmseconds - time_to_sec($form["time_length_number"]->selectedvals, $form["time_length_unit"]->selectedvals)),
"end" => $gmseconds,
"width" => 500,
"height" => 300
));
$iquery = arr2query(array(
"start" => ($gmseconds - time_to_sec($form["time_length_number"]->selectedvals, $form["time_length_unit"]->selectedvals)),
"end" => $gmseconds,
"width" => $width,
"height" => $height
));
$name2 = $form["characteristics"]->name;
foreach($form["characteristics"]->elementvals as $key2 => $val2) {
}
break;
case "end_time":
$aquery = arr2query(array(
"host0rrddsid" => $host0rrddsid,
"host1rrddsid" => $host1rrddsid,
"start" => ($gmseconds - time_to_sec($form["time_length_number"]->selectedvals, $form["time_length_unit"]->selectedvals)),
"end" => $gmseconds,
"width" => 500,
"height" => 300
));
$iquery = arr2query(array(
"host0rrddsid" => $host0rrddsid,
"host1rrddsid" => $host1rrddsid,
"start" => ($gmseconds - time_to_sec($form["time_length_number"]->selectedvals, $form["time_length_unit"]->selectedvals)),
"end" => $gmseconds,
"width" => $width,
"height" => $height
));
$name2 = $form["characteristics"]->name;
foreach($form["characteristics"]->elementvals as $key2 => $val2) {
echo <<<EOD
<div class="graph">
<a href="graph/$key2.php?$aquery" title="User Defined: From &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height.">
<img src="graph/$key2.php?$iquery" width="$widthpx" height="$heightpx" alt="User Defined: From &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height." title="—" />
</a>
</div>\n
<div class="graph">
<a href="graph/$key2.php?$aquery" title="User Defined: From &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height.">
<img src="graph/$key2.php?$iquery" width="$widthpx" height="$heightpx" alt="User Defined: From &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height." title="—" />
</a>
</div>\n
EOD;
}
break;
}
}
}
break;
}
}
?>
<?php /*
<div class="graph">
......@@ -651,7 +677,7 @@ EOD;
<div class="graph">
<?php
echo <<<EOD
<a href="graph/packetloss.php?$aquery" title="Packetloss Default Time from &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height."><img id="packetloss" src="graph/packetloss.php?$iquery" width="497px" height="293px" alt="Packetloss Default Time from &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height." title="—" /></a>\n
<a href="graph/packetloss.php?$aquery" title="Packetloss Default Time from &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height."><img id="packetloss" src="graph/packetloss.php?$iquery" width="497px" height="293px" alt="Packetloss Default Time from &amp;start to &amp;end. Image dimensions: &amp;width × &amp;height." title="—" /></a>\n
EOD;
}
?>
......@@ -684,7 +710,7 @@ EOD;
<div class="table">
<table class="vertical thetop">
<caption>Packetloss</caption>
<caption>Packetloss Top</caption>
<tbody>
<?php
......@@ -719,12 +745,12 @@ EOD;
<?php
//if(count($packetlossTop->top2rows) > 0) {
if(isset($config->enable_appmon_top)) {
if(isset($config->enable_protocol_top)) {
?>
<div class="table">
<table class="vertical thetop">
<caption>Appmon</caption>
<caption>Protocol Top</caption>
<thead>
<tr><th scope="col" >Protocol</th> <th scope="col" class="right">Total pkts</th> <th scope="col" class="right">Lost pkts</th></tr>
......@@ -759,6 +785,9 @@ EOD;
<?php
echo "<span>".$packetlossTop->miscarr["ts"]["label"].": <span id=\"ts\">".date("H:i d F Y", $packetlossTop->miscarr["ts"]["value"])."</span></span>";
?>
<span class="note line">* or ".": Data are up-to-date (timesamp has changed since last refresh, service is running).</span>
<span class="note line">?: Data are NOT up-to-date (timestamp has NOT changed since last refresh, service probably NOT running).</span>
</span>
</label>
</div>
</form>
......
......@@ -30,6 +30,8 @@ var packetlossTop = {
delay: 10000, // 10s
tid: 0,
counter: 0,
last_ts: 0,
uptodate: 0,
rslash: ".*.*",
objarr: Array(),
......@@ -91,6 +93,8 @@ var packetlossTop = {
var value = arr[3];
if(id == "ts") {
packetlossTop.uptodate = (value > packetlossTop.last_ts);
packetlossTop.last_ts = value;
d = new Date();
d.setTime(value + "000");
value = (d.getHours() < 10 ? "0" + d.getHours() : d.getHours()) +
......@@ -114,10 +118,11 @@ var packetlossTop = {
for(var i = 0; i < packetlossTop.bufferarr.length; i++) {
var arr = packetlossTop.bufferarr[i].split(";");
var hid = arr[0];
if(hid.substr(0, 4) == "host") {
var id = arr[1];
var label = arr[2];
var value = arr[3];
if(hid == "host") {
var hid = arr[1];
var id = arr[2];
var label = arr[3];
var value = arr[4];
packetlossTop.hostarr.push({
id: hid,
value: {
......@@ -294,7 +299,10 @@ var packetlossTop = {
},
addSlash: function(str) {
return str + " " + packetlossTop.rslash.charAt(packetlossTop.counter % 4);
if(packetlossTop.uptodate)
return str + " " + packetlossTop.rslash.charAt(packetlossTop.counter % 4);
else
return str + " " + "?";
}
}
......
......@@ -31,14 +31,18 @@ class Graph {
var $height;
var $output = "-";
function Graph($type, $predefined, $start="now-3600s", $end="now", $width="500", $height="300", $title="Untitled") {
function Graph($type, $host0rrddsid, $host1rrddsid, $predefined, $start="now-3600s", $end="now", $width="500", $height="300", $title="Untitled") {
global $config, $predefinedTimes;
$this->cwd = $config->packetloss_home;
$this->rrdtool = $config->rrdtool;
$this->type = $type;
$this->predefined = $predefined;
$this->type = $type;
$this->host0id = $host0rrddsid; // backward compatibility
$this->host0rrddsid = $host0rrddsid;
$this->host1id = $host1rrddsid; // backward compatibility
$this->host1rrddsid = $host1rrddsid;
$this->predefined = $predefined;
$this->start = $start != "" ? $start : "now-3600s";
$this->end = $end != "" ? $end : "now";
......@@ -52,10 +56,11 @@ class Graph {
$line = trim($rarr[$i]);
$arr = explode(";", $line);
$hid = $arr[0];
if (substr($hid, 0, 4) == "host") {
$id = $arr[1];
$label = $arr[2];
$value = $arr[3];
if ($hid == "host") {
$hid = $arr[1];
$id = $arr[2];
$label = $arr[3];
$value = $arr[4];
$this->hostarr[$hid][$id] = array(
"label" => $label,
"value" => $value
......@@ -68,7 +73,7 @@ class Graph {
$this->rrd_filename = $config->packetloss_rrd;
if($this->predefined != "") {
list($avg, $dur) = explode("_", $this->predefined);
$this->title = "Packet Loss ratio \t(".($predefinedTimes[$this->predefined]).")";
$this->title = "Packet Loss ratio (".($predefinedTimes[$this->predefined]).")";
$this->start = "end-$dur";
}
else {
......@@ -84,7 +89,7 @@ class Graph {
$this->rrd_filename = $config->packetcount_rrd;
if($this->predefined != "") {
list($avg, $dur) = explode("_", $this->predefined);
$this->title = "Lost packets \t(".$predefinedTimes[$this->predefined].")";
$this->title = "Lost packets (".$predefinedTimes[$this->predefined].")";
$this->start = "end-$dur";
}
else {
......@@ -100,19 +105,25 @@ class Graph {
}
function __setup_command_packetloss() {
$host0 = $this->hostarr["host0"]["hostname"]["value"];
$host0name = $this->hostarr["$this->host0id"]["hostname"]["value"];
$host0rrddsid = $this->host0rrddsid;
$i = 0;
while($this->hostarr["host0"]["if$i"]) {
$host0 .= ($i == 0 ? "\:" : ",").$this->hostarr["host0"]["if$i"]["value"];
while($this->hostarr["$this->host0id"]["if$i"]) {
$host0 .= ($i == 0 ? "\:" : ",").$this->hostarr["$this->host0id"]["if$i"]["value"];
$i++;
};
$host1 = $this->hostarr["host1"]["hostname"]["value"];
$host1name = $this->hostarr["$this->host1id"]["hostname"]["value"];
$host1rrddsid = $this->host1rrddsid;
$i = 0;
while($this->hostarr["host1"]["if$i"]) {
$host1 .= ($i == 0 ? "\:" : ",").$this->hostarr["host1"]["if$i"]["value"];
while($this->hostarr["$this->host1id"]["if$i"]) {
$host1 .= ($i == 0 ? "\:" : ",").$this->hostarr["$this->host1id"]["if$i"]["value"];
$i++;
};
$flow0 = $host0rrddsid.$host1rrddsid;
$flow1 = $host1rrddsid.$host0rrddsid;
$this->command = <<<EOC
TZ=":GMT" "$this->rrdtool" graph "$this->output" $@ \
--width="$this->width" \
......@@ -124,30 +135,36 @@ TZ=":GMT" "$this->rrdtool" graph "$this->output" $@ \
--interlaced \
--vertical-label "Packet Loss Ratio [%]" \
--title "$this->title" \
"DEF:flow0=$this->rrd_filename:flow0:AVERAGE" \
"DEF:flow1=$this->rrd_filename:flow1:AVERAGE" \
"AREA:flow0#00FF00:$host0 to $host1" \
"DEF:$flow0=$this->rrd_filename:$flow0:AVERAGE" \
"DEF:$flow1=$this->rrd_filename:$flow1:AVERAGE" \
"AREA:$flow0#00FF00:$host0name to $host1name" \
"LINE:0" \
"AREA:flow1#0066FF:$host0 to $host1:STACK" \
"AREA:$flow1#0066FF:$host1name to $host0name:STACK" \
"LINE:0#000000"
EOC;
}
function __setup_command_packetcount() {
$host0 = $this->hostarr["host0"]["hostname"]["value"];
$host0name = $this->hostarr["$this->host0id"]["hostname"]["value"];
$host0rrddsid = $this->host0rrddsid;
$i = 0;
while($this->hostarr["host0"]["if$i"]) {
$host0 .= ($i == 0 ? "\:" : ",").$this->hostarr["host0"]["if$i"]["value"];
while($this->hostarr["$this->host0id"]["if$i"]) {
$host0 .= ($i == 0 ? "\:" : ",").$this->hostarr["$this->host0id"]["if$i"]["value"];
$i++;
};
$host1 = $this->hostarr["host1"]["hostname"]["value"];
$host1name = $this->hostarr["$this->host1id"]["hostname"]["value"];
$host1rrddsid = $this->host1rrddsid;
$i = 0;
while($this->hostarr["host1"]["if$i"]) {
$host1 .= ($i == 0 ? "\:" : ",").$this->hostarr["host1"]["if$i"]["value"];
while($this->hostarr["$this->host1id"]["if$i"]) {
$host1 .= ($i == 0 ? "\:" : ",").$this->hostarr["$this->host1id"]["if$i"]["value"];
$i++;
};
$flow0 = $host0rrddsid.$host1rrddsid;
$flow1 = $host1rrddsid.$host0rrddsid;
$this->command = <<<EOC
TZ=":GMT" "$this->rrdtool" graph "$this->output" $@ \
--width="$this->width" \
......@@ -159,11 +176,11 @@ TZ=":GMT" "$this->rrdtool" graph "$this->output" $@ \
--interlaced \
--vertical-label "Lost Packets" \
--title "$this->title" \
"DEF:flow0=$this->rrd_filename:flow0:AVERAGE" \
"DEF:flow1=$this->rrd_filename:flow1:AVERAGE" \
"AREA:flow0#00FF00:$host0 to $host1" \
"DEF:$flow0=$this->rrd_filename:$flow0:AVERAGE" \
"DEF:$flow1=$this->rrd_filename:$flow1:AVERAGE" \
"AREA:$flow0#00FF00:$host0name to $host1name" \
"LINE:0" \
"AREA:flow1#0066FF:$host0 to $host1:STACK" \
"AREA:$flow1#0066FF:$host1name to $host0name:STACK" \
"LINE:0#000000"
EOC;
......
......@@ -59,10 +59,11 @@ class PacketlossTop {
else {
$arr = explode(";", $line);
$hid = $arr[0];
if(substr($hid, 0, 4) == "host") {
$id = $arr[1];
$label = $arr[2];
$value = $arr[3];
if($hid == "host") {
$hid = $arr[1];
$id = $arr[2];
$label = $arr[3];
$value = $arr[4];
$this->hostarr[$hid][$id] = array(
"id" => $id,
"label" => $label,
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment