aboutsummaryrefslogtreecommitdiffstats
path: root/web/nms.gathering.org/api/public/ping
diff options
context:
space:
mode:
authorKristian Lyngstol <kly@kly.no>2016-03-17 19:51:46 +0000
committerKristian Lyngstol <kly@kly.no>2016-03-17 19:51:46 +0000
commit5c9d6d10dc7e53a8d06fbd056ded591a6b583167 (patch)
tree6f6290fb1b8bcc859278a2c68573a35547173931 /web/nms.gathering.org/api/public/ping
parent76a3aad5090d304ec0f76f28e50afe1f53b7b96c (diff)
parent025f01e7e8c5bfea21b559fbac650f90c2774a29 (diff)
Merge branch 'master' of https://github.com/tech-server/tgmanage
Diffstat (limited to 'web/nms.gathering.org/api/public/ping')
-rwxr-xr-xweb/nms.gathering.org/api/public/ping12
1 files changed, 9 insertions, 3 deletions
diff --git a/web/nms.gathering.org/api/public/ping b/web/nms.gathering.org/api/public/ping
index f13a03b..bf92440 100755
--- a/web/nms.gathering.org/api/public/ping
+++ b/web/nms.gathering.org/api/public/ping
@@ -2,10 +2,18 @@
use lib '../../../../include';
use nms::web;
-my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) time,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE time in (select max(time) from ping where " . $nms::web::when . " group by switch)");
+#nms::web::setwhen('1s');
+
+my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (now() - time) as age,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE time in (select max(time) from ping where " . $nms::web::when . " group by switch)");
$q->execute();
while (my $ref = $q->fetchrow_hashref()) {
$nms::web::json{'switches'}{$ref->{'sysname'}}{'latency'} = $ref->{'latency_ms'};
+ # This isn't pretty, feel free to fix, but I want age == seconds
+ # without decimals.
+ my ($h,$m,$ss) = split(':', $ref->{'age'});
+ my ($s,undef) = split('\.', "$ss");
+
+ $nms::web::json{'switches'}{$ref->{'sysname'}}{'age'} = ($h*60*60) + ($m*60) + $s;# $$ref->{'age'};
}
my $qs = $nms::web::dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping_secondary_ip WHERE " . $nms::web::when . " ORDER BY switch, time DESC;");
@@ -20,8 +28,6 @@ while (my $ref = $lq->fetchrow_hashref()) {
$nms::web::json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ];
}
-$q->execute();
-
$nms::web::cc{'max-age'} = "1";
$nms::web::cc{'stale-while-revalidate'} = "5";
finalize_output();