separate metric for direct aprs messages
This commit is contained in:
parent
4a8e9472ab
commit
6c70e19c63
36
owrx/aprs.py
36
owrx/aprs.py
@ -33,6 +33,9 @@ thirdpartyeRegex = re.compile("^([a-zA-Z0-9-]+)>((([a-zA-Z0-9-]+\\*?,)*)([a-zA-Z
|
|||||||
# regex for getting the message id out of message
|
# regex for getting the message id out of message
|
||||||
messageIdRegex = re.compile("^(.*){([0-9]{1,5})$")
|
messageIdRegex = re.compile("^(.*){([0-9]{1,5})$")
|
||||||
|
|
||||||
|
# regex to filter pseudo "WIDE" path elements
|
||||||
|
widePattern = re.compile("^WIDE[0-9]-[0-9]$")
|
||||||
|
|
||||||
|
|
||||||
def decodeBase91(input):
|
def decodeBase91(input):
|
||||||
base = decodeBase91(input[:-1]) * 91 if len(input) > 1 else 0
|
base = decodeBase91(input[:-1]) * 91 if len(input) > 1 else 0
|
||||||
@ -154,24 +157,33 @@ class AprsParser(Parser):
|
|||||||
super().__init__(handler)
|
super().__init__(handler)
|
||||||
self.ax25parser = Ax25Parser()
|
self.ax25parser = Ax25Parser()
|
||||||
self.deframer = KissDeframer()
|
self.deframer = KissDeframer()
|
||||||
self.metric = None
|
self.metrics = {}
|
||||||
|
|
||||||
def setDialFrequency(self, freq):
|
def setDialFrequency(self, freq):
|
||||||
super().setDialFrequency(freq)
|
super().setDialFrequency(freq)
|
||||||
self.metric = None
|
self.metrics = {}
|
||||||
|
|
||||||
def getMetric(self):
|
def getMetric(self, category):
|
||||||
if self.metric is None:
|
if category not in self.metrics:
|
||||||
band = "unknown"
|
band = "unknown"
|
||||||
if self.band is not None:
|
if self.band is not None:
|
||||||
band = self.band.getName()
|
band = self.band.getName()
|
||||||
name = "aprs.decodes.{band}.aprs".format(band=band)
|
name = "aprs.decodes.{band}.aprs.{category}".format(band=band, category=category)
|
||||||
metrics = Metrics.getSharedInstance()
|
metrics = Metrics.getSharedInstance()
|
||||||
self.metric = metrics.getMetric(name)
|
self.metrics[category] = metrics.getMetric(name)
|
||||||
if self.metric is None:
|
if self.metrics[category] is None:
|
||||||
self.metric = CounterMetric()
|
self.metrics[category] = CounterMetric()
|
||||||
metrics.addMetric(name, self.metric)
|
metrics.addMetric(name, self.metrics[category])
|
||||||
return self.metric
|
return self.metrics[category]
|
||||||
|
|
||||||
|
def isDirect(self, aprsData):
|
||||||
|
if "path" in aprsData and len(aprsData["path"]) > 0:
|
||||||
|
hops = [host for host in aprsData["path"] if widePattern.match(host) is None]
|
||||||
|
if len(hops) > 0:
|
||||||
|
return False
|
||||||
|
if "type" in aprsData and aprsData["type"] in ["thirdparty", "item", "object"]:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def parse(self, raw):
|
def parse(self, raw):
|
||||||
for frame in self.deframer.parse(raw):
|
for frame in self.deframer.parse(raw):
|
||||||
@ -183,7 +195,9 @@ class AprsParser(Parser):
|
|||||||
|
|
||||||
logger.debug("decoded APRS data: %s", aprsData)
|
logger.debug("decoded APRS data: %s", aprsData)
|
||||||
self.updateMap(aprsData)
|
self.updateMap(aprsData)
|
||||||
self.getMetric().inc()
|
self.getMetric("total").inc()
|
||||||
|
if self.isDirect(aprsData):
|
||||||
|
self.getMetric("direct").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