aboutsummaryrefslogtreecommitdiffstats
path: root/collectors
diff options
context:
space:
mode:
authorJonas Lindstad <jonaslindstad@gmail.com>2016-05-24 13:04:34 +0200
committerJonas Lindstad <jonaslindstad@gmail.com>2016-05-24 13:04:34 +0200
commit2c9306e5be42d73c376ebdad5d927f63d4f3af86 (patch)
tree4442e9a49a23edc5581f9341043e34de5258af36 /collectors
parentd7db901796438c811ab239ecbbee0ad0dd49832c (diff)
parent78684bd2f31a6e8bd174219d363d116e1273f6a2 (diff)
Merge branch 'master' of https://github.com/tech-server/gondul
Diffstat (limited to 'collectors')
-rwxr-xr-xcollectors/ping.pl19
1 files changed, 14 insertions, 5 deletions
diff --git a/collectors/ping.pl b/collectors/ping.pl
index c50ea87..d5acded 100755
--- a/collectors/ping.pl
+++ b/collectors/ping.pl
@@ -1,7 +1,7 @@
#! /usr/bin/perl
use DBI;
use POSIX;
-use Time::HiRes;
+use Time::HiRes qw(sleep time);
use Net::Oping;
use strict;
use warnings;
@@ -15,11 +15,18 @@ my $dbh = nms::db_connect();
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
-my $q = $dbh->prepare("SELECT switch,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as secondary_ip FROM switches WHERE mgmt_v4_addr is not null or mgmt_v6_addr is not null ORDER BY random()");
-my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets WHERE addr1 is not null and addr2 is not null");
+my $q = $dbh->prepare("SELECT switch,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as secondary_ip FROM switches WHERE mgmt_v4_addr is not null or mgmt_v6_addr is not null ORDER BY random();");
+my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets WHERE addr1 is not null and addr2 is not null;");
+my $last = time();
+my $target = 0.2;
while (1) {
- sleep(0.5);
+ my $now = time();
+ my $elapsed = ($now - $last);
+ if ($elapsed < $target) {
+ sleep($target - ($now - $last));
+ }
+ $last = time();
# ping loopbacks
my $ping = Net::Oping->new;
$ping->timeout(0.2);
@@ -58,7 +65,9 @@ while (1) {
my $drops = 0;
while (my ($ip, $latency) = each %$result) {
my $switch = $ip_to_switch{$ip};
- next if (!defined($switch));
+ if (!defined($switch)) {
+ next;
+ }
if (!defined($latency)) {
$drops += $dropped{$ip};