simple metrics api to interface with collectd and grafana
This commit is contained in:
32
owrx/metrics.py
Normal file
32
owrx/metrics.py
Normal file
@ -0,0 +1,32 @@
|
||||
class Metrics(object):
|
||||
sharedInstance = None
|
||||
|
||||
@staticmethod
|
||||
def getSharedInstance():
|
||||
if Metrics.sharedInstance is None:
|
||||
Metrics.sharedInstance = Metrics()
|
||||
return Metrics.sharedInstance
|
||||
|
||||
def __init__(self):
|
||||
self.metrics = {}
|
||||
|
||||
def pushDecodes(self, band, mode, count = 1):
|
||||
if band is None:
|
||||
band = 'unknown'
|
||||
else:
|
||||
band = band.getName()
|
||||
|
||||
if mode is None:
|
||||
mode = 'unknown'
|
||||
|
||||
if not band in self.metrics:
|
||||
self.metrics[band] = {}
|
||||
if not mode in self.metrics[band]:
|
||||
self.metrics[band][mode] = {
|
||||
"count": 0
|
||||
}
|
||||
|
||||
self.metrics[band][mode]["count"] += count
|
||||
|
||||
def getMetrics(self):
|
||||
return self.metrics
|
Reference in New Issue
Block a user