$now=time; $packets_sec = $packets / ($now - $lasttime); $lasttime=$now;
is what I was thinking of. It just helps make up for an irregular timer a little bit, as if the timer took longer, there will be more packets and the elapsed time will be longer, balancing things out somewhat.

Those are really irregular. I wonder if the timer is only going off when packets are received?

If there's some kind of bad interaction between the alarms and the packet capturing (for example, Net::Pcap; is setting its own alarms), one approach would be to split up the packet code and the monitoring code into two processes. The packet sniffing code would just listen for packets, and whenever it found one print something to its standard out. Meanwhile, the monitoring code would count the number of times the packets sniffer printed, and when the alarm went off would print the result. That would split the alarm code and packet code into two seperate processes, so they can't interfere with each other.

Still, that sounds a bit elaborate. Perhaps somebody who knows Net::Pcap better than I do can give you better advice.


In reply to Re: Re: Re: IP Packet count at regular intervals of time by sgifford
in thread IP Packet count at regular intervals of time by prakashrj

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.