Import RRDtool
Import time
CUR_TIME=STR (int (time.time ()))
Rrd=rrdtool.create (' flow.rrd ', '--step ', ' a ', '--start ', Cur_time, #Flow. RRD filename,--step indicates how often the data is written, Start indicates the start time of the first record
' Ds:eth0_in:counter:600:0:u ', #DS定义数据源, the network card eth0 into the traffic, COUNTER represents the increment (DST definition data type), followed by 600 seconds for the heartbeat value, 600 seconds without receiving data, will be replaced with unknown, 0 is the minimum value and U is the maximum value
' Ds:eth0_out:counter:600:0:u ', #DST有的类型: DERIVE (can be increased and reduced), ABSOLUTE (assuming the previous time interval is 0, then the average), guage (the value is received directly into RRA), COMPUTE (defining expressions, referencing DS and automatically calculating a value)
' rra:average:0.5:1:600 ', #RRA定义数据存储格式
' rra:average:0.5:6:700 ', #CF统计合并数据, with AVERAGE, Max, min,last up-to-date values
' rra:average:0.5:24:775 ', #数字0.5 indicates that PDP values in one CDP are marked as unknown if more than half are unknown.
' rra:average:0.5:288:797 ', #存储时间计算为0. The value after 5 is multiplied by 300 seconds, and the last value represents the number of times the value is stored
' rra:max:0.5:1:600 ',
' rra:max:0.5:6:700 ',
' rra:max:0.5:24:775 ',
' rra:max:0.5:444:797 ',
' rra:min:0.5:1:600 ',
' rra:min:0.5:6:700 ',
' rra:min:0.5:24:775 ',
' rra:min:0.5:444:797 ')
If RRD:
Print (Rrdtool.error ())
RRDtool combine Python to count network card traffic