Documentation updated
git-svn-id: file:///home/svn/mapi/trunk@811 8d5bb341-7cf1-0310-8cf6-ba355fef3186
<?php | ||
require_once("common.php"); | ||
/* require_once("common.php"); */ | ||
define(NET_IMG, "cesnet2-20051216-passivem.jpg"); | ||
define(REMOTE_USERNAME, "abw"); | ||
define(GRAPH_SCRIPT, "/usr/local/abw/bin/rrd_graph_all.sh"); | ||
define(GRAPH_DIR, "/var/www/perfmon/abw/graph"); | ||
define(REMOTE_GRAPH_DIR, "/usr/local/abw/graph"); | ||
/* BEGINNING OF USER CONFIGURATION SECTION */ | ||
/* Picture of the monitored network to be shown in the user interface */ | ||
define(NET_IMG, "cesnet2-20060804-passivem.jpg"); | ||
/* | ||
* Define subjects | ||
*/ | ||
/* | ||
* This must be the same as "label" field in [subject] section in | ||
* the configuration file. | ||
* Single-word names (without spaces) refering to monitored links. | ||
* They must be the same as "label" field in [subject] section in | ||
* the abw.cfg configuration file. You can choose them here and edit | ||
* abw.cfg afterwards. | ||
*/ | ||
$subject_label=array( | ||
"GN2_CESNET", | ||
... | ... | @@ -30,13 +31,10 @@ $subject_label=array( |
"Usti_PoP" | ||
); | ||
/* If 1 then subject is disabled (shown gray in the form) */ | ||
$subject_disabled=array( 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 ); | ||
/* | ||
* This is what will appear as graph description, it can be anything, | ||
* but it is probably a good idea to make it the same as "description" | ||
* field in [subject] section in the configuration file. | ||
* Description of monitored links, can include spaces. It is probably a good | ||
* idea to make it the same as "description" field in [subject] section in | ||
* the abw.cfg configuration file (but it is not required). | ||
*/ | ||
$subject_description=array( | ||
"GN2 CESNET2", | ||
... | ... | @@ -54,10 +52,9 @@ $subject_description=array( |
/* | ||
* Hostnames where results are stored in RRD files and from which they should | ||
* be retrieved. It can be one central station that communicates with remote | ||
* be retrieved. It can be a central station that communicates with remote | ||
* monitoring stations via DiMAPI. Or it can be individual remote monitoring | ||
* stations if monitoring application runs locally on remote monitoring | ||
* stations and uses MAPI. | ||
* stations directly. | ||
*/ | ||
$subject_hostname=array( | ||
"jra1-2.cesnet.cz", | ||
... | ... | @@ -67,12 +64,22 @@ $subject_hostname=array( |
"perfmon-liberec.cesnet.cz", | ||
"perfmon-olomouc.cesnet.cz", | ||
"perfmon-ostrava.cesnet.cz", | ||
"perfmon-pardubice.cesnet.cz", | ||
"195.113.125.254", | ||
"perfmon-plzen.cesnet.cz", | ||
"perfmon1.cesnet.cz", | ||
"perfmon-usti.cesnet.cz" | ||
); | ||
/* If 1 then the subject is disabled (shown gray in the user interface) */ | ||
$subject_disabled=array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ); | ||
/* END OF USER CONFIGURATION SECTION */ | ||
define(REMOTE_USERNAME, "abw"); | ||
define(GRAPH_SCRIPT, "/usr/local/abw/bin/rrd_graph_all.sh"); | ||
define(GRAPH_DIR, "/var/www/perfmon/abw/graph"); | ||
define(REMOTE_GRAPH_DIR, "/usr/local/abw/graph"); | ||
/* | ||
* Predefined time intervals and granularities | ||
* | ||
... | ... | @@ -138,6 +145,44 @@ $graph_type_description=array("L4", "Application"); |
$monthNumberToLongName=array("January", "February", "March", "April", "May", | ||
"June", "July", "August", "September", "October", "November", "December"); | ||
function time_to_sec($number, $unit) { | ||
switch ($unit) { | ||
case "Seconds": | ||
return $number; | ||
case "Minutes": | ||
return $number * 60; | ||
case "Hours": | ||
return $number * 3600; | ||
case "Days": | ||
return $number * 86400; | ||
case "Weeks": | ||
return $number * 86400 * 7; | ||
case "Months": | ||
return $number * 86400 * 30; | ||
case "Years": | ||
return $number * 86400 * 365; | ||
default: | ||
return -1; | ||
} | ||
} /* time_to_sec() */ | ||
function time_diff($time1, $time2) { | ||
if ($time2["sec"] > $time1["sec"]) { | ||
if ($time2["sec"] > ($time1["sec"]+1)) | ||
$res=$time2["sec"] - $time1["sec"]; | ||
else | ||
$res=0; | ||
$res=$res+(float)(1000000-$time1["usec"])/1000000 + | ||
(float)($time2["usec"])/1000000; | ||
} | ||
else | ||
$res=(float)($time2["usec"]-$time1["usec"])/1000000; | ||
return $res; | ||
} /* time_diff() */ | ||
/* | ||
* Start application | ||
*/ | ||
... | ... | @@ -258,46 +303,92 @@ echo "</table></td>\n"; |
echo "<td> </td><td><p>Start or end time:<br>"; | ||
echo "<select name=time_hour>"; | ||
for ($i=0; $i<=23; $i++) { | ||
echo "<option value=$i"; | ||
if ($time_hour==$i) | ||
echo " selected"; | ||
echo ">"; | ||
printf("%02d", $i); | ||
echo "</option>\n"; | ||
} | ||
echo "</select>\n"; | ||
echo "<select name=time_minute>"; | ||
for ($i=0; $i<=59; $i++) { | ||
echo "<option value=$i"; | ||
if ($time_minute==$i) | ||
echo " selected"; | ||
echo ">"; | ||
printf("%02d", $i); | ||
echo "</option>\n"; | ||
} | ||
echo "</select>\n"; | ||
echo "<select name=time_day>"; | ||
for ($i=1; $i<=31; $i++) | ||
echo "<option value=$i>$i</option>\n"; | ||
for ($i=1; $i<=31; $i++) { | ||
echo "<option value=$i"; | ||
if ($time_day==$i) | ||
echo " selected"; | ||
echo ">$i</option>\n"; | ||
} | ||
echo "</select>\n"; | ||
echo "<select name=time_month>"; | ||
for ($i=1; $i<=12; $i++) | ||
echo "<option value=$i>" . $monthNumberToLongName[$i-1] . "</option>\n"; | ||
for ($i=1; $i<=12; $i++) { | ||
echo "<option value=$i"; | ||
if ($time_month==$i) | ||
echo " selected"; | ||
echo ">" . $monthNumberToLongName[$i-1] . "</option>\n"; | ||
} | ||
echo "</select>\n"; | ||
echo "<select name=time_year>"; | ||
for ($i=2006; $i<=2015; $i++) | ||
echo "<option value=$i>$i</option>\n"; | ||
for ($i=2006; $i<=2015; $i++) { | ||
echo "<option value=$i"; | ||
if ($time_year==$i) | ||
echo " selected"; | ||
echo ">$i</option>\n"; | ||
} | ||
echo "</select>\n"; | ||
echo "<p>Time length:<br>\n"; | ||
echo "<input type=text size=3 name=time_length_number></input>\n"; | ||
echo "<input type=text size=3 name=time_length_number value=\"$time_length_number\"></input>\n"; | ||
echo "<select name=time_length_unit>"; | ||
$time_length_units=array("Minutes", "Hours", "Days", "Weeks", "Months", | ||
"Years"); | ||
foreach ($time_length_units as $value) | ||
echo "<option value=$value>$value</option>\n"; | ||
foreach ($time_length_units as $value) { | ||
echo "<option value=$value"; | ||
if ($time_length_unit==$value) | ||
echo " selected"; | ||
echo ">$value</option>\n"; | ||
} | ||
echo "</select>\n"; | ||
/* Interval + avg/max are as a separate table */ | ||
echo "<p><table><tr><td>Interval:</td><td>Avg/Max:</td></tr><tr>\n"; | ||
echo "<td><input type=text size=3 name=r1_number></input>\n"; | ||
echo "<td><input type=text size=3 name=r1_number value=\"$r1_number\"></input>\n"; | ||
echo "<select name=r1_unit>"; | ||
$r1_units=array("Seconds", "Minutes", "Hours", "Days", "Weeks", "Months", | ||
"Years"); | ||
foreach ($r1_units as $value) | ||
echo "<option value=$value>$value</option>\n"; | ||
foreach ($r1_units as $value) { | ||
echo "<option value=$value"; | ||
if ($r1_unit==$value) | ||
echo " selected"; | ||
echo ">$value</option>\n"; | ||
} | ||
echo "</select></td>\n"; | ||
echo "<td><input type=text size=3 name=r2_number></input>\n"; | ||
echo "<td><input type=text size=3 name=r2_number value=\"$r2_number\"></input>\n"; | ||
echo "<select name=r2_unit>"; | ||
$r2_units=array("Seconds", "Minutes", "Hours", "Days", "Weeks", "Months", | ||
"Years"); | ||
foreach ($r2_units as $value) | ||
echo "<option value=$value>$value</option>\n"; | ||
foreach ($r2_units as $value) { | ||
echo "<option value=$value"; | ||
if ($r2_unit==$value) | ||
echo " selected"; | ||
echo ">$value</option>\n"; | ||
} | ||
echo "</select></td>\n"; | ||
echo "</tr></table>\n"; | ||
... | ... | @@ -307,22 +398,22 @@ if (!isset($time_type)) |
echo "<p>Time type:<br>\n"; | ||
echo "Predefined <input type=radio name=\"time_type\" value=\"predefined\""; | ||
if (!strcmp($time_type, "predefined")) | ||
echo " selected"; | ||
echo " checked"; | ||
echo ">"; | ||
echo " Start time <input type=radio name=\"time_type\" value=\"start_time\""; | ||
if (!strcmp($time_type, "start_time")) | ||
echo " selected"; | ||
echo " checked"; | ||
echo ">"; | ||
echo " End time <input type=radio name=\"time_type\" value=\"end_time\""; | ||
if (!strcmp($time_type, "end_time")) | ||
echo " selected"; | ||
echo " checked"; | ||
echo ">"; | ||
echo "</td>\n"; | ||
echo "</tr></table\n"; | ||
echo "<p>Note: selecting all time periods will require a lot of processing time\n"; | ||
/* echo "<p>Note: selecting all time periods will require a lot of processing time\n"; */ | ||
echo "<p>\n"; | ||
echo "<input type=submit name=button_name value=\"Generate graphs\">\n"; | ||
... | ... | @@ -332,7 +423,6 @@ echo "</form><br>\n"; |
if ($action=="gen_graph") { | ||
$current_time=date("G:i:s Ymd", time()); | ||
echo "current_time: $current_time<br>\n"; | ||
foreach (glob(GRAPH_DIR . "/*") as $filename) | ||
unlink($filename); | ||
... | ... | @@ -342,11 +432,17 @@ if ($action=="gen_graph") { |
if (isset($graph_types) && | ||
(isset($subjects) || $subject_all) && | ||
(isset($times) || $time_all)) { | ||
(isset($times) || $time_all || strcmp($time_type, "predefined"))) { | ||
$total_time=0; | ||
echo "<p>\n"; | ||
echo "<table>\n"; | ||
echo "<tr><td>Graph type</td><td>Link</td><td>Time (gen / copy)</td></tr>\n"; | ||
/* Go over all selected graph types */ | ||
foreach($graph_types as $graph_type) { | ||
foreach($graph_type_label as $graph_type_key => $graph_type_value) { | ||
if (in_array($graph_type_value, $graph_types)) { | ||
/* Go over all subjects and for each selected subject issue | ||
one remote command to generate graphs */ | ||
... | ... | @@ -358,36 +454,110 @@ if ($action=="gen_graph") { |
$hostname=$subject_hostname[$i]; | ||
$command="ssh " . REMOTE_USERNAME . "@" . $subject_hostname[$i] . | ||
" \"" . GRAPH_SCRIPT . " -r --protocols=" . $graph_type . | ||
" --label=" . $subject_value . " --parameters_id=1"; | ||
$command="ssh " . REMOTE_USERNAME . "@" . $subject_hostname[$i] . " \"" . GRAPH_SCRIPT . " -r --protocols=" . $graph_type_value . " --label=" . $subject_value . " --parameters_id=1"; | ||
/* Append one --time argument for each selected time period */ | ||
if (!strcmp($time_type, "predefined")) { | ||
foreach ($time_description as $time_key => $time_value) { | ||
$time_label=$r1[$time_key] . "_" . $r2[$time_key] . "_" . | ||
$time_length[$time_key]; | ||
$time_label=$r1[$time_key] . "_" . $r2[$time_key] . | ||
"_" . $time_length[$time_key]; | ||
if ($time_all || in_array($time_label, $times)) { | ||
$hhmmYYYYMMDD=date("G:i Ymd", (int)(time() / $r2[$time_key]) * $r2[$time_key] - $r2[$time_key]); | ||
echo "r2: $r2[$time_key], hhmmYYMMDD: $hhmmYYYYMMDD<br>\n"; | ||
$command=$command . " --time=\\\"" . | ||
$r1[$time_key] . " " . $r2[$time_key] . " " . | ||
$time_length[$time_key] . " " . $hhmmYYYYMMDD . "\\\""; | ||
} | ||
} | ||
} /* if (!strcmp($time_type, "predefined")) */ | ||
else { | ||
/* echo "time_type: $time_type<br>\n"; | ||
echo "time_hour: $time_hour<br>\n"; | ||
echo "time_minute: $time_minute<br>\n"; | ||
echo "time_day: $time_day<br>\n"; | ||
echo "time_month: $time_month<br>\n"; | ||
echo "time_year: $time_year<br>\n"; | ||
echo "time_length_number: $time_length_number, time_length_unit: $time_length_unit<br>\n"; | ||
echo "r1_number: $r1_number, r1_unit: $r1_unit<br>\n"; | ||
echo "r2_number: $r2_number, r2_unit: $r2_unit<br>\n"; */ | ||
/* Convert R1, R2 and time length to seconds, | ||
adjust time_length to R2 boundary */ | ||
$r1_sec=time_to_sec($r1_number, $r1_unit); | ||
$r2_sec=time_to_sec($r2_number, $r2_unit); | ||
/* echo "r1_sec: $r1_sec, r2_sec: $r2_sec<br>\n"; */ | ||
if ($r1_sec<=0 || $r2_sec<=0 || $r2_sec<$r1_sec || | ||
($r2_sec%$r1_sec)>0) { | ||
echo "Incorrect time or date specification.<br>\n"; | ||
exit(); | ||
} | ||
$time_length_sec=time_to_sec($time_length_number, | ||
$time_length_unit); | ||
$time_length_sec= | ||
((int)($time_length_sec / $r2_sec)) * $r2_sec; | ||
if ($time_length_sec<=0) { | ||
echo "Incorrect time or date specification.<br>\n"; | ||
exit(); | ||
} | ||
/* Compute timestamp of start or end of requested period */ | ||
$timestamp=strtotime($time_year . "-" . $time_month . "-" . | ||
$time_day . " " . $time_hour . ":" . $time_minute); | ||
/* echo "timestamp: $timestamp<br>\n"; */ | ||
$hhmmYYYYMMDD=date("G:i Ymd", $timestamp); | ||
/* echo "hhmmYYYYMMDD: $hhmmYYYYMMDD<br>\n"; */ | ||
/* If start time was given, then compute end time */ | ||
if (!strcmp($time_type, "start_time")) { | ||
$timestamp=$timestamp + $time_length_sec; | ||
/* echo "timestamp + time_length: $timestamp<br>\n"; */ | ||
$hhmmYYYYMMDD=date("G:i Ymd", $timestamp); | ||
/* echo "hhmmYYYYMMDD + time_length: $hhmmYYYYMMDD<br>\n"; */ | ||
} | ||
/* Adjust timestamp to R2 boundary */ | ||
$timestamp=((int)($timestamp / $r2_sec)) * $r2_sec; | ||
$command=$command . " --time=\\\"" . $r1_sec . " " . | ||
$r2_sec . " " . $time_length_number . | ||
$time_length_unit . " " . $hhmmYYYYMMDD . "\\\""; | ||
} | ||
< |