def get_counters(cls, format=None): if format == 'json': return db.get_metrics(type='counter') elif format == 'prometheus': counters = list() for c in Counter.get_counters(): counters.append('# HELP alerta_{group}_{name} {description}\n' '# TYPE alerta_{group}_{name} counter\n' 'alerta_{group}_{name}_total {count}\n'.format( group=c.group, name=c.name, description=c.description, count=c.count)) return "".join(counters) else: return db.get_counters()
def get_gauges(cls, format=None): if format == 'json': return db.get_metrics(type='gauge') elif format == 'prometheus': gauges = list() for g in Gauge.get_gauges(): gauges.append('# HELP alerta_{group}_{name} {description}\n' '# TYPE alerta_{group}_{name} gauge\n' 'alerta_{group}_{name} {value}\n'.format( group=g.group, name=g.name, description=g.description, value=g.value)) return "".join(gauges) else: return db.get_gauges()
def get_counters(cls, format=None): if format == 'json': return db.get_metrics(type='counter') elif format == 'prometheus': counters = list() for c in Counter.get_counters(): counters.append( '# HELP alerta_{group}_{name} {description}\n' '# TYPE alerta_{group}_{name} counter\n' 'alerta_{group}_{name}_total {count}\n'.format( group=c.group, name=c.name, description=c.description, count=c.count ) ) return "".join(counters) else: return db.get_counters()
def get_gauges(cls, format=None): if format == 'json': return db.get_metrics(type='gauge') elif format == 'prometheus': gauges = list() for g in Gauge.get_gauges(): gauges.append( '# HELP alerta_{group}_{name} {description}\n' '# TYPE alerta_{group}_{name} gauge\n' 'alerta_{group}_{name} {value}\n'.format( group=g.group, name=g.name, description=g.description, value=g.value ) ) return "".join(gauges) else: return db.get_gauges()
def get_timers(cls, format=None): if format == 'json': return db.get_metrics(type='timer') elif format == 'prometheus': timers = list() for t in Timer.get_timers(): timers.append( '# HELP alerta_{group}_{name} {description}\n' '# TYPE alerta_{group}_{name} summary\n' 'alerta_{group}_{name}_count {count}\n' 'alerta_{group}_{name}_sum {total_time}\n'.format( group=t.group, name=t.name, description=t.description, count=t.count, total_time=t.total_time ) ) return "".join(timers) else: return db.get_timers()
def get_timers(cls, format=None): if format == 'json': return db.get_metrics(type='timer') elif format == 'prometheus': timers = list() for t in Timer.get_timers(): timers.append( '# HELP alerta_{group}_{name} {description}\n' '# TYPE alerta_{group}_{name} summary\n' 'alerta_{group}_{name}_count {count}\n' 'alerta_{group}_{name}_sum {total_time}\n'.format( group=t.group, name=t.name, description=t.description, count=t.count, total_time=t.total_time)) return "".join(timers) else: return db.get_timers()
def find_all(cls): return [Gauge.from_db(gauge) for gauge in db.get_metrics(type='gauge')]
def find_all(cls): return [Timer.from_db(timer) for timer in db.get_metrics(type='timer')]
def find_all(cls): return [ Counter.from_db(counter) for counter in db.get_metrics(type='counter') ]
def find_all(cls): return [Counter.from_db(counter) for counter in db.get_metrics(type='counter')]