def main(): now = round(datetime.now().timestamp()) oneminago = now - 60 cmd = f'-s {oneminago} -e {now} --step 2 --json DEF:a=db.rrd:Package_id_0:AVERAGE XPORT:a' print(cmd) js = rrdtool.xport('-s', str(oneminago), '-e', str(now), '--step', '2', '--json', 'DEF:a=db.rrd:ssCpuUser:AVERAGE', 'XPORT:a') print(js)
def test_xport(rrd_database, bounds, result): "Test python binding and that direct memory access behaves correctly" qstart, qend = bounds assert (rrdtool.xport([ "DEF:fir=%s:one:AVERAGE" % rrd_database, "XPORT:fir", "-s", str(qstart), "-e", str(qend), ]) == result)
def xport(self): rrd_args = ["--start", self.start_point, "--end", self.end_point] for column in self.list_ds: rrd_args.append("DEF:" + column + "=" + self.file + ":" + column + ":AVERAGE") rrd_args.append("CDEF:cdef_" + column + "=" + column + ",1,*") rrd_args.append("XPORT:" + column + ":\"" + column + "\"") res_xport = rrdtool.xport(rrd_args) return res_xport
def create_file(self): """Flush the rrd_cache if it's necessary, then get the rrd-config, generate the graph(s) and merge them to a single file""" graphs = [] if not self.end or self.end > time.time() - self.__rrd_update_interval: self.flush_rrd_cache() if self.output_format == 'csv': for tmpl_params in self.template.rrd_params: graphs.append(rrdtool.xport(*tmpl_params)) self._file = self.merge_files(graphs) else: for tmpl_params in self.template.rrd_params: graphs.append(rrdtool.graphv('-', *tmpl_params)) self._file = self.merge_files(graphs) if not self._file: PyNPException('No graph was generated')
def get_data(timeFrame): startTime = "now-%s" % timeFrame print startTime jsonData = rrdtool.xport("--start", startTime.encode('ascii', 'ignore'), "--end", "now", "--step", "300", "DEF:a="+dataFile+":cpuTemp:AVERAGE", "DEF:b="+dataFile+":boardTemp:AVERAGE", "DEF:c="+dataFile+":calibTemp:AVERAGE", "DEF:d="+dataFile+":atm:AVERAGE", "DEF:e="+dataFile+":light:AVERAGE", 'XPORT:a:"CPU Temp"', 'XPORT:b:"Board Temp"', 'XPORT:c:"Estimated Temp"', 'XPORT:d:"Atmospheric Pressure"', 'XPORT:e:"Light"') return jsonData
def rrd(file, ds): data = {'max': None, 'avg': None} try: max_data = rrdtool.xport('DEF:%s=%s:%s:LAST' % (ds, file, ds), '-s', '-30d', '-e', 'now', 'XPORT:%s:last' % ds) start_max = max_data['meta']['start'] end_max = max_data['meta']['end'] ds_max = max(max_data['data']) ds_avg = [ int(i[0]) for i in max_data['data'] if i[0] != None if int(i[0]) != 0 ] start_max_stamp = datetime.fromtimestamp(start_max) start_max_time = start_max_stamp.strftime('%Y-%m-%d %H:%M:%S') end_max_stamp = datetime.fromtimestamp(end_max) end_max_time = end_max_stamp.strftime('%Y-%m-%d %H:%M:%S') d_max = {'start': None, 'end': None, 'data': None} d_avg = {'start': None, 'end': None, 'data': None} d_max['start'] = start_max_time d_max['end'] = end_max_time d_max['data'] = int(ds_max[0]) d_avg['start'] = start_max_time d_avg['end'] = end_max_time d_avg['data'] = average(ds_avg) data['max'] = d_max data['avg'] = d_avg return data except Exception as msg: return data, msg
import rrdtool ret = rrdtool.xport ('--start 1355312020', '--end 1355314500', 'DEF:x=./xo_stats/abacus.rrd:active:AVERAGE', 'XPORT:x:"Ativitye active"') if ret: print rrdtool.error() else: print "OK"