aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rwxr-xr-xweb/nms.gathering.org/ping-json.pl11
-rw-r--r--web/nms.gathering.org/ping.js19
2 files changed, 25 insertions, 5 deletions
diff --git a/web/nms.gathering.org/ping-json.pl b/web/nms.gathering.org/ping-json.pl
index 78e795a..e661e8f 100755
--- a/web/nms.gathering.org/ping-json.pl
+++ b/web/nms.gathering.org/ping-json.pl
@@ -7,13 +7,18 @@ use nms;
my $cgi = CGI->new;
my $dbh = nms::db_connect();
+my %json = ();
my $q = $dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping WHERE updated >= NOW() - INTERVAL '15 secs' ORDER BY switch, updated DESC;");
$q->execute();
-
-my %json = ();
while (my $ref = $q->fetchrow_hashref()) {
- $json{'switches'}{$ref->{'switch'}} = $ref->{'latency_ms'};
+ $json{'switches'}{$ref->{'switch'}}{'latency'} = $ref->{'latency_ms'};
+}
+
+my $qs = $dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping_secondary_ip WHERE updated >= NOW() - INTERVAL '15 secs' ORDER BY switch, updated DESC;");
+$qs->execute();
+while (my $ref = $qs->fetchrow_hashref()) {
+ $json{'switches'}{$ref->{'switch'}}{'latency_secondary'} = $ref->{'latency_ms'};
}
my $lq = $dbh->prepare("SELECT DISTINCT ON (linknet) linknet, latency1_ms, latency2_ms FROM linknet_ping WHERE updated >= NOW() - INTERVAL '15 secs' ORDER BY linknet, updated DESC;");
diff --git a/web/nms.gathering.org/ping.js b/web/nms.gathering.org/ping.js
index c1b2fbe..ce3d99f 100644
--- a/web/nms.gathering.org/ping.js
+++ b/web/nms.gathering.org/ping.js
@@ -110,6 +110,15 @@ function update_ping(json) {
setTimeout(get_ping, 1000);
}
+function gradient_from_latency(latency_ms, latency_secondary_ms) {
+ if (latency_secondary_ms === undefined) {
+ return rgb_from_latency(latency_ms);
+ }
+ return '-webkit-gradient(linear, left top, left bottom, ' +
+ 'from(' + rgb_from_latency(latency_ms) + '), ' +
+ 'to(' + rgb_from_latency(latency_secondary_ms) + '))';
+}
+
function rgb_from_latency(latency_ms) {
if (latency_ms === null || latency_ms === undefined) {
return '#0000ff';
@@ -127,8 +136,14 @@ function rgb_from_latency(latency_ms) {
function really_update_ping(json) {
if (json['switches']) {
for (var switchnum in switches) {
- switches[switchnum].style.backgroundColor = rgb_from_latency(json['switches'][switchnum]);
- }
+ if (json['switches'][switchnum]) {
+ switches[switchnum].style.background =
+ gradient_from_latency(json['switches'][switchnum]['latency'],
+ json['switches'][switchnum]['latency_secondary']);
+ } else {
+ switches[switchnum].style.background = '#0000ff';
+ }
+ }
}
if (json['linknets']) {
for (var linknetnum in linknets) {