Commit 96260bac authored by 's avatar

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");
*/
set_vars();
$current_ts=time();
/*
* Default values
*/
......@@ -80,30 +82,28 @@ if (!isset($default)) {
$times[0]=$r1[0] . "_" . $r2[0] . "_" . $time_length[0];
/* $times[1]=$r1[1] . "_" . $r2[1] . "_" . $time_length[1];
$times[2]=$r1[2] . "_" . $r2[2] . "_" . $time_length[2]; */
}
$current_time=date("G:i:s Ymd", time());
if (!isset($time_type))
$time_type="predefined";
if (!isset($time_minute))
$time_minute=date("i", time());
if (!isset($time_hour))
$time_hour=date("G", time());
$start_time_minute=date("i", $current_ts-600);
$start_time_hour=date("H", $current_ts-600);
$start_time_day=date("j", $current_ts-600);
$start_time_month=date("n", $current_ts-600);
$start_time_year=date("Y", $current_ts-600);
if (!isset($time_day))
$time_day=date("d", time());
$end_time_minute=date("i", $current_ts);
$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))
$time_month=date("m", time());
$r1_number=1;
$r1_unit="seconds";
$r2_number="30";
$r2_unit="seconds";
if (!isset($time_year))
$time_year=date("Y", time());
if (!isset($maxline))
$maxline="a";
}
/*
* For conversion of month number to month name
......@@ -114,19 +114,19 @@ $monthNumberToLongName=array("January", "February", "March", "April", "May",
function time_to_sec($number, $unit) {
switch ($unit) {
case "Seconds":
case "seconds":
return $number;
case "Minutes":
case "minutes":
return $number * 60;
case "Hours":
case "hours":
return $number * 3600;
case "Days":
case "days":
return $number * 86400;
case "Weeks":
case "weeks":
return $number * 86400 * 7;
case "Months":
case "months":
return $number * 2628000; /* for non-leap years */
case "Years":
case "years":
return $number * 86400 * 365; /* for non-leap years */
default:
return -1;
......@@ -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"; */
/*
* Print form to select time granularities and periods
* Print form to select time period and resolution
*/
echo "<p>\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>Time type:<br>\n";
echo "Time type:<br>\n";
echo "<table><tr><td>Predefined <input type=radio name=\"time_type\" value=\"predefined\"";
if (!strcmp($time_type, "predefined"))
echo " checked";
echo "></td><td width=20>&nbsp;</td>";
echo "<td>User defined start time <input type=radio name=\"time_type\" value=\"start_time\"";
if (!strcmp($time_type, "start_time"))
echo "<td>User defined <input type=radio name=\"time_type\" value=\"user_defined\"";
if (!strcmp($time_type, "user_defined"))
echo " checked";
echo "></td><td width=20>&nbsp;</td>";
echo "<td>User defined end time <input type=radio name=\"time_type\" value=\"end_time\"";
if (!strcmp($time_type, "end_time"))
echo " checked";
echo "></td></tr></table>";
echo "<table>\n";
echo "</tr></table>";
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><table border=1>\n";
......@@ -287,14 +285,16 @@ if (isset($time_all))
echo " checked";
echo "></td>\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++) {
echo "<option value=$i";
if ($time_hour==$i)
if ($start_time_hour==$i)
echo " selected";
echo ">";
printf("%02d", $i);
......@@ -302,69 +302,102 @@ echo "<select name=time_hour>";
}
echo "</select>\n";
echo "<select name=time_minute>";
echo "<select name=start_time_minute>";
for ($i=0; $i<=59; $i++) {
echo "<option value=$i";
if ($time_minute==$i)
if ($start_time_minute==$i)
echo " selected";
echo ">";
printf("%02d", $i);
echo "</option>\n";
}
echo "</select>\n";
echo "</select></td><td width=\"20px\">&nbsp;</td>\n";
echo "<p>Start or end date:<br>\n";
echo "<select name=time_day>";
echo "<td><select name=start_time_day>";
for ($i=1; $i<=31; $i++) {
echo "<option value=$i";
if ($time_day==$i)
if ($start_time_day==$i)
echo " selected";
echo ">$i</option>\n";
}
echo "</select>\n";
echo "<select name=time_month>";
echo "<select name=start_time_month>";
for ($i=1; $i<=12; $i++) {
echo "<option value=$i";
if ($time_month==$i)
if ($start_time_month==$i)
echo " selected";
echo ">" . $monthNumberToLongName[$i-1] . "</option>\n";
}
echo "</select>\n";
echo "<select name=time_year>";
echo "<select name=start_time_year>";
for ($i=2006; $i<=2015; $i++) {
echo "<option value=$i";
if ($time_year==$i)
if ($start_time_year==$i)
echo " selected";
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 "<p>Time length:<br>\n";
if (isset($time_length_number))
$time_length_number_preset=$time_length_number;
else
$time_length_number_preset="";
echo "<input type=text size=3 name=time_length_number value=\"$time_length_number_preset\"></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";
if ($time_length_unit==$value)
echo "<select name=end_time_minute>";
for ($i=0; $i<=59; $i++) {
echo "<option value=$i";
if ($end_time_minute==$i)
echo " selected";
echo ">$value</option>\n";
}
echo ">";
printf("%02d", $i);
echo "</option>\n";
}
echo "</select></td><td width=\"20px\">&nbsp;</td>\n";
echo "<td><select name=end_time_day>";
for ($i=1; $i<=31; $i++) {
echo "<option value=$i";
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 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 */
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 "<select name=r1_unit>";
$r1_units=array("Seconds", "Minutes", "Hours", "Days", "Weeks", "Months",
"Years");
$r1_units=array("seconds", "minutes", "hours", "days", "weeks", "months",
"years");
foreach ($r1_units as $value) {
echo "<option value=$value";
if ($r1_unit==$value)
......@@ -374,8 +407,8 @@ foreach ($r1_units as $value) {
echo "</select></td>\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");
$r2_units=array("seconds", "minutes", "hours", "days", "weeks", "months",
"years");
foreach ($r2_units as $value) {
echo "<option value=$value";
if ($r2_unit==$value)
......@@ -388,11 +421,11 @@ echo "</tr></table>\n";
echo "</td>\n";
echo "</tr></table\n";
echo "</tr></table>\n";
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\"";
if (!strcmp($maxline, "y"))
echo " checked";
......@@ -479,64 +512,55 @@ if ($action=="gen_graph") {
}
} /* 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) {
echo "Incorrect time or date specification (resolution and avg/max must be greater than zero).<br>\n";
exit();
if ($r1_sec<=0) {
$r1_sec=1; $r1_number=1; $r1_unit="seconds";
echo "<span class=\"warning\">Warning: resolution must be greater than zero (resolution was adjusted to 1 second).</span><br>\n";
}
if ($r2_sec<$r1_sec) {
echo "Incorrect time or date specification (avg/max must be greater than equal to resolution).<br>\n";
exit();
if ($r2_sec<=0) {
$r2_sec=30; $r2_number=30; $r2_unit="seconds";
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,
$time_length_unit);
/* Rounding was removed */
// $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();
if ($r2_sec<$r1_sec) {
$r2_sec=$r1_sec; $r2_number=$r1_number; $r2_unit=$r1_unit;
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";
}
/* Compute timestamp of start or end of requested period */
$timestamp=strtotime($time_year . "-" . $time_month . "-" .
$time_day . " " . $time_hour . ":" . $time_minute);
/* Compute timestamps of start and end of requested period */
/* Adjust timestamp to R2 boundary */
/* Rounding was removed */
// $timestamp=((int)($timestamp / $r2_sec)) * $r2_sec;
/* echo "timestamp: $timestamp<br>\n"; */
$start_timestamp=mktime($start_time_hour, $start_time_minute, 0, $start_time_month, $start_time_day, $start_time_year);
/* If start time was given, then compute end time */
$end_timestamp=mktime($end_time_hour, $end_time_minute, 0, $end_time_month, $end_time_day, $end_time_year);
if (!strcmp($time_type, "start_time")) {
$timestamp=$timestamp + $time_length_sec;
/* echo "timestamp + time_length: $timestamp<br>\n"; */
if ($end_timestamp > $current_ts) {
$end_timestamp=$current_ts;
$end_timestamp=(int)($end_timestamp / 60);
$end_timestamp=$end_timestamp * 60;
$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 ($timestamp>time()) {
echo "Incorrect time or date specification (end time must not be in the future).<br>\n";
exit();
if ($end_timestamp <= $start_timestamp) {
$start_timestamp=$end_timestamp-600;
$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";
}
$hhmmYYYYMMDD=date("G:i Ymd", $timestamp);
/* echo "hhmmYYYYMMDD + time_length: $hhmmYYYYMMDD<br>\n"; */
$time_length_number=$end_timestamp - $start_timestamp;
/* 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 . " " .
$r2_sec . " " . $time_length_number .
......@@ -553,9 +577,6 @@ if ($action=="gen_graph") {
$time2=gettimeofday();
$diff=time_diff($time1, $time2);
$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;
syslog(LOG_DEBUG, "Command: $command");
......@@ -564,7 +585,6 @@ if ($action=="gen_graph") {
$time2=gettimeofday(TRUE);
$diff=time_diff($time1, $time2);
$total_time+=$diff;
/* printf("%.02fs</td></tr>\n", $diff); */
}
$i++;
}
......@@ -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 " </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";
if (!strcmp($time_type, "start_time"))
echo " from";
else
echo " to";
printf(" %02d:%02d %d-%02d-%02d", $time_hour, $time_minute,
$time_year, $time_month, $time_day);
echo "<br>(interval $r1_number $r1_unit, Avg/Max $r2_number $r2_unit)</td>\n";
echo " <td align=center width=450>" . $graph_type_description[array_search($graph_type, $graph_type_label)] . ", Monitored link: " . $subject_description[$subject_key] . "<br>\n";
printf("From %d:%02d %d.%02d.%d to %d:%02d %d.%02d.%d<br>\n",
$start_time_hour, $start_time_minute, $start_time_day,
$start_time_month, $start_time_year, $end_time_hour,
$end_time_minute, $end_time_day, $end_time_month,
$end_time_year);
echo "(interval $r1_number $r1_unit, Avg/Max $r2_number $r2_unit)</td>\n";
echo " </tr>\n";
echo " </table>\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