File: location_statistics.php

package info (click to toggle)
bandwidthd 2.0.1%2Bcvs20090917-4.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,064 kB
  • ctags: 560
  • sloc: sh: 13,357; ansic: 2,743; php: 1,235; yacc: 216; makefile: 160; lex: 36; sql: 27
file content (96 lines) | stat: -rwxr-xr-x 3,201 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<HEAD>
<TITLE>Location Statistics</TITLE>
</HEAD>
<?
include("include.php");
include("header.php");
?></CENTER>
<HEAD>
<link href="bandwidthd.css" rel="stylesheet" type="text/css">
</head>
<center><img src=legend.gif></center>
<?
$db = ConnectDb();

$location_id = $HTTP_GET_VARS['location_id'];
$locations = pg_query("SELECT * from locations where id = $location_id");
if (!$locations)
    echo "<TR><TD>No matching locations in database...</center>";

$r = @pg_fetch_array($locations);

$sensors = pg_query("select distinct sensor_name from sensors where location = ".$r['id']." order by sensor_name;");

while ($sensor = @pg_fetch_array($sensors))
	{
	echo("<H3>".$sensor['sensor_name']."</H3>");
	$interfaces = pg_query("select * from sensors where sensor_name = '".$sensor['sensor_name']."' order by interface;");
	$First = true;
	while ($interface = @pg_fetch_array($interfaces))
		{
		$extension_log = pg_query("select * from extension_log where sensor_id = ".$interface['sensor_id']." order by timestamp desc limit 1;");
		$extension = @pg_fetch_array($extension_log);
		if ($First)
			{
			$First = false;
			echo("<TABLE width=100%><TR>");	
			if ($extension['version'] != "")
				echo("<TD>Version: ".$extension['version']);
			if ($extension['uptime'] != "")
				{
				$uptime_seconds = $extension['uptime'];
				$uptime_text = "";
				if ($uptime_seconds > 60*60*24)
					{
					$value = floor($uptime_seconds/(60*60*24));
					$uptime_text .= $value." Days ";
					$uptime_seconds -= $value*60*60*24;
					}
				if ($uptime_seconds > 60*60)
					{
					$value = floor($uptime_seconds/(60*60));
					$uptime_text .= $value." Hours ";
					$uptime_seconds -= $value*60*60;
					}
				$value = floor($uptime_seconds/60);
				$uptime_text .= $value." Minutes ";
				$uptime_seconds -= $value*60*60;
				echo("<TD>Uptime: ".$uptime_text);
				}
			if ($extension['loadavg'] != "")
				echo("<TR><TD>5 Min load Avg: ".$extension['loadavg']);
			echo("</TABLE>");
			}
		echo "<h4><a onclick=\"window.moveTo(0,0); window.resizeTo(screen.width,screen.height);\" href=sensors.php?sensor_id=".$interface['sensor_id'].">".$interface['interface']." - ".$interface['description']."</a></h4>\n";
		if ($extension['minlatency'] != "")
			{
			echo("<TABLE><TR><TD>Latency:<TD>Min<TD>".$extension['minlatency']."ms<TD>Avg<TD>".$extension['avglatency']."ms<TD>Max<TD>".$extension['maxlatency']."ms</TABLE>");
			}
		if ($extension['ipaddr'] != "")
			echo "<PRE>".$extension['ipaddr']."</PRE>\n";
		if ($extension['errors'] != "")
			echo "<PRE>".$extension['errors']."</PRE>\n";	
		if ($extension['wireless'] != "")
			echo "<PRE>".preg_replace("/Encryption key:[0-9A-F-]*/", "Encryption key:HIDDEN", $extension['wireless'])."</PRE>\n";
		echo "Transmit<br><img src=graph.php?ip=0.0.0.0/0&sensor_id=".$interface['sensor_id']."&table=bd_tx_total_log&width=525&height=150><BR>";
		echo "Receive<BR><img src=graph.php?ip=0.0.0.0/0&sensor_id=".$interface['sensor_id']."&table=bd_rx_total_log&width=525&height=150><BR>";
		}
    }

// Add some blank lines to the bottom so we can always scroll all the way down to the bottom graph
?>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>