Linux systems use Python to monitor network interfaces for network input and output

Source: Internet
Author: User

#!/usr/bin/env Python
Import time
Import Sys

If Len (SYS.ARGV) > 1:
INTERFACE = sys.argv[1]
Else
INTERFACE = ' eth0 '
STATS = []
print ' Interface: ', Interface

Def RX ():
Ifstat = open ('/proc/net/dev '). ReadLines ()
For interface in Ifstat:
If INTERFACE in INTERFACE:
Stat = float (Interface.split () [1])
Stats[0:] = [stat]

DEF TX ():
Ifstat = open ('/proc/net/dev '). ReadLines ()
For interface in Ifstat:
If INTERFACE in INTERFACE:
Stat = float (Interface.split () [9])
Stats[1:] = [stat]

print ' in Out '
Rx ()
TX ()

While True:
Time.sleep (1)
Rxstat_o = List (STATS)
Rx ()
TX ()
RX = float (stats[0])
Rx_o = rxstat_o[0]
TX = float (stats[1])
Tx_o = rxstat_o[1]
Rx_rate = Round ((rx-rx_o)/1024/1024,3)
Tx_rate = Round ((tx-tx_o)/1024/1024,3)
Print rx_rate, ' MB ', tx_rate, ' MB '

Linux systems use Python to monitor network interfaces for network input and output

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.