Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Traffic monitor Linux Python Version     - How to create a new file system / partitions under Linux terminal (Linux)

- How to configure SNMPv3 on Ubuntu, CentOS and Cisco systems (Linux)

- Sshuttle A VPN-based transparent proxy that uses ssh (Server)

- Embedded Linux to solve the problem in the time zone (Linux)

- Linux System Getting Started Learning: The Linux ac command (Linux)

- Running into the site-wide HTTPS (Server)

- How VMware extend disk without rebooting the system (Linux)

- linux system optimization and security configuration (Linux)

- RedHat install GCC problem --- Depends (Linux)

- Three methods easy data encryption on Linux (Linux)

- DOM event handlers add notes (Programming)

- Memcache explain in detail (Server)

- Linux command execution judge sentences -;, &&, || (Linux)

- Source MongoDB 3.2.1 installed on CentOS6.5 (Database)

- Use Hexo quickly build and deploy a blog to Github (Server)

- Use GLOBK batch command network adjustment (Linux)

- Build your own Python coding environment (Linux)

- Several Ceph performance optimization of new methods and ideas (2015 SH Ceph Day after flu reference) (Server)

- Zabbix monitoring Oracle Database use Orabbix plug (Enhanced Edition) (Database)

- Depth understanding of Python character set encoding (Programming)

 
         
  Traffic monitor Linux Python Version
     
  Add Date : 2018-11-21      
         
         
         
  Python version of Linux traffic monitoring, directly on the code, passing parameters to use OptionParser


from __future__ import division
import re
import time
from optparse import OptionParser


def getbandwidth (eth = 'eth0', intevel = 1):
    a = open ( '/ proc / net / dev')
    data = a.read ()
    patten = eth + '. *'
    if not re.search (patten, data):
        print "The ETHname not have"
        exit (1)
    . Rev_old = re.search (patten, data) .group () replace ( ':', '') .split () [1]
    . Send_old = re.search (patten, data) .group () replace ( ':', '') .split () [9]
    a.close ()

    while True:
        #print intevel
        time.sleep (int (intevel))
        a = open ( '/ proc / net / dev')
        data = a.read ()
        . Rev = re.search (patten, data) .group () replace ( ':', '') .split () [1]
        . Send = re.search (patten, data) .group () replace ( ':', '') .split () [9]
        diff_Rev = int (Rev) -int (Rev_old)
        diff_Sen = int (Send) -int (Send_old)
        diff_M = diff_Rev * 8/1024/1024 / int (intevel)
        diff_S = diff_Sen * 8/1024/1024 / int (intevel)
        print time.strftime ( "% Y% m% d% H:% M:% S") + 'The Recevie is% 6.2f Mbps (byte is% d)'% (diff_M, diff_Rev) + 'The Send is% 6.2f Mbps (byte is% d) '% (diff_S, diff_Sen)
        Rev_old = Rev
        Send_old = Send
        a.close ()
if __name __ == '__ main__':
    
    import sys
    usage = '' '% prog [-i ethname] [-t interveltime]
          Example:% prog -i eth0 -t 1 '' '
    parser = OptionParser (usage = usage, version = '2.0_20150602')

    parser.add_option ( '- i', '- interface', dest = 'interface', default = 'eth0', help = 'Wann to interface')
    parser.add_option ( '- t', '- time', dest = 'intevel', type = 'int', default = '1', help = 'The intevel time')
    (Options, args) = parser.parse_args ()
    print "The interafce is% s and the intevel time is% d"% (options.interface, options.intevel)
    getbandwidth (options.interface, options.intevel)

Instructions:
'' '% Prog [-i ethname] [-t interveltime]
          Example:% prog -i eth0 -t 1 '' '
The default is eth0, the interval is 1
     
         
         
         
  More:      
 
- GNU / Linux system, how to clean up memory space (Linux)
- Rman Oracle database backup and recovery plan (Database)
- Examples of testing and installation Mesos on CentOS (Linux)
- How to use the process on the desktop xkill end Linux (Linux)
- Iptables use examples (Linux)
- Java object serialization and deserialization (Programming)
- RHEL5.x RHEL6.x replace CentOS yum source (Linux)
- Bash variable expansion modifier (Programming)
- Upgrading Oracle 11.2.0.1.0 to 11.2.0.3.0 (Database)
- Linux remote landing system (Linux)
- NAT and firewall under Linux (Linux)
- To install Ganglia (Linux)
- Linux Mint 17 set up the Ruby environment (Linux)
- Windows and Ubuntu dual system, repair of two ways UEFI boot (Linux)
- Use MD5 transform algorithm to prevent exhaustive decipher passwords (Linux)
- Python kills corresponding process according to pid (Programming)
- PXE + Kickstart automatically install CentOS 6.5 (Linux)
- How to install web crawler tool in Ubuntu 14.04 LTS: Scrapy (Linux)
- Linux system using the command line shutdown or restart (Linux)
- Nine tips to protect the security of Linux desktop (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.