unix - Reading Incoming Mbit/s in plaintext with Perl -


I can not find any solution for this, I want to read the incoming MBT / S on the interface in Perl. I am just trying to report Perl script as MBT / S: 9.66 It will be as if I have a network of 9.66 MB / s.

I tried to use VNNastat and parse the characters. But no benefit.

If you are on a Linux system, then there are usually sub directories in / sys / :

  / sys / class / net / eth0 / statistics   

If you can depend on that current constant (/ sys /) in kernel 2 , Then you should be fine), "files" in that directory can be used to create some statistics on the interface, including incoming (Rx) bytes in that interface.

Here is a extremely crude example:

  Usage list :: UTL qw (amount); My @bytes; (1..11) {open (FH, "& lt;", "/ sys / class / net / eth0 / statistics / rx_bytes") or die $ @; Push (@bytes, & lt; fh & gt;); Sleeping 1; Close (FH); } My @bytes_per_second; (1..10) {my $ diff = ($ bytes [$ _] - $ bytes [($ _ - 1)]); Push (@bytes_per_second, $ diff); } Print amount (@ bytes_per_second) / @ bytes_per_second;   

The above code will give you an average [bytes] of the average data per second (seconds) in the interface called "atte". There are great ways to improve this performance, which I do not think are necessary for this performance, but using a timer and reading it separately from the file.

Hope this will prove useful to you, but if you are not on Linux, then unfortunately it will be completely useless.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -