# HG changeset patch # User drewp@bigasterisk.com # Date 1569459363 25200 # Node ID f4e06baaad567a2162e514b50dc8280ab7ef6148 # Parent 013e2a89b345f24eeec68f65ee0edb9ec8647f2f whitespace and doc Ignore-this: 51023da4821300d28020696e0b145db5 diff -r 013e2a89b345 -r f4e06baaad56 lib/export_to_influxdb/export_to_influxdb.py --- a/lib/export_to_influxdb/export_to_influxdb.py Wed Sep 25 17:36:44 2019 -0700 +++ b/lib/export_to_influxdb/export_to_influxdb.py Wed Sep 25 17:56:03 2019 -0700 @@ -19,7 +19,7 @@ replication='1') self.createdPolicies.add(days) return name - + class InfluxExporter(object): def __init__(self, configGraph, influxHost='bang6'): self.graph = configGraph @@ -68,13 +68,24 @@ log.info('writing stats to %r', points) self.lastExport = now #print('send %r' % points) - + task.LoopingCall(send).start(period_secs, now=False) - + def exportToInflux(self, currentStatements): + """ + looks for + + ?subj ?p ?value; + :influxMeasurement [ + :measurement ?name; + :predicate ?p; + :tag [:key ?k; :value ?v], ... + ] + + """ graph = self.graph now = int(time.time()) - + points = [] for stmt in currentStatements: if (stmt[0], stmt[1]) in self.measurements: @@ -89,11 +100,11 @@ pale = 3600 if graph.value(meas, ROOM['pointsAtLeastEvery'], default=None): pale = graph.value(meas, ROOM['pointsAtLeastEvery']).toPython() - + if not self.shouldSendNewPoint(now, stmt[0], measurementName, tags, value, pointsAtLeastEvery=pale): continue - + points.append({ 'measurement': measurementName, "tags": tags, @@ -114,7 +125,7 @@ if not isinstance(value, (int, float)): raise NotImplementedError('value=%r' % value) return value - + def shouldSendNewPoint(self, now, subj, measurementName, tags, value, pointsAtLeastEvery): key = (subj, measurementName, tuple(sorted(tags.items()))) if key in self.lastSent: