⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 np_act.py

📁 该软件根据网络数据生成NetFlow记录。NetFlow可用于网络规划、负载均衡、安全监控等
💻 PY
📖 第 1 页 / 共 3 页
字号:
#! /usr/bin/env python################################################################################                                                                             ##   Copyright 2005 University of Cambridge Computer Laboratory.               ##                                                                             ##   This file is part of Nprobe.                                              ##                                                                             ##   Nprobe is free software; you can redistribute it and/or modify            ##   it under the terms of the GNU General Public License as published by      ##   the Free Software Foundation; either version 2 of the License, or         ##   (at your option) any later version.                                       ##                                                                             ##   Nprobe is distributed in the hope that it will be useful,                 ##   but WITHOUT ANY WARRANTY; without even the implied warranty of            ##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             ##   GNU General Public License for more details.                              ##                                                                             ##   You should have received a copy of the GNU General Public License         ##   along with Nprobe; if not, write to the Free Software                     ##   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA ##                                                                             ################################################################################################################################################################ #### Extract probe activity and resource usage from Nprobe logs## ## ############################################################################ import stringimport osimport sysimport nprobefrom sys import argvimport getoptfrom signal import *import socketfrom traceback import print_stackimport np_file_utilimport np_http_utilfrom  np_longutil import *from np_plot import *############################################################################def usage(scriptname):    print "usage: %s [-h(elp)] <rep-file-list>" % (scriptname)    sys.exit(1)#############################################################################def handle_sigint(n, f):    print 'SIGINT'    print_stack()    sys.exit(0)#############################################################################def places(f):        places = 1    while modf(f)[0]:        places += 1        f *= 10    return places############################################################################		scriptname = os.path.basename(argv[0])to_read = Nonetry:    optlist, args = getopt.getopt(sys.argv[1:], 'hr:')except getopt.error, s:    print '%s: %s' % (scriptname, s)    usage(scriptname)    sys.exit(1)optstr = ''for opt in optlist:    if opt[0] == "-h":	usage(scriptname)    if opt[0] == "-r":	to_read = int(opt[1])        signal(SIGINT, handle_sigint)REC_WIRE_PERIOD_REPORT = nprobe.REC_WIRE_PERIOD_REPORTREC_PERIOD_REPORT = nprobe.REC_PERIOD_REPORTREC_OTHER = nprobe.REC_OTHER_ALLREC_PROCSTAT = nprobe.REC_OTHER_PROCSTATREC_WRAPPER = nprobe.REC_OTHER_WRAPPERWRAPPER_TIME_CALLS = nprobe.WRAPPER_TIME_CALLSWRITE_BLKSZ = nprobe.WRITE_BLKSZopenfilelist, counters, basepath = np_file_util.get_files(args)nread = 0first_ts = 0 # time at startlast_uts = 0 # time of last rusage recordlast_utm = 0 # amount of last user rusagelast_stm = 0 # amount of last system rusage## last_majflt = 0## last_nswap = 0## last_blkio = 0## last_cswitches = 0last_times_ip_uusage = 0 # amount of last IP call rusagelast_times_ip_susage = 0last_times_tcp_uusage = 0 # amount of last TCP call rusagelast_times_tcp_susage = 0last_rts = 0 # time of last period recordlast_w_rts = 0 # time of last pkt driven period recordlast_times_ts = 0 # time of last call rusage recordlast_tous_in = 0last_tous_out = 0last_frus_in = 0last_frus_out = 0lastrtm = 0# where to collect the statsurusage = []srusage = []trusage = []## maxrss = []## majflt = []## nswap = []## blkio = []## cswitches = []## times_ip_uusage = []## times_ip_susage = []## times_tcp_uusage = []## times_tcp_susage = []## times_udp_uusage = []## times_udp_susage = []## times_tcp_inseq_uusage = []## times_tcp_inseq_susage = []## times_tcp_catchup_uusage = []## times_tcp_catchup_susage = []## times_tcp_serv_uusage = []## times_tcp_serv_susage = []## times_http_uusage = []## times_http_susage = []## times_html_uusage = []## times_html_susage = []wire_bw = []tcp_bw = []udp_bw = []http_bw = []html_parse = []wire_pkts = []tcp_pkts = []udp_pkts = []http_pkts = []rwritten = []dwritten = []twritten = []rdumped = []ddumped = []tdumped = []max_fetch_int = []bheld = []fails = []IP_ulen = []tcp_to = []udp_to = []tcp_seq_to = []tous_in = []tous_out = []frus_in = []frus_out = []# do but packet arrival drivenw_wire_bw = []w_tcp_bw = []w_udp_bw = []w_http_bw = []w_html_parse = []w_wire_pkts = []w_tcp_pkts = []w_udp_pkts = []w_http_pkts = []# stats from /proc/selfproc_utm = []proc_stm = []proc_ttm = []proc_majflt = []proc_nswap = []# stats from /proc/statsproc_itot = []proc_csw = []# running maximum for scaling## max_maxrss = 0## max_majflt = 0## max_nswap = 0## max_blkio = 0## max_cswitches = 0## max_times_ip_uusage = 0## max_times_ip_susage = 0## max_times_tcp_uusage = 0## max_times_tcp_susage = 0## max_times_udp_uusage = 0## max_times_udp_susage = 0## max_times_tcp_inseq_uusage = 0## max_times_tcp_inseq_susage = 0## max_times_tcp_catchup_uusage = 0## max_times_tcp_catchup_susage = 0## max_times_tcp_serv_uusage = 0## max_times_tcp_serv_susage = 0## max_times_http_uusage = 0## max_times_http_susage = 0## max_times_html_uusage = 0## max_times_html_susage = 0max_wmbs = 0max_tmbs = 0max_umbs = 0max_hmbs = 0 max_wpps = 0max_tpps = 0max_upps = 0max_hpps = 0max_hparsed = 0max_repwritten = 0max_dumpwritten = 0max_twritten = 0max_repdumped = 0max_dumpdumped = 0max_tdumped = 0max_mfi = 0max_bheld = 0max_fails = 0max_IP_ulen = 0max_tcp_to = 0max_udp_to = 0max_tcp_seq_to = 0max_tous_in = 0max_tous_out = 0max_frus_in = 0max_frus_out = 0# do but packet arrival drivenw_max_wmbs = 0w_max_tmbs = 0w_max_umbs = 0w_max_hmbs = 0w_max_wpps = 0w_max_tpps = 0w_max_upps = 0w_max_hpps = 0w_max_hparsed = 0# stats from /proc/selfmax_proc_utm = 0max_proc_stm = 0max_proc_ttm = 0max_proc_majflt = 0max_proc_nswap = 0# stats from /proc/statsmax_proc_itot = 0max_proc_csw = 0ru = nprobe.np_rusage()pr = nprobe.period_report()wr = nprobe.wrapper_record()pcr = nprobe.procstat_rec()file_closes = []for file in openfilelist:        fnm = os.path.basename(file.fnm)    hz = file.get_hz()    ncpus = file.get_ncpus()    #if len(openfilelist) > 1:    if 1:	print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"	print "File %s - %d records" % (fnm, file.counters.nrecords)	print	sys.stdout.flush()            while 1:                nread += 1        if to_read and nread > to_read:            break                 #rectype = file.find_next_period_record()        rectype = file.next_type_rec(REC_OTHER)        #print rectype	if rectype == -1: #EOF	    break        elif rectype == REC_WIRE_PERIOD_REPORT:            pr.read_reprec(file, ru, 0)            #            # stats stuff - but driven by packet arrival times            #            rts = tv2l(pr.get_ts())            if first_ts == 0:                first_ts = rts            if rts == last_w_rts:                print 'rusage - duplicated time stamp',                #print float(rts-first_ts)/1000000                continue            per = rts - last_w_rts            last_w_rts = rts            ts = float(rts - first_ts)/1000000            #print ts, per

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -