Search code examples
phpnetwork-monitoring

PHP network monitoring debian


My plan is to monitor network activity/usage on eth0 on my debian wheezy 7.1 using php. Could this done be done somehow by php? Does exist some library for this? Or should I use exec() and parse the output?

Would be really thankful for every tutorial, suggestion or a tip, thanks!


Solution

  • The info you need is in /proc/net/dev

    # cat /proc/net/dev
    Inter-|   Receive                                                |  Transmit
     face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
        lo:  177937    1304    0    0    0     0          0         0   177937    1304    0    0    0     0       0          0
      eth0:16268834   14619    0    0    0 10091          0         0  1201136   10555   20    0    0     0       0          0
    

    For the transfer rate you will have to calculate the delta from the previous capture but the value will be approximate.