Jan 19, 2010 5:45 AM
accessing RRD values in object files
-
Like (0)
Hi ,
I have a requirement to show the RRD values in an object file. I was able to access the RRD values from object file using "cacheRRDValue" method. But the problem is the values in RRD file are not the exact values that my snmp agent returned.
I used the following command to create an RRD file
RRA:AVERAGE:0.5:1:600
RRA:AVERAGE:0.5:6:600
RRA:AVERAGE:0.5:24:600
RRA:AVERAGE:0.5:288:600
RRA:MAX:0.5:6:600
RRA:MAX:0.5:24:600
RRA:MAX:0.5:288:600
When there is a time dealy of 30 or 40 seconds in collecting the perfromance data, RRD is averaging the value and storing the modified new value in a RRA. But still I could see the last collected value in RRD file. ( I used rrdtool dump command to see the content in the file ).
<!-- Round Robin Database Dump --><rrd> <version> 0003 </version>
<step> 300 </step> <!-- Seconds -->
<lastupdate> 920809800 </lastupdate> <!-- 1999-03-07 07:30:00 EST -->
<ds>
<name> speed </name>
<type> GAUGE </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> NaN </min>
<max> NaN </max>
<!-- PDP Status -->
<last_ds> 1850 </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
-----
<last_ds> 1850 <last_ds> is the value that I am looking to display in an object file. Is there any api that can return the <last_ds> value? or is there a way to create an RRD file in which there won't be any calculations and store exact values that an snmp agent returns?
I spent around 3 days to find a solution for this but could not find any clues. I have gone through the RRDView.py but could not find any api to access the last datasource value.
Thanks in advance.
I've been using something like the following with some success:
#!/usr/bin/env python
from __future__ import division
import os,sys
import re
import time
import math
import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
# device name in Zenoss
devicename = "localhost"
# stand-in for metrics
metric = 'laLoadInt5'
# polling interval in seconds
interval = 300
# sample period in seconds
period = 86400
# first determine current time in epoch
now = int(time.time())
# subtract 24 hours from current time in epoch
yesterday = now - period
samples = int(period/interval)
# array to hold today's data
todaysData=[]
# find the device
dmd = ZenScriptBase(connect=True).dmd
devices = dmd.Devices.getSubDevices()
for device in devices:
print device.id
if str(device.id) == devicename:
print "found",device.id
rrdsource = device
# for each interval in the day, pull the RRD data
alpha = yesterday
while samples > 0 :
omega = alpha + interval
value = rrdsource.getRRDValue(metric, start=alpha, end=omega, function="LAST")
todaysData.append(value)
alpha = yesterday + interval
samples = samples - 1
print "samples:",len(todaysData)
for data in todaysData:
print data
Hi ,
Thanks for the info.
I resolved the issue by using the below code in model file
def getrtedHostSRFailedEvents(self):
"""
Returns the cached rtedHostSRFailedEvents for this device
@rtype: int
"""
try:
log = logging.getLogger('zen.MinMaxCheck')
fileName = self.getRRDFileName('rtedHostSRFailedEvents')
perfPath = zenPath('perf')
fileName = perfPath + '/' + fileName
log.warn("fileName %s",fileName)
val = rrdtool.info(fileName)['ds[ds0].last_ds']
if val == 'U':
return 'unknown'
else:
return val
# return long(self.cacheRRDValue('rtedHostSRFailedEvents', -1))
except Exception:
log.exception("failed getting rtedHostSRFailedEvents")
return 'unknown'
Follow Us On Twitter »
|
Latest from the Zenoss Blog » | Community | Products | Services Resources | Customers Partners | About Us | ||
Copyright © 2005-2011 Zenoss, Inc.
|
||||||||