Comments on: How to gather statistics at regular intervals http://www.xaprb.com/blog/2011/03/18/how-to-gather-statistics-at-regular-intervals/ Stay curious! Fri, 10 May 2013 18:25:19 +0000 hourly 1 http://wordpress.org/?v=3.5.1 By: Xaprb http://www.xaprb.com/blog/2011/03/18/how-to-gather-statistics-at-regular-intervals/#comment-19208 Xaprb Fri, 18 Mar 2011 16:59:43 +0000 http://www.xaprb.com/blog/?p=2241#comment-19208 lamby, I found that even backgrounding (and sleep itself) causes enough drift to matter. Jeremy, yes that’s a good Perl-ism. I remember that we used that in mk-heartbeat originally, but ultimately had to move away from it because of various problems I don’t recall with sleep and alarms and signal handlers… it stops working reliably when things get more complex. Allan, bash doesn’t do floating-point math, only integer math.

]]>
By: Allan Wind http://www.xaprb.com/blog/2011/03/18/how-to-gather-statistics-at-regular-intervals/#comment-19207 Allan Wind Fri, 18 Mar 2011 15:31:51 +0000 http://www.xaprb.com/blog/?p=2241#comment-19207 watch -n 1 gather-some-stats if you want the first behavior. expr or \$(()) at least with bash allows easier math.

]]>
By: Jeremy Cole http://www.xaprb.com/blog/2011/03/18/how-to-gather-statistics-at-regular-intervals/#comment-19206 Jeremy Cole Fri, 18 Mar 2011 14:50:51 +0000 http://www.xaprb.com/blog/?p=2241#comment-19206 Baron,

I usually use Perl and Time::HiRes for that. The following pattern should do what you want (for 1 second intervals here):

use Time::HiRes qw( ualarm );

\$SIG{ALRM} = sub {};
ualarm((1_000_000 – (gettimeofday)[1]), 1_000_000);
while(1)
{
sleep;
print “beep!\n”;
}

This will set up a repeating timer, starting at the edge of the next second, and repeating every 1 second after that. Unhooking SIGALRM from its default abort handler will just cause it to wake up from the indefinite “sleep” call.

Regards,

Jeremy

]]>
By: lamby http://www.xaprb.com/blog/2011/03/18/how-to-gather-statistics-at-regular-intervals/#comment-19205 lamby Fri, 18 Mar 2011 14:32:28 +0000 http://www.xaprb.com/blog/?p=2241#comment-19205 If you don’t care about the possibility of concurrent stats collection processes, you could simply fork the gather-some-stats call and sleep for \$INTERVAL. You will perhaps still “drift” over the course of a week or so, but perhaps that’s acceptable.

]]>