tips-rrdtools
RRDtools
rrdpython
% pip3.7 --proxy http://127.0.0.1:18080 install --upgrade --user rrdtool
cli info
http://www.sakito.com/2012/10/rrdtool.html
tip
http://www.itmedia.co.jp/enterprise/articles/0705/25/news013_2.html
check
http://blog.majide.com/2009/02/socket-programming-server/
ネットワークの転送量は //sys/class/net/eth2/statistics/tx_bytes /proc/net/dev のいずれかから FreeBSD の場合には sysctl -a | grep em1 | grep recvd
pipy_rrdtools - sample
% cat test_CREATE.py
import rrdtool
# Create Round Robin Database
rrdtool.create('test.rrd', '--start', 'now', '--step', '300', 'RRA:AVERAGE:0.5:1:1200', 'DS:temp:GAUGE:600:-273:5000')
# Feed updates to the RRD
rrdtool.update('test.rrd', 'N:32')
% cat ./test_FETCH.py
import rrdtool
result = rrdtool.fetch("test.rrd", "AVERAGE")
start, end, step = result[0]
ds = result[1]
rows = result[2]
print(ds)
print(rows)
% cat ./test_graph.py
import rrdtool
result = rrdtool.graph("graph.png", *args)
width = result[0]
height = result[1]
if result[2] is not None:
calcpr = result[2] # list
% cat ./test_info.py
import rrdtool
ret = rrdtool.info("test.rrd")
print(ret)
RRDtols の応用
https://heartbeats.jp/hbblog/2013/02/predict-rrdtool.html
% cat ./test02.sh
rrdtool graph g0002.png \ --start="-1w" \ --end="+1w" \ --imgformat=PNG \ --title="Load Average (5min)" \ --height=400 \ --width=800 \ --lower-limit=0 \ DEF:load=/var/munin/PXY000/PXY000-load-load-g.rrd:42:MAX \ CDEF:sm=load,10800,TREND \ CDEF:cf=86400,-8,3600,sm,PREDICT \ AREA:load#CC0000:"Load Average (5min)" \ LINE1:sm#00CC00:"Smoothing" \ LINE1:cf#0000CC:"Curve Fitting" \ LINE2:2#CCCCCC:"Limit" # DEF:load=/var/munin/PXY000/PXY000-load-load-g.rrd:42:AVERAGE \ # AREA:load#CC0000:"Load Average (5min)" \ # LINE2:2#CCCCCC:"Limit
python-rrdtool sample
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import rrdtool
def create():
data_sources = [
'DS:load1:GAUGE:600:0:U',
'DS:load5:GAUGE:600:0:U',
'DS:load15:GAUGE:600:0:U',
]
rras = [
'RRA:AVERAGE:0.5:1:600',
'RRA:AVERAGE:0.5:6:700',
'RRA:AVERAGE:0.5:24:775',
'RRA:AVERAGE:0.5:288:797',
'RRA:MAX:0.5:1:600',
'RRA:MAX:0.5:6:700',
'RRA:MAX:0.5:24:775',
'RRA:MAX:0.5:288:797',
'RRA:MIN:0.5:1:600',
'RRA:MIN:0.5:6:700',
'RRA:MIN:0.5:24:775',
'RRA:MIN:0.5:288:797',
]
rrdtool.create('pyload.rrd',
'--step', '300',
data_sources,
rras)
def main():
create()
if __name__ == '__main__':
main()