Commit 96260bac authored by 's avatar
Browse files

User-defined time can be now specified as start to end (rather than

duration).


git-svn-id: file:///home/svn/mapi/trunk@1461 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent b1cd4ffe
...@@ -69,6 +69,8 @@ $graph_type_description=array("L3/L4 protocols", "Application protocols"); ...@@ -69,6 +69,8 @@ $graph_type_description=array("L3/L4 protocols", "Application protocols");
*/ */
set_vars(); set_vars();
$current_ts=time();
/* /*
* Default values * Default values
*/ */
...@@ -80,30 +82,28 @@ if (!isset($default)) { ...@@ -80,30 +82,28 @@ if (!isset($default)) {
$times[0]=$r1[0] . "_" . $r2[0] . "_" . $time_length[0]; $times[0]=$r1[0] . "_" . $r2[0] . "_" . $time_length[0];
/* $times[1]=$r1[1] . "_" . $r2[1] . "_" . $time_length[1]; /* $times[1]=$r1[1] . "_" . $r2[1] . "_" . $time_length[1];
$times[2]=$r1[2] . "_" . $r2[2] . "_" . $time_length[2]; */ $times[2]=$r1[2] . "_" . $r2[2] . "_" . $time_length[2]; */
}
$current_time=date("G:i:s Ymd", time());
if (!isset($time_type))
$time_type="predefined"; $time_type="predefined";
if (!isset($time_minute)) $start_time_minute=date("i", $current_ts-600);
$time_minute=date("i", time()); $start_time_hour=date("H", $current_ts-600);
$start_time_day=date("j", $current_ts-600);
if (!isset($time_hour)) $start_time_month=date("n", $current_ts-600);
$time_hour=date("G", time()); $start_time_year=date("Y", $current_ts-600);
if (!isset($time_day)) $end_time_minute=date("i", $current_ts);
$time_day=date("d", time()); $end_time_hour=date("H", $current_ts);
$end_time_day=date("j", $current_ts);
$end_time_month=date("n", $current_ts);
$end_time_year=date("Y", $current_ts);
if (!isset($time_month)) $r1_number=1;
$time_month=date("m", time()); $r1_unit="seconds";
$r2_number="30";
$r2_unit="seconds";
if (!isset($time_year))
$time_year=date("Y", time());
if (!isset($maxline))
$maxline="a"; $maxline="a";
}
/* /*
* For conversion of month number to month name * For conversion of month number to month name
...@@ -114,19 +114,19 @@ $monthNumberToLongName=array("January", "February", "March", "April", "May", ...@@ -114,19 +114,19 @@ $monthNumberToLongName=array("January", "February", "March", "April", "May",
function time_to_sec($number, $unit) { function time_to_sec($number, $unit) {
switch ($unit) { switch ($unit) {
case "Seconds": case "seconds":
return $number; return $number;
case "Minutes": case "minutes":
return $number * 60; return $number * 60;
case "Hours": case "hours":
return $number * 3600; return $number * 3600;
case "Days": case "days":
return $number * 86400; return $number * 86400;
case "Weeks": case "weeks":
return $number * 86400 * 7; return $number * 86400 * 7;
case "Months": case "months":
return $number * 2628000; /* for non-leap years */ return $number * 2628000; /* for non-leap years */
case "Years": case "years":
return $number * 86400 * 365; /* for non-leap years */ return $number * 86400 * 365; /* for non-leap years */
default: default:
return -1; return -1;
...@@ -241,30 +241,28 @@ echo "</table>\n"; ...@@ -241,30 +241,28 @@ echo "</table>\n";
/* echo "<p><i>Note: PIONIER monitoring stations are down due to moving to a different subnet.</i>\n"; */ /* echo "<p><i>Note: PIONIER monitoring stations are down due to moving to a different subnet.</i>\n"; */
/* /*
* Print form to select time granularities and periods * Print form to select time period and resolution
*/ */
echo "<p>\n"; echo "<p>\n";
echo "<h3>Step 3: Select time period and resolution:</h3>\n"; echo "<h3>Step 3: Select time period and resolution:</h3>\n";
echo "(<a href=\"aggregation.html\">how is data aggregated</a>)\n"; echo "(<a href=\"aggregation.html\">How is data aggregated?</a>)\n";
echo "<p>\n"; echo "<p>\n";
echo "<p>Time type:<br>\n"; echo "Time type:<br>\n";
echo "<table><tr><td>Predefined <input type=radio name=\"time_type\" value=\"predefined\""; echo "<table><tr><td>Predefined <input type=radio name=\"time_type\" value=\"predefined\"";
if (!strcmp($time_type, "predefined")) if (!strcmp($time_type, "predefined"))
echo " checked"; echo " checked";
echo "></td><td width=20>&nbsp;</td>"; echo "></td><td width=20>&nbsp;</td>";
echo "<td>User defined start time <input type=radio name=\"time_type\" value=\"start_time\""; echo "<td>User defined <input type=radio name=\"time_type\" value=\"user_defined\"";
if (!strcmp($time_type, "start_time")) if (!strcmp($time_type, "user_defined"))
echo " checked"; echo " checked";
echo "></td><td width=20>&nbsp;</td>"; echo "></td><td width=20>&nbsp;</td>";
echo "<td>User defined end time <input type=radio name=\"time_type\" value=\"end_time\""; echo "</tr></table>";
if (!strcmp($time_type, "end_time"))
echo " checked";
echo "></td></tr></table>";
echo "<table>\n";
echo "<p>\n"; echo "<p>\n";
echo "<table>\n";
echo "<tr><td>Predefined:</td><td width=20>&nbsp;</td><td>User defined:</td></tr>\n"; echo "<tr><td>Predefined:</td><td width=20>&nbsp;</td><td>User defined:</td></tr>\n";
echo "<tr><td><table border=1>\n"; echo "<tr><td><table border=1>\n";
...@@ -287,14 +285,16 @@ if (isset($time_all)) ...@@ -287,14 +285,16 @@ if (isset($time_all))
echo " checked"; echo " checked";
echo "></td>\n"; echo "></td>\n";
echo "</tr>\n"; echo "</tr>\n";
echo "</table></td>\n"; echo "</table>\n";
echo "</td><td>&nbsp;</td><td>\n";
echo "<td>&nbsp;</td><td><p>Start or end time:<br>"; echo "<table><tr><td>Start time:</td><td width=\"20px\">&nbsp;</td><td>Start date:</td></tr>\n";
echo "<select name=time_hour>"; echo "<tr><td><select name=start_time_hour>";
for ($i=0; $i<=23; $i++) { for ($i=0; $i<=23; $i++) {
echo "<option value=$i"; echo "<option value=$i";
if ($time_hour==$i) if ($start_time_hour==$i)
echo " selected"; echo " selected";
echo ">"; echo ">";
printf("%02d", $i); printf("%02d", $i);
...@@ -302,69 +302,102 @@ echo "<select name=time_hour>"; ...@@ -302,69 +302,102 @@ echo "<select name=time_hour>";
} }
echo "</select>\n"; echo "</select>\n";
echo "<select name=time_minute>"; echo "<select name=start_time_minute>";
for ($i=0; $i<=59; $i++) { for ($i=0; $i<=59; $i++) {
echo "<option value=$i"; echo "<option value=$i";
if ($time_minute==$i) if ($start_time_minute==$i)
echo " selected"; echo " selected";
echo ">"; echo ">";
printf("%02d", $i); printf("%02d", $i);
echo "</option>\n"; echo "</option>\n";
} }
echo "</select>\n"; echo "</select></td><td width=\"20px\">&nbsp;</td>\n";
echo "<p>Start or end date:<br>\n"; echo "<td><select name=start_time_day>";
echo "<select name=time_day>";
for ($i=1; $i<=31; $i++) { for ($i=1; $i<=31; $i++) {
echo "<option value=$i"; echo "<option value=$i";
if ($time_day==$i) if ($start_time_day==$i)
echo " selected"; echo " selected";
echo ">$i</option>\n"; echo ">$i</option>\n";
} }
echo "</select>\n"; echo "</select>\n";
echo "<select name=time_month>"; echo "<select name=start_time_month>";
for ($i=1; $i<=12; $i++) { for ($i=1; $i<=12; $i++) {
echo "<option value=$i"; echo "<option value=$i";
if ($time_month==$i) if ($start_time_month==$i)
echo " selected"; echo " selected";
echo ">" . $monthNumberToLongName[$i-1] . "</option>\n"; echo ">" . $monthNumberToLongName[$i-1] . "</option>\n";
} }
echo "</select>\n"; echo "</select>\n";
echo "<select name=time_year>"; echo "<select name=start_time_year>";
for ($i=2006; $i<=2015; $i++) { for ($i=2006; $i<=2015; $i++) {
echo "<option value=$i"; echo "<option value=$i";
if ($time_year==$i) if ($start_time_year==$i)
echo " selected"; echo " selected";
echo ">$i</option>\n"; echo ">$i</option>\n";
} }
echo "</select></td></tr></table>\n";
echo "<table><tr><td>End time:</td><td width=\"20px\">&nbsp;</td><td>End date:</td></tr>\n";
echo "<tr><td><select name=end_time_hour>";
for ($i=0; $i<=23; $i++) {
echo "<option value=$i";
if ($end_time_hour==$i)
echo " selected";
echo ">";
printf("%02d", $i);
echo "</option>\n";
}
echo "</select>\n"; echo "</select>\n";
echo "<p>Time length:<br>\n"; echo "<select name=end_time_minute>";
if (isset($time_length_number)) for ($i=0; $i<=59; $i++) {
$time_length_number_preset=$time_length_number; echo "<option value=$i";
else if ($end_time_minute==$i)
$time_length_number_preset=""; echo " selected";
echo "<input type=text size=3 name=time_length_number value=\"$time_length_number_preset\"></input>\n"; echo ">";
printf("%02d", $i);
echo "<select name=time_length_unit>"; echo "</option>\n";
$time_length_units=array("Minutes", "Hours", "Days", "Weeks", "Months", }
"Years"); echo "</select></td><td width=\"20px\">&nbsp;</td>\n";
foreach ($time_length_units as $value) {
echo "<option value=$value"; echo "<td><select name=end_time_day>";
if ($time_length_unit==$value) for ($i=1; $i<=31; $i++) {
echo " selected"; echo "<option value=$i";
echo ">$value</option>\n"; if ($end_time_day==$i)
} echo " selected";
echo ">$i</option>\n";
}
echo "</select>\n";
echo "<select name=end_time_month>";
for ($i=1; $i<=12; $i++) {
echo "<option value=$i";
if ($end_time_month==$i)
echo " selected";
echo ">" . $monthNumberToLongName[$i-1] . "</option>\n";
}
echo "</select>\n"; echo "</select>\n";
echo "<select name=end_time_year>";
for ($i=2006; $i<=2015; $i++) {
echo "<option value=$i";
if ($end_time_year==$i)
echo " selected";
echo ">$i</option>\n";
}
echo "</select></td></tr></table>\n";
/* Interval + avg/max are as a separate table */ /* Interval + avg/max are as a separate table */
echo "<p><table><tr><td>Resolution:</td><td>Avg/Max:</td></tr><tr>\n"; echo "<p><table><tr><td>Resolution:</td><td>Avg/Max:</td></tr><tr>\n";
echo "<td><input type=text size=3 name=r1_number value=\"$r1_number\"></input>\n"; echo "<td><input type=text size=3 name=r1_number value=\"$r1_number\"></input>\n";
echo "<select name=r1_unit>"; echo "<select name=r1_unit>";
$r1_units=array("Seconds", "Minutes", "Hours", "Days", "Weeks", "Months", $r1_units=array("seconds", "minutes", "hours", "days", "weeks", "months",
"Years"); "years");
foreach ($r1_units as $value) { foreach ($r1_units as $value) {
echo "<option value=$value"; echo "<option value=$value";
if ($r1_unit==$value) if ($r1_unit==$value)
...@@ -374,8 +407,8 @@ foreach ($r1_units as $value) { ...@@ -374,8 +407,8 @@ foreach ($r1_units as $value) {
echo "</select></td>\n"; echo "</select></td>\n";
echo "<td><input type=text size=3 name=r2_number value=\"$r2_number\"></input>\n"; echo "<td><input type=text size=3 name=r2_number value=\"$r2_number\"></input>\n";
echo "<select name=r2_unit>"; echo "<select name=r2_unit>";
$r2_units=array("Seconds", "Minutes", "Hours", "Days", "Weeks", "Months", $r2_units=array("seconds", "minutes", "hours", "days", "weeks", "months",
"Years"); "years");
foreach ($r2_units as $value) { foreach ($r2_units as $value) {
echo "<option value=$value"; echo "<option value=$value";
if ($r2_unit==$value) if ($r2_unit==$value)
...@@ -388,11 +421,11 @@ echo "</tr></table>\n"; ...@@ -388,11 +421,11 @@ echo "</tr></table>\n";
echo "</td>\n"; echo "</td>\n";
echo "</tr></table\n"; echo "</tr></table>\n";
echo "<p><h3>Step 4: Choose options:</h3>"; echo "<p><h3>Step 4: Choose options:</h3>";
echo "<p>Draw maximum line: (<a href=\"max_line.html\">what does it mean?</a>)<br>\n"; echo "<p>Draw maximum line: (<a href=\"max_line.html\">What does it mean?</a>)<br>\n";
echo "<table><tr><td>Yes <input type=radio name=\"maxline\" value=\"y\""; echo "<table><tr><td>Yes <input type=radio name=\"maxline\" value=\"y\"";
if (!strcmp($maxline, "y")) if (!strcmp($maxline, "y"))
echo " checked"; echo " checked";
...@@ -479,64 +512,55 @@ if ($action=="gen_graph") { ...@@ -479,64 +512,55 @@ if ($action=="gen_graph") {
} }
} /* if (!strcmp($time_type, "predefined")) */ } /* if (!strcmp($time_type, "predefined")) */
else { 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); $r1_sec=time_to_sec($r1_number, $r1_unit);
$r2_sec=time_to_sec($r2_number, $r2_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) {
if ($r1_sec<=0 || $r2_sec<=0) { $r1_sec=1; $r1_number=1; $r1_unit="seconds";
echo "Incorrect time or date specification (resolution and avg/max must be greater than zero).<br>\n"; echo "<span class=\"warning\">Warning: resolution must be greater than zero (resolution was adjusted to 1 second).</span><br>\n";
exit();
} }
if ($r2_sec<$r1_sec) { if ($r2_sec<=0) {
echo "Incorrect time or date specification (avg/max must be greater than equal to resolution).<br>\n"; $r2_sec=30; $r2_number=30; $r2_unit="seconds";
exit(); echo "<span class=\"warning\">Warning: avg/max must be greater than zero (avg/max was adjusted to 30 seconds).</span><br>\n";
} }
$time_length_sec=time_to_sec($time_length_number, if ($r2_sec<$r1_sec) {
$time_length_unit); $r2_sec=$r1_sec; $r2_number=$r1_number; $r2_unit=$r1_unit;
/* Rounding was removed */ echo "<span class=\"warning\">Warning: avg/max must be greater than or equal to resolution (avg/max was adjusted to equal resolution).</span><br>\n";
// $time_length_sec=
// ((int)($time_length_sec / $r2_sec)) * $r2_sec;
if ($time_length_sec<=0) {
echo "Incorrect time or date specification (time length must be greater than zero).<br>\n";
exit();
} }
/* Compute timestamp of start or end of requested period */ /* Compute timestamps of start and end of requested period */
$timestamp=strtotime($time_year . "-" . $time_month . "-" . $start_timestamp=mktime($start_time_hour, $start_time_minute, 0, $start_time_month, $start_time_day, $start_time_year);
$time_day . " " . $time_hour . ":" . $time_minute);
/* Adjust timestamp to R2 boundary */ $end_timestamp=mktime($end_time_hour, $end_time_minute, 0, $end_time_month, $end_time_day, $end_time_year);
/* Rounding was removed */ if ($end_timestamp > $current_ts) {
// $timestamp=((int)($timestamp / $r2_sec)) * $r2_sec; $end_timestamp=$current_ts;
/* echo "timestamp: $timestamp<br>\n"; */ $end_timestamp=(int)($end_timestamp / 60);
$end_timestamp=$end_timestamp * 60;
/* If start time was given, then compute end time */ $end_time_minute=date("i", $end_timestamp);
$end_time_hour=date("H", $end_timestamp);
$end_time_day=date("j", $end_timestamp);
$end_time_month=date("n", $end_timestamp);
$end_time_year=date("Y", $end_timestamp);
echo "<span class=\"warning\">Warning: end time must not be in future (end time was adjusted to current time).</span><br>\n";
}
if (!strcmp($time_type, "start_time")) { if ($end_timestamp <= $start_timestamp) {
$timestamp=$timestamp + $time_length_sec; $start_timestamp=$end_timestamp-600;
/* echo "timestamp + time_length: $timestamp<br>\n"; */ $start_time_minute=date("i", $start_timestamp);
$start_time_hour=date("H", $start_timestamp);
$start_time_day=date("j", $start_timestamp);
$start_time_month=date("n", $start_timestamp);
$start_time_year=date("Y", $start_timestamp);
echo "<span class=\"warning\">Warning: end time must be later than start time (start time was adjusted to end time - 10 minutes).</span><br>\n";
} }
if ($timestamp>time()) {
echo "Incorrect time or date specification (end time must not be in the future).<br>\n";
exit();
}
$hhmmYYYYMMDD=date("G:i Ymd", $timestamp); $time_length_number=$end_timestamp - $start_timestamp;
/* echo "hhmmYYYYMMDD + time_length: $hhmmYYYYMMDD<br>\n"; */ /* echo "time_length_number: $time_length_number ($end_timestamp - $start_timestamp)<br>\n"; */
$time_length_unit="seconds";
$hhmmYYYYMMDD=date("G:i Ymd", $end_timestamp);
$command=$command . " --time=\\\"" . $r1_sec . " " . $command=$command . " --time=\\\"" . $r1_sec . " " .
$r2_sec . " " . $time_length_number . $r2_sec . " " . $time_length_number .
...@@ -553,9 +577,6 @@ if ($action=="gen_graph") { ...@@ -553,9 +577,6 @@ if ($action=="gen_graph") {
$time2=gettimeofday(); $time2=gettimeofday();
$diff=time_diff($time1, $time2); $diff=time_diff($time1, $time2);
$total_time+=$diff; $total_time+=$diff;
/* printf("<tr><td>%s</td><td>%s</td><td>%.02fs / ",
$graph_type_description[$graph_type_key], $subject_value,
$diff); */
$command="scp " . $REMOTE_USERNAME . "@" . $subject_hostname[$i] . ":" . $REMOTE_GRAPH_DIR . "/" . $session . "/* " . $GRAPH_DIR . "/" . $session; $command="scp " . $REMOTE_USERNAME . "@" . $subject_hostname[$i] . ":" . $REMOTE_GRAPH_DIR . "/" . $session . "/* " . $GRAPH_DIR . "/" . $session;
syslog(LOG_DEBUG, "Command: $command"); syslog(LOG_DEBUG, "Command: $command");
...@@ -564,7 +585,6 @@ if ($action=="gen_graph") { ...@@ -564,7 +585,6 @@ if ($action=="gen_graph") {
$time2=gettimeofday(TRUE); $time2=gettimeofday(TRUE);
$diff=time_diff($time1, $time2); $diff=time_diff($time1, $time2);
$total_time+=$diff; $total_time+=$diff;
/* printf("%.02fs</td></tr>\n", $diff); */
} }
$i++; $i++;
} }
...@@ -632,14 +652,13 @@ if ($action=="gen_graph") { ...@@ -632,14 +652,13 @@ if ($action=="gen_graph") {
echo " <td align=center width=450><a href=\"$graph_filename\"><img width=400 src=\"$graph_filename\"></a></td>\n"; echo " <td align=center width=450><a href=\"$graph_filename\"><img width=400 src=\"$graph_filename\"></a></td>\n";
echo " </tr>\n"; echo " </tr>\n";
echo " <tr>\n"; echo " <tr>\n";
echo " <td align=center width=450>" . $graph_type_description[array_search($graph_type, $graph_type_label)] . ", Monitored link: " . $subject_description[$subject_key] . "<br>$time_length_number $time_length_unit"; echo " <td align=center width=450>" . $graph_type_description[array_search($graph_type, $graph_type_label)] . ", Monitored link: " . $subject_description[$subject_key] . "<br>\n";
if (!strcmp($time_type, "start_time")) printf("From %d:%02d %d.%02d.%d to %d:%02d %d.%02d.%d<br>\n",
echo " from"; $start_time_hour, $start_time_minute, $start_time_day,
else $start_time_month, $start_time_year, $end_time_hour,
echo " to"; $end_time_minute, $end_time_day, $end_time_month,
printf(" %02d:%02d %d-%02d-%02d", $time_hour, $time_minute, $end_time_year);
$time_year, $time_month, $time_day); echo "(interval $r1_number $r1_unit, Avg/Max $r2_number $r2_unit)</td>\n";
echo "<br>(interval $r1_number $r1_unit, Avg/Max $r2_number $r2_unit)</td>\n";
echo " </tr>\n"; echo " </tr>\n";
echo " </table>\n"; echo " </table>\n";
echo "</td>\n"; echo "</td>\n";
......
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