Hi Folks,
I have a script to update the RRD databases with latency values to 5 different locations.The script forks 5 different process where each process will run the ping command to their respective location for 15 seconds and sleep for remaining 45 seconds & update the rrd databases after that with the values.
What i intend to by this is to update the RRD databases exactly at every 1 minute interval (i.ee 12:40:00 ,12:41:00,12:42:00 and so on...) The breakup is as follows:
12:40:00 - 12:40:15 (ping for 15 seconds)
12:40:15 - 12:40:59 (sleep for 45 seconds)
12:41:00 - update the rrd db
The problem i am facing is that the values dont arrive exactly at the right interval after some time..i.ee the values start to drift.
Instead of getting the value at 16:50:00 or 16:51:00 ..16:52:00 i am getting the values 3-4 seconds late i.ee 16:50:04 ..16:51:04..16:52:04
So,how do i make sure that i input the values in the db exactly at 1 minute interval ??
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
use POSIX;
use IO::Handle;
use IPC::Open3;
use Data::Dumper;
sub _Forked {
my $ip = shift;
#
croak "Couldn't fork" unless defined (my $pid = fork());
if ($pid == 0) {
#CHILD
while (1) {
#
sleep 45;
my @data = `/bin/ping -w 15 -q $ip`;;
my @values = ($data[4] =~ m{(\d+).\d+}g);
my $time = scalar localtime();
print "$time - $ip - @values\n";
#
}
}
#
return ($pid);
}
sub main {
my $DSname = {
can => 'vfs.edu',
us => 'ucla.edu',
aus => 'cdu.edu.au',
mal => 'um.edu.my',
uk => 'imperial.ac.uk',
};
#
foreach my $host (keys %{$DSname}) {
my $cpid = _Forked($DSname->{$host});
}
#
my $dpid = POSIX::waitpid(-1,WUNTRACED);
}
main();
The script will just print the values as of now
Output
Wed Nov 30 12:27:00 2011 - cdu.edu.au - 241 246 255 5
Wed Nov 30 12:27:00 2011 - vfs.edu - 251 254 260 3
Wed Nov 30 12:27:00 2011 - ucla.edu - 216 223 233 6
Wed Nov 30 12:27:00 2011 - um.edu.my - 112 119 124 3
Wed Nov 30 12:27:00 2011 - imperial.ac.uk - 171 178 185 6
After few hours,the values are:
Wed Nov 30 15:28:04 2011 - cdu.edu.au - 241 246 255 5
Wed Nov 30 15:28:04 2011 - vfs.edu - 251 254 260 3
Wed Nov 30 15:28:04 2011 - ucla.edu - 216 223 233 6
Wed Nov 30 15:28:04 2011 - um.edu.my - 112 119 124 3
Wed Nov 30 15:28:04 2011 - imperial.ac.uk - 171 178 185 6
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.