create metric dynamically
This commit is contained in:
parent
5d4f3b8d90
commit
4a8e9472ab
27
owrx/aprs.py
27
owrx/aprs.py
@ -154,23 +154,24 @@ class AprsParser(Parser):
|
|||||||
super().__init__(handler)
|
super().__init__(handler)
|
||||||
self.ax25parser = Ax25Parser()
|
self.ax25parser = Ax25Parser()
|
||||||
self.deframer = KissDeframer()
|
self.deframer = KissDeframer()
|
||||||
self.metric = self.getMetric()
|
self.metric = None
|
||||||
|
|
||||||
def setDialFrequency(self, freq):
|
def setDialFrequency(self, freq):
|
||||||
super().setDialFrequency(freq)
|
super().setDialFrequency(freq)
|
||||||
self.metric = self.getMetric()
|
self.metric = None
|
||||||
|
|
||||||
def getMetric(self):
|
def getMetric(self):
|
||||||
band = "unknown"
|
if self.metric is None:
|
||||||
if self.band is not None:
|
band = "unknown"
|
||||||
band = self.band.getName()
|
if self.band is not None:
|
||||||
name = "aprs.decodes.{band}.aprs".format(band=band)
|
band = self.band.getName()
|
||||||
metrics = Metrics.getSharedInstance()
|
name = "aprs.decodes.{band}.aprs".format(band=band)
|
||||||
metric = metrics.getMetric(name)
|
metrics = Metrics.getSharedInstance()
|
||||||
if metric is None:
|
self.metric = metrics.getMetric(name)
|
||||||
metric = CounterMetric()
|
if self.metric is None:
|
||||||
metrics.addMetric(name, metric)
|
self.metric = CounterMetric()
|
||||||
return metric
|
metrics.addMetric(name, self.metric)
|
||||||
|
return self.metric
|
||||||
|
|
||||||
def parse(self, raw):
|
def parse(self, raw):
|
||||||
for frame in self.deframer.parse(raw):
|
for frame in self.deframer.parse(raw):
|
||||||
@ -182,7 +183,7 @@ class AprsParser(Parser):
|
|||||||
|
|
||||||
logger.debug("decoded APRS data: %s", aprsData)
|
logger.debug("decoded APRS data: %s", aprsData)
|
||||||
self.updateMap(aprsData)
|
self.updateMap(aprsData)
|
||||||
self.metric.inc()
|
self.getMetric().inc()
|
||||||
self.handler.write_aprs_data(aprsData)
|
self.handler.write_aprs_data(aprsData)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("exception while parsing aprs data")
|
logger.exception("exception while parsing aprs data")
|
||||||
|
Loading…
Reference in New Issue
Block a user