index.php 12 KB
Newer Older
1 2 3
<?php

require_once("common.php");
4

's avatar
committed
5 6 7 8 9 10
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");

11
/*
's avatar
committed
12
 * Define subjects
13 14
 */

's avatar
committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/* 
 * This must be the same as "label" field in [subject] section in
 *	the configuration file.
 */
$subject_label=array(
	"GN2_CESNET", 
	"Brno_PoP", 
	"Budejovice_PoP", 
	"Hradec_PoP", 
	"Liberec_PoP", 
	"Olomouc_PoP", 
	"Ostrava_PoP", 
	"Pardubice_PoP", 
	"Plzen_PoP", 
	"Prague_PoP", 
	"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 );
35 36

/*
's avatar
committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
 * 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.
 */
$subject_description=array(
	"GN2 CESNET2", 
	"Brno PoP", 
	"Budejovice PoP", 
	"Hradec PoP", 
	"Liberec PoP", 
	"Olomouc PoP", 
	"Ostrava PoP", 
	"Pardubice PoP", 
	"Plzen PoP", 
	"Prague PoP", 
	"Usti PoP"
);

/*
 * 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
 * monitoring stations via DiMAPI. Or it can be individual remote monitoring
 * stations if monitoring application runs locally on remote monitoring
 * stations and uses MAPI.
 */
$subject_hostname=array(
	"jra1-2.cesnet.cz", 
	"perfmon2.cesnet.cz", 
	"perfmon-budejovice.cesnet.cz", 
	"perfmon-hradec.cesnet.cz", 
	"perfmon-liberec.cesnet.cz", 
	"perfmon-olomouc.cesnet.cz", 
	"perfmon-ostrava.cesnet.cz", 
	"perfmon-pardubice.cesnet.cz", 
	"perfmon-plzen.cesnet.cz", 
	"perfmon1.cesnet.cz", 
	"perfmon-usti.cesnet.cz"
);

/*
 * Predefined time intervals and granularities
's avatar
committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91
 *
 * Keep in mind the following requirements:
 *
 *   - each resolution must be >= time of one pixel on X axis
 *     (set in rrd_graph_all.sh) otherwise time of one pixel is used
 *
 *   - UNIX timestamps of both start time and end time must be multiples
 *     of both resolutions (set time_length accordingly and compute
 *     end time to be on boundary) and it is safer to skip the most recent
 *     samples, see variable $hhmmYYYYMMDD below
 *
 *   - RRD files must include RRA samples for the whole requested period,
 *     create RRD files to include enough RRA samples for possible browsing
 *     in time axis
's avatar
committed
92 93 94
 */

$time_description[0]="last 10 mins (interval 1 sec, avg/max 30 sec)";
's avatar
committed
95 96
$time_description[1]="last 1 hour (interval 10 sec, avg/max 3 min)";
$time_description[2]="last 10 hours (interval 1 min, avg/max 20 min)";
's avatar
committed
97 98 99 100 101 102 103 104 105
$time_description[3]="last 1 day (interval 3 min, avg/max 1 hour)";
$time_description[4]="last 1 week (interval 20 min, avg/max 6 hour)";
$time_description[5]="last 1 month (interval 3 hour, avg/max 1 day)";
$time_description[6]="last 1 year (interval 1 day, avg/max 1 month)";

$r1[0]=1;
$r2[0]=30;
$time_length[0]="10min";

's avatar
committed
106
$r1[1]=10;
's avatar
committed
107 108 109
$r2[1]=180;
$time_length[1]="1h";

's avatar
committed
110
$r1[2]=60;
's avatar
committed
111
$r2[2]=1200;
's avatar
committed
112
$time_length[2]="10h";
's avatar
committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

$r1[3]=180;
$r2[3]=3600;
$time_length[3]="1day";

$r1[4]=120;
$r2[4]=21600;
$time_length[4]="1week";

$r1[5]=10800;
$r2[5]=86400;
$time_length[5]="1month";

$r1[6]=86400;
$r2[6]=2628000;
$time_length[6]="1year";

/*
 * Define graph types
132 133
 */

's avatar
committed
134 135 136 137 138 139
$graph_type_label=array("l4", "apps");
$graph_type_description=array("L4", "Application");

/* For conversion of month number to month name */
$monthNumberToLongName=array("January", "February", "March", "April", "May", 
	"June", "July", "August", "September", "October", "November", "December");
140 141 142 143

/*
 * Start application
 */
144 145 146 147 148 149 150 151

$func="main()";

openlog($_SERVER['REMOTE_USER'], LOG_PID, LOG_LOCAL0);
syslog(LOG_INFO, "$func: starting");

echo "<html>\n";
echo "<head>\n";
152
echo "<link rel=\"StyleSheet\" type=\"text/css\" href=\"../../style.css\">\n";
153 154
echo "</head>\n";
echo "<body>\n";
155
echo "<h2>ABW - Passive bandwith usage monitoring</h2>\n";
156

's avatar
committed
157
echo "<a href=\"" . NET_IMG . "\"><img src=\"" . NET_IMG . "\" width=\"400\" align=\"right\"></a>\n";
158

159 160
if (!isset($subject_selected))
	$subject_selected=1;
161

162 163 164 165
echo "<form method=post action=\"index.php?action=gen_graph\">\n";

/*
 * Print form to select graph types
166 167
 */

's avatar
committed
168 169
/* if (!isset($graph_types))
	$graph_types[0]="l4"; */
170 171 172

echo "<b>Type of graphs:</b><p>\n";

's avatar
committed
173 174 175
foreach ($graph_type_label as $key => $value) {
	echo "$graph_type_description[$key] protocols ";
	echo "<input type=checkbox name=\"graph_types[]\" value=\"$value\"";
176
	if (isset($graph_types)) {
's avatar
committed
177
		if (in_array($value, $graph_types))
178 179 180 181 182 183 184
			echo " checked";
	}
	echo ">\n";
}

/*
 * Print form to select monitored links
185 186
 */

's avatar
committed
187 188 189 190 191
/* if (!isset($subjects))
	$subjects[0]="Prague_PoP"; */

$half=count($subject_label)/2 + $subject_label%2;
$i=0;
192

193
echo "<p>\n";
194 195
echo "<b>Monitored links:</b><p>\n";
echo "<table border=1>\n";
's avatar
committed
196 197 198 199 200
foreach ($subject_label as $key => $value) {
	if (($i%2)==0)
		echo "<tr>\n";
	echo "<td>$subject_description[$key]</td>";
	echo "<td><input type=checkbox name=\"subjects[]\" value=\"$value\"";
201
	if (isset($subjects)) {
's avatar
committed
202
		if (in_array($value, $subjects))
203 204
			echo " checked";
	}
's avatar
committed
205 206 207 208 209 210
	if ($subject_disabled[$key] > 0)
		echo " disabled";
	echo "></td>\n";
	if (($i%2)>0)
		echo "</tr>\n";
	$i++;
211
}
's avatar
committed
212 213 214 215 216 217 218 219 220 221

if (($i%2)==0)
	echo "<tr>\n";
echo "<td>all subjects</td>\n";
echo "<td><input type=checkbox name=\"subject_all\"";
if ($subject_all)
   echo " checked";
echo "></td>\n";
$i++;

's avatar
committed
222 223
if (($i%2)>0)
	echo "<td>&nbsp;</td><td>&nbsp;</td>";
's avatar
committed
224
echo "</tr></table>\n";
225

226 227 228
/*
 * Print form to select time granularities and periods
 */
229 230

echo "<p>\n";
's avatar
committed
231
echo "<b>Time period and granularity:</b><p>\n";
232

's avatar
committed
233 234 235 236 237 238
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";
foreach ($time_description as $key => $value) {
239
	echo "<tr>\n";
's avatar
committed
240 241 242 243
	echo "<td>$value</td>\n";
	$time_label=$r1[$key] . "_" . $r2[$key] . "_" . $time_length[$key];
   echo "<td><input type=checkbox name=\"times[]\" value=\"" . $time_label . "\"";
	if (isset($times)) {
's avatar
committed
244
		if (in_array($time_label, $times))
's avatar
committed
245 246
   		echo " checked";
	}
247 248
	echo "></td>\n";
	echo "</tr>\n";
249
}
250
echo "<tr>\n";
's avatar
committed
251
echo "<td>all predefined time periods</td>\n";
252 253 254 255
echo "<td><input type=checkbox name=\"time_all\"";
if ($time_all)
	echo " checked";
echo "></td>\n";
256
echo "</tr>\n";
's avatar
committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
echo "</table></td>\n";

echo "<td>&nbsp;</td><td><p>Start or end time:<br>";

echo "<select name=time_day>";
	for ($i=1; $i<=31; $i++)
		echo "<option value=$i>$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";
echo "</select>\n";

echo "<select name=time_year>";
	for ($i=2006; $i<=2015; $i++)
		echo "<option value=$i>$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 "<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";
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 "<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";
echo "</select></td>\n";
echo "<td><input type=text size=3 name=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";
echo "</select></td>\n";
echo "</tr></table>\n";

if (!isset($time_type))
	$time_type="predefined";

echo "<p>Time type:<br>\n";
echo "Predefined <input type=radio name=\"time_type\" value=\"predefined\"";
if (!strcmp($time_type, "predefined"))
	echo " selected";
echo ">";
echo "  Start time <input type=radio name=\"time_type\" value=\"start_time\"";
if (!strcmp($time_type, "start_time"))
   echo " selected";
echo ">";
echo "  End time <input type=radio name=\"time_type\" value=\"end_time\"";
if (!strcmp($time_type, "end_time"))
   echo " selected";
echo ">";

echo "</td>\n";

echo "</tr></table\n";

echo "<p>Note: selecting all time periods will require a lot of processing time\n";
326 327

echo "<p>\n";
's avatar
committed
328 329 330
echo "<input type=submit name=button_name value=\"Generate graphs\">\n";

echo "</form><br>\n";
331

332 333
if ($action=="gen_graph") {

's avatar
committed
334 335
	$current_time=date("G:i:s Ymd", time());
	echo "current_time: $current_time<br>\n";
's avatar
committed
336 337

	foreach (glob(GRAPH_DIR . "/*") as $filename)
338 339
      unlink($filename);

's avatar
committed
340 341 342
	/* If at least one graph type, one subject and one time period were
		selected, then generate and show graphs */

's avatar
committed
343 344 345
	if (isset($graph_types) && 
		 (isset($subjects) || $subject_all) && 
		 (isset($times) || $time_all)) {
's avatar
committed
346 347

		/* Go over all selected graph types */
348

's avatar
committed
349
		foreach($graph_types as $graph_type) {
350

's avatar
committed
351 352
			/* Go over all subjects and for each selected subject issue
				one remote command to generate graphs */
353

's avatar
committed
354 355
			$i=0;
			foreach ($subject_label as $subject_key => $subject_value) {
's avatar
committed
356 357 358
		      if (($subject_all || in_array($subject_value, $subjects)) &&
					 !$subject_disabled[$subject_key]) {

's avatar
committed
359 360 361 362 363 364 365 366 367 368 369 370
					$hostname=$subject_hostname[$i];

					$command="ssh " . REMOTE_USERNAME . "@" . $subject_hostname[$i] .
						" \"" . GRAPH_SCRIPT . " -r --protocols=" . $graph_type .
						" --label=" . $subject_value . " --parameters_id=1";

					/* Append one --time argument for each selected time period */

					foreach ($time_description as $time_key => $time_value) {
						$time_label=$r1[$time_key] . "_" . $r2[$time_key] . "_" . 
							$time_length[$time_key];
					   if ($time_all || in_array($time_label, $times)) {
's avatar
committed
371 372 373
							$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";

's avatar
committed
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
							 $command=$command . "  --time=\\\"" .
							 	$r1[$time_key] . " " . $r2[$time_key] . " " .
								$time_length[$time_key] . " " . $hhmmYYYYMMDD . "\\\"";
						}
					}
					$command=$command . " 2>&1 > /dev/null\"";
					echo "Command: $command<br>\n";
					system($command);

					$command="scp " . REMOTE_USERNAME . "@" . $subject_hostname[$i] .
						":" . REMOTE_GRAPH_DIR . "/* " . GRAPH_DIR;	
					echo "Command: $command<br>\n";
					system($command);
				}
			$i++;
			}
		} /* foreach($graph_types as $graph_type) */

		echo "<p>\n<table>\n";
		$graphs=0;

		foreach($graph_types as $graph_type) {
			foreach ($subject_label as $subject_key => $subject_value) {
's avatar
committed
397 398
		      if (($subject_all || in_array($subject_value, $subjects)) &&
					 !$subject_disabled[$subject_key]) {
's avatar
committed
399 400 401 402 403 404 405 406 407 408 409 410
					foreach ($time_description as $time_key => $time_value) {
						$time_label=$r1[$time_key] . "_" . $r2[$time_key] . "_" . 
							$time_length[$time_key];
					   if ($time_all || in_array($time_label, $times)) {

							$graph_filename="graph/graph_" . $subject_value . "_" . 
								$graph_type . "_" . $r1[$time_key] . "s_" .
								$r2[$time_key] . "s_" . $time_length[$time_key] . 
								".png";

							if (($graphs%2)==0)
								echo "<tr>\n";
411
	
's avatar
committed
412 413 414 415 416 417 418 419 420 421 422 423 424
							echo "<td width=430 align=center>\n";
							echo "  <table>\n";
							echo "  <tr>\n";
							echo "    <td align=center><a href=\"$graph_filename\"><img width=400 src=\"$graph_filename\"></a></td>\n";
							echo "  </tr>\n";
							echo "  <tr>\n";
							echo "    <td align=center>" . $graph_type_description[array_search($graph_type, $graph_type_label)] . " protocols, Monitored link: " . $subject_description[$subject_key] . "<br>$time_description[$time_key]</td>\n";
							echo "  </tr>\n";
							echo "  </table>\n";
							echo "</td>\n";

							if (($graphs%2)!=0)
								echo "</tr>\n";
425
			
's avatar
committed
426 427 428
							$graphs++;
						}
					} 
429
				}
's avatar
committed
430 431 432 433 434
			} /* foreach($subject_label as $subject_key => $subject_value) */
		} /* foreach ($graph_types as $graph_type) */

		echo "</table>\n";

's avatar
committed
435
	} /* if (isset($graph_types) && ... */
436 437

} /* if ($action=="gen_graph") */
438 439 440 441 442

echo "</body>\n";
echo "</html>\n";

?>