This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtooltipdata.php
112 lines (101 loc) · 3.06 KB
/
tooltipdata.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?
/*
* TODO: make more generic for all metric types?
* TODO: return more information than just latency and loss? Better tooltips
*/
require_once("matrix_lib.php");
$now = time();
$expires = $now + 600;
header("Expires: $expires");
header("Cache-Control: public, max-age=$expires");
header("Last-Modified: $now");
header_remove("Pragma");
/* we get a few historical periods for latency */
$intervals = array(
//'10mins' => SECONDS_10MINS,
'1hour' => SECONDS_1HOUR,
'1day' => SECONDS_1DAY,
'1week' => SECONDS_1WEEK
);
/* and cache the longer periods for longer */
$cachetimes = array(
//'10mins' => SECONDS_1MIN,
'1hour' => SECONDS_5MINS,
'1day' => SECONDS_30MINS,
'1week' => SECONDS_1HOUR
);
if ( !isset($_REQUEST["src"]) || !isset($_REQUEST["dst"]) ) {
echo "<div>src and dst both need to be set!</div>";
exit;
}
//TODO check ampsource,ampdest,metric are all valid
$ampsource = $_REQUEST["src"];
$ampdest = $_REQUEST["dst"];
$response = array();
getSites($sites, "", "");
if ( !array_key_exists($ampsource, $sites) ) {
echo "<div>Unknown source $ampsource</div>";
exit;
}
getSites($sites, $ampsource, "");
if ( !array_key_exists($ampdest, $sites) ) {
echo "<div>Unknown destination $ampdest</div>";
exit;
}
$memcache_connected = false;
if(class_exists('Memcache')) {
$memcache = new Memcache;
$memcache_connected = $memcache->connect('localhost', 11211);
}
foreach($intervals as $i => $seconds) {
$cache_hit = false;
$key = $ampsource . $ampdest . "latency" . $i;
if ( $memcache_connected ) {
if ( ($data = $memcache->get($key)) != false ) {
$cache_hit = true;
}
}
/* fetch and save it if it isn't already in cache */
if ( $cache_hit == false ) {
$data = getLatencyData($ampsource, $ampdest, $seconds);
/* cache data according to length of period */
if ( $memcache_connected )
$memcache->set($key, $data, 0, $cachetimes[$i]);
}
//echo "<br />$cache_hit<br />";
/* pass the data back to be displayed */
$response["latency"][$i] = roundRTT($data["latency"]);
$response["latency-stddev"][$i] = roundRTT($data["latency-stddev"]);
$response["loss"][$i] = $data["loss"];
}
if ( $memcache_connected ) {
$memcache->close();
}
/* format data for display in a tooltip */
$content = "<table>" .
"<thead>" .
"<tr><th colspan='4'>" . $ampsource . " to " . $ampdest . "</th></tr>" .
"<tr>" .
"<th> </th>" .
"<th>1 Hour<br />(average)</a></th>" .
"<th>24 Hour<br />(average)</th>" .
"<th>7 Day<br />(average)</th>" .
"</tr>" .
"</thead>" .
"<tbody>" .
"<tr>" .
"<td class='head'>Latency (ms)</td>" .
"<td>" . $response['latency']['1hour'] . "</td>" .
"<td>" . $response['latency']['1day'] . "</td>" .
"<td>" . $response['latency']['1week'] . "</td>" .
"</tr>" .
"<tr>" .
"<td class='head'>Packet Loss (%)</td>" .
"<td>" . $response['loss']['1hour'] . "</td>" .
"<td>" . $response['loss']['1day'] . "</td>" .
"<td>" . $response['loss']['1week'] . "</td>" .
"</tr>" .
"</tbody>" .
"</table>";
echo $content;
?>