# apt-get install python-rrdtool
# rrdtool create traffic.rrd --start 1340723000 --step 300 \ DS:input:COUNTER:600:U:U \ DS:output:COUNTER:600:U:U \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775
#!/usr/bin/python import rrdtool import sys import re import time proc = '/proc/net/dev' iname = 'eth0:' infile = open(proc, "r") while infile: line = infile.readline() if len(line) == 0: break index = line.find(iname) if index > 0: trafficinfo=line[index+len(iname):] items = re.split(" +", trafficinfo) inbyte = items[0] outbyte = items[8] uptime = int(time.time()) rtv = rrdtool.update('traffic.rrd', "{0}:{1}:{2}".format(uptime,inbyte, outbyte)) starttime = time.time() - (3600 * 24) rtv = rrdtool.graph('traffic.png', '--imgformat', 'PNG', '--width', '540', '--height', '100', '--start', "%i" % starttime, '--end', "-1", '--vertical-label', 'Traffic', '--title', 'Input/Output Traffic', 'DEF:input=/var/www/moniwiki/script/traffic.rrd:input:AVERAGE', 'DEF:output=/var/www/moniwiki/script/traffic.rrd:output:AVERAGE', 'LINE1:input#990033', 'LINE1:output#FF0000' )
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
Contents
rrdpython
예제
Recent Posts
Archive Posts
Tags