Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to RRD-Ping getting values on right interval by hello_world

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-19 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found