本文整理汇总了Python中pyrrd.rrd.RRD类的典型用法代码示例。如果您正苦于以下问题:Python RRD类的具体用法?Python RRD怎么用?Python RRD使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RRD类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
def create(self):
"""
Creates a new RRD database
"""
ds1 = DS(dsName=self.value_name, dsType=self.type, heartbeat=self.heartbeat)
dss = [ds1]
rras = []
# 1 days-worth of n heartbeat samples --> 60/1 * 24
rra1 = RRA(cf="AVERAGE", xff=0.5, steps=1, rows=int(self.heartbeat / 1.0 * 24))
# 7 days-worth of n heartbeat samples --> 60/5 * 24 * 7
rra2 = RRA(cf="AVERAGE", xff=0.5, steps=5, rows=int(self.heartbeat / 5.0 * 24 * 7))
# 30 days-worth of n heartbeat samples --> 60/60 * 24 * 30
rra3 = RRA(cf="AVERAGE", xff=0.5, steps=60, rows=int(self.heartbeat / 60.0 * 24 * 30))
# 365 days worth of n heartbeat samples --> 60/120 * 24 * 365
rra4 = RRA(cf="AVERAGE", xff=0.5, steps=120, rows=int(self.heartbeat / 120.0 * 24 * 365))
# 10 years worth of n heartbeat samples --> 60/180 * 24 * 365 * 10
rra5 = RRA(cf="AVERAGE", xff=0.5, steps=180, rows=int(self.heartbeat / 180.0 * 24 * 365 * 10))
rras.extend([rra1, rra2, rra3, rra4, rra5])
rrd = RRD(
os.path.join("history/", "%s.rrd" % self.value_id), step=self.heartbeat, ds=dss, rra=rras, start=self.time
)
rrd.create(debug=False)
示例2: graph
def graph(req, rrd):
if os.path.isfile(rrdPath+rrd):
filename = rrd
rrd = RRD(rrdPath+rrd, mode='r')
info = rrd.getData()
info['filename'] = filename
return render_to_response('rrd/graph.html', {'info': info})
示例3: RrdCreate
def RrdCreate(rrdfile):
'''Creates a RRD database.'''
dataSources = []
roundRobinArchives = []
dataSources.append(DataSource(
dsName='temperature', dsType='GAUGE', heartbeat=600,
minval=-50, maxval=100))
dataSources.append(DataSource(
dsName='humidity', dsType='GAUGE', heartbeat=600,
minval=0, maxval=100))
dataSources.append(DataSource(
dsName='mq9', dsType='GAUGE', heartbeat=600))
dataSources.append(DataSource(
dsName='dust_pc', dsType='GAUGE', heartbeat=600, minval=0))
dataSources.append(DataSource(
dsName='dust_raw', dsType='GAUGE', heartbeat=600))
# Keep all values for 10 days
roundRobinArchives.append(RRA(cf='AVERAGE', xff=0.5, steps=1,
rows=10*24*60))
# Keep 15-minute averages for one year days
roundRobinArchives.append(RRA(cf='AVERAGE', xff=0.5, steps=15,
rows=365*24*4))
# Keep 1-hour averages for 10 years
roundRobinArchives.append(RRA(cf='AVERAGE', xff=0.5, steps=60,
rows=10*365*24))
myRRD = RRD(
rrdfile, step=60, ds=dataSources, rra=roundRobinArchives)
myRRD.create()
示例4: create
def create(namerrd,fieldname,starttime,typeofinfo):
try:
dataSources = []
roundRobinArchives = []
dataSources = get_ds(fieldname)
if typeofinfo == 'hardware' :
dict = {}
dict = config_info['hardware']
s = dict['func']
step = dict['step']
funcProfile = globals()[s]
roundRobinArchives = funcProfile()
elif typeofinfo == 'netusage':
dict = {}
dict = config_info['netusage']
s = dict['func']
step = int(dict['step'])
funcProfile = globals()[s]
roundRobinArchives = funcProfile()
myRRD = RRD(filename=namerrd,ds=dataSources, rra=roundRobinArchives, start=starttime,step=step)
myRRD.create()
return (True,'Create is successfull.')
except Exception,e:
return (False,str(e))
示例5: rrdtool_log
def rrdtool_log(self, count, category, key):
""" Log a message to an category's corresponding rrdtool databse """
# rrdtool doesn't like spaces
key = key.replace(' ', '_')
filename = rrd_dir + '/' + category + '/' + key + '.rrd'
if not category in rrd_categories:
raise ValueError, "Invalid category %s" % category
if not os.path.isfile(filename):
self.rrdtool_create(filename)
# rrdtool complains if you stuff data into a freshly created
# database less than one second after you created it. We could do a
# number of things to mitigate this:
# - sleep for 1 second here
# - return from this function and not log anything only on the
# first time we see a new data key (a new country, a new
# filename).
# - pre-create our databases at startup based on magical knowledge
# of what keys we're going to see coming over the AMQP line
#
# For now, we're just going to return.
return
# TODO -- Is this an expensive operation (opening the RRD)? Can we make
# this happen less often?
rrd = RRD(filename)
rrd.bufferValue(str(int(time.time())), str(count))
# This flushes the values to file.
# TODO -- Can we make this happen less often?
rrd.update()
示例6: RRDB
class RRDB(object):
def __init__(self, filename):
self.db = RRD(filename)
def store(self, values):
self.db.bufferValue(int(time.time()), *values)
self.db.update()
@classmethod
def generate_archives(cls, step, rows=1440,
day_periods=[2, 14, 60, 180, 720]):
rras = []
for days in day_periods:
# how many primary data points (we get one each step)
# go into a consolidated data point
PDPs = 86400 * days / step / rows
rras.extend([
RRA(cf='AVERAGE', xff=0.1, rows=rows, steps=PDPs),
RRA(cf='MIN', xff=0.1, rows=rows, steps=PDPs),
RRA(cf='MAX', xff=0.1, rows=rows, steps=PDPs),
])
return rras
@classmethod
def create_db(cls):
raise NotImplementedError("Create DB is not implemented")
def graph(self, outfile):
raise NotImplementedError("graph method should be overriden")
示例7: load_rrd
def load_rrd(cls, filepath, options, default_options):
take_param = lambda k: (k, options[k]
if k in options else default_options.get(k))
kargs = dict(map(take_param, ['start', 'end', 'resolution', 'cf']))
rrd = RRD(filepath, mode='r', backend=bindings)
rrd_data = rrd.fetch(**kargs)
return rrd_data.get('42')
示例8: _rrdtool_log
def _rrdtool_log(self, count, filename):
""" Workhorse for rrdtool logging. Shouldn't be called directly. """
if not os.path.isfile(filename):
self.rrdtool_create(filename)
# rrdtool complains if you stuff data into a freshly created
# database less than one second after you created it. We could do a
# number of things to mitigate this:
# - sleep for 1 second here
# - return from this function and not log anything only on the
# first time we see a new data key (a new country, a new
# filename).
# - pre-create our databases at startup based on magical knowledge
# of what keys we're going to see coming over the AMQP line
#
# For now, we're just going to return.
return
# TODO -- Is this an expensive operation (opening the RRD)? Can we make
# this happen less often?
rrd = RRD(filename)
rrd.bufferValue(str(int(time.time())), str(count))
# This flushes the values to file.
# TODO -- Can we make this happen less often?
rrd.update()
示例9: init_rdd
def init_rdd(self):
# Initiates RRD-archive
# Creates the new one if absent or need to reset
filename = options.rrd_file
if not options.rrd_reset and access(filename, F_OK):
myRRD = RRD(filename)
else:
heartbeat=options.stats_period*2
dataSources = [
DataSource(dsName='agents_u', dsType='ABSOLUTE', heartbeat=heartbeat),
DataSource(dsName='t_unique', dsType='ABSOLUTE', heartbeat=heartbeat),
DataSource(dsName='t_started', dsType='ABSOLUTE', heartbeat=heartbeat),
DataSource(dsName='t_completed', dsType='ABSOLUTE', heartbeat=heartbeat),
DataSource(dsName='t_failed', dsType='ABSOLUTE', heartbeat=heartbeat),
DataSource(dsName='bytes', dsType='ABSOLUTE', heartbeat=heartbeat),
DataSource(dsName='cpu', dsType='DERIVE', heartbeat=heartbeat,minval=0),
DataSource(dsName='duration', dsType='ABSOLUTE', heartbeat=heartbeat),
DataSource(dsName='duration_avg', dsType='GAUGE', heartbeat=heartbeat),
]
roundRobinArchives = []
for (_steps, _rows) in options.rrd_rra:
roundRobinArchives.append(RRA(cf='AVERAGE', xff=0.5, steps=_steps, rows=_rows))
roundRobinArchives.append(RRA(cf='MAX', xff=0.5, steps=_steps, rows=_rows))
myRRD = RRD(filename, ds=dataSources, rra=roundRobinArchives, step=options.stats_period)
myRRD.create(debug=True)
return myRRD
示例10: create
def create(self):
if os.path.exists(self.rrdfile):
self.rrd = RRD(self.rrdfile)
return
dss = []
ds1 = DS(dsName="requests", dsType="COUNTER", heartbeat=120, minval=0, maxval=100000000)
ds2 = DS(dsName="connections", dsType="ABSOLUTE", heartbeat=120, minval=0, maxval=60000)
ds3 = DS(dsName="reading", dsType="ABSOLUTE", heartbeat=120, minval=0, maxval=60000)
ds4 = DS(dsName="writing", dsType="ABSOLUTE", heartbeat=120, minval=0, maxval=60000)
ds5 = DS(dsName="waiting", dsType="ABSOLUTE", heartbeat=120, minval=0, maxval=60000)
dss.extend([ds1,ds2,ds3,ds4,ds5])
rras = []
rra1 = RRA(cf="AVERAGE", xff=0.5, steps=1, rows=2880)
rra2 = RRA(cf="AVERAGE", xff=0.5, steps=30, rows=672)
rra3 = RRA(cf="AVERAGE", xff=0.5, steps=120, rows=732)
rra4 = RRA(cf="AVERAGE", xff=0.5, steps=720, rows=1460)
rras.extend([rra1, rra2, rra3, rra4])
self.rrd = RRD(self.rrdfile, step=60, ds=dss, rra=rras)
self.rrd.create(debug=False)
time.sleep(2)
示例11: insert
def insert(self):
"""
Inserts new data in the RRD database
"""
rrd = RRD(os.path.join("history/", "%s.rrd" % self.value_id))
rrd.bufferValue(self.time, self.value_value)
rrd.update()
print self.time, self.value_value
示例12: data
def data(req, rrd, ds, rra):
if os.path.isfile(rrdPath+rrd):
rrd = RRD(rrdPath+rrd, mode='r')
info = rrd.getData()
step = info[rra]['step']
start = info['lastupdate'] - info[rra]['rows']*step
data = rrd.fetch(resolution=step, start=start, end=info['lastupdate'])
return HttpResponse(simplejson.dumps(data))
示例13: main
def main(self, argv):
"""
Create an RRD file with values 0-9 entered at 1 second intervals from
1980-01-01 00:00:00 (the first date that rrdtool allows)
"""
from pyrrd.rrd import DataSource, RRA, RRD
start = int(datetime(1980, 1, 1, 0, 0).strftime('%s'))
dss = []
rras = []
filename = os.path.join(self.build_dir, 'test.rrd')
rows = 12
step = 10
dss.append(
DataSource(dsName='speed', dsType='GAUGE', heartbeat=2 * step))
rras.append(RRA(cf='AVERAGE', xff=0.5, steps=1, rows=rows))
rras.append(RRA(cf='AVERAGE', xff=0.5, steps=12, rows=rows))
my_rrd = RRD(filename, ds=dss, rra=rras, start=start, step=step)
my_rrd.create()
for i, t in enumerate(
range(start + step, start + step + (rows * step), step)):
self.log.debug(
'DATA: %s %s (%s)' % (t, i, datetime.fromtimestamp(t)))
my_rrd.bufferValue(t, i)
# Add further data 1 second later to demonstrate that the rrd
# lastupdatetime does not necessarily fall on a step boundary
t += 1
i += 1
self.log.debug('DATA: %s %s (%s)' % (t, i, datetime.fromtimestamp(t)))
my_rrd.bufferValue(t, i)
my_rrd.update()
示例14: RrdProcess
def RrdProcess(rrdfile, samples):
'''Reads given samples and stores them in the RRD database.'''
# TODO: Optionally update the database only periodically.
rrd = RRD(rrdfile)
for sample in samples:
logging.debug("Saving sample %s", sample)
rrd.bufferValue(sample.time, sample.temperature, sample.humidity,
sample.mq9, sample.dust_pc, sample.dust_raw)
rrd.update(debug=True)
# Flush the print statements executed so far.
sys.stdout.flush()
示例15: dumpfileinfo
def dumpfileinfo(self):
#rrds = os.walk(self.path)
mylist = []
for root, dir, files in os.walk(self.path):
for sfile in files:
filename = os.path.join(root, sfile)
subpath = filename[len(self.path):]
rrd = RRD(filename, mode='r')
info = rrd.getData()
for i in rrd.ds:
mylist.append((self,subpath,sfile,i.name),)
return mylist