示例#1
0
 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')
示例#2
0
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))
示例#3
0
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))
示例#4
0
def data(req, rrdpathname, rrd, ds, rra):
	filename = Rrdpath.objects.get(name=str(rrdpathname)).path 
	fullfilename = filename + '/' + rrd
	if os.path.isfile(fullfilename):
                rrd = RRD(fullfilename, mode='r')
		info = rrd.getData()
		step = info['step']
		#this should be the pdp maybe
		start = info['lastupdate'] - 100*step
                #data = rrd.fetch(resolution=step, start=start, end=info['lastupdate'])
                data = rrd.fetch(resolution=step, start=start, end=info['lastupdate'])
        	return HttpResponse(simplejson.dumps(data))
示例#5
0
 def render_GET(self, request):
     
     self.request = request
     type = request.args["type"][0]
     period = request.args["period"][0]
     history_id = request.args["history_id"][0]
     
     if type == "gauge":
         rrd = RRD("history/%s.rrd" % history_id)
         result = rrd.fetch(resolution=60, start=period, end='now')
         
         clockfix = (datetime.datetime.now().hour - datetime.datetime.utcnow().hour) * 3600
         
         series = [((ts + clockfix) * 1000, val) for ts, val in result["data"]]
         
     return json.dumps(series)
示例#6
0
 def fetch(self, start=None, end=None, resolution=None):
     """
     Fetch data from the RRD database.
     """
     rrd = RRD("history/108732.rrd")
     print rrd.fetch(resolution=300, start='-1h', end=self.epoch_now())         
示例#7
0
 def fetch(self, start=None, end=None, resolution=None):
     """
     Fetch data from the RRD database.
     """
     rrd = RRD("history/108732.rrd")
     print rrd.fetch(resolution=300, start='-1h', end=self.epoch_now())
    f.close


def GetRRDImportance(filename):
	'''
		This is the very core of cinderella:
		 - we load one RRD into memory
		 - we build a histogram of its values
		 - we use a histogram to find out whether this is an active bean attribute.
	'''
    if not os.path.isfile(filename):
        print("file not found: %s\n" %filename)
        return (0,0)
    #print filename
    myRRD = RRD(filename, mode="r")
    results = myRRD.fetch()['value']
    validnums=[]
    for value in results:
        if not math.isnan(value[1]):# and (value[1] != 0.0):
            validnums.append(value[1])
    #print len(validnums)
    #print validnums
    if len(validnums) > 0:
        h = histogram(validnums)
        #print h
        count = 0

        for counter in h[0]:
            if counter > 0:
                count = count + 1
        only_growing = 1
示例#9
0
class RRDManip(object):

    def __init__(self, filename, step=None,
                 dataSources=None, roundRobinArchives=None):
        """
        实例化 RRDManip 类对象。

        :param filename: the name of the RRD you to manipulative
        :param dataSources: 相关的 data Source 队列
        :param roundRobinArchives: 相关的 rra 队列
        """
        if not isinstance(dataSources, list) and \
                not isinstance(dataSources, tuple):
            dataSources = [dataSources]
        if not isinstance(roundRobinArchives, list) and \
                not isinstance(roundRobinArchives, tuple):
            roundRobinArchives = [roundRobinArchives]

        self.dataSources = dataSources
        self.roundRobinArchives = roundRobinArchives
        self.filename = filename
        self.step = step
        self.rrd = None

    def ensure_rrd(self):
        """
        Ensures that an RRD file is created.
        """
        if os.path.isfile(self.filename):
            # the rrd file alread exist
            self.rrd = RRD(self.filename)
        else:
            self.create_rrd()

    def create_rrd(self):
        """
        Creates an RRD file.
        """
        dataSources = [DataSource(**ds) for ds in self.dataSources]
        roundRobinArchives = [RRA(**rra) for rra in self.roundRobinArchives]
        # start 时间设定为当前时间的一天前,86400 即一天内包含的秒数
        past_one_day = int(time.time()) - 86400
        self.rrd = RRD(self.filename, start=past_one_day, step=self.step,
                       ds=dataSources, rra=roundRobinArchives)
        self.rrd.create()

    def update(self, timestamp, values):
        """
        Feeds data values into an RRD.
        """
        timestamp = int(timestamp)
        if not isinstance(values, list) and not isinstance(values, tuple):
            values = [values]
        self.rrd.bufferValue(timestamp, *values)
        try:
            self.rrd.update()
        except:
            # 防止 脏数据 污染 update vslues
            self.rrd.values = []

    def fetch(self, cf='AVERAGE', resolution=None, start=None, end=None, returnStyle="ds"):
        """
        Fetch data values from an RRD.

        :param returnStyle: 指定返回的数据格式,包括有'ds' 和 'time'
        """
        return self.rrd.fetch(cf, resolution, start, end, returnStyle)