Mark Bergsma has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371060 )

Change subject: Add generic monitor metrics
......................................................................

Add generic monitor metrics

pybal_monitor_{up,down}_result_total count the number of up and down
check run results, not transitions
pybal_monitor_status is a gauge that represents whether the monitor
is up or down.

Bug: T171710
Change-Id: I2c28d40019338930ad093c407b85a9c235427723
---
M pybal/metrics.py
M pybal/monitor.py
2 files changed, 14 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/debs/pybal 
refs/changes/60/371060/1

diff --git a/pybal/metrics.py b/pybal/metrics.py
index f44acf5..1178970 100644
--- a/pybal/metrics.py
+++ b/pybal/metrics.py
@@ -21,7 +21,13 @@
     def inc(**kwargs):
         pass
 
+class DummyGauge(DummyMetric):
+    def set(**kwargs):
+        pass
+
 if metrics_implementation == 'prometheus':
     Counter = prometheus_client.Counter
+    Gauge = prometheus_client.Gauge
 else:
     Counter = DummyCounter
+    Gauge = DummyGauge
diff --git a/pybal/monitor.py b/pybal/monitor.py
index d8d187f..96d1ca0 100644
--- a/pybal/monitor.py
+++ b/pybal/monitor.py
@@ -7,7 +7,7 @@
 from twisted.internet import reactor
 from . import util
 import logging
-from pybal.metrics import Counter
+from pybal.metrics import Counter, Gauge
 
 _log = util._log
 
@@ -30,6 +30,9 @@
     metrics = {
         'up_transitions_total': Counter('up_transitions_total', 'Monitor up 
transition count', **metric_keywords),
         'down_transitions_total': Counter('down_transitions_total', 'Monitor 
down transition count', **metric_keywords),
+        'up_result_total': Counter('up_result_total', 'Monitor up result 
count', **metric_keywords),
+        'down_result_total': Counter('down_result_total', 'Monitor down result 
count', **metric_keywords),
+        'status': Gauge('status', 'Monitor up status', **metric_keywords)
     }
 
     def __init__(self, coordinator, server, configuration={}, reactor=reactor):
@@ -70,6 +73,7 @@
         """Sets own monitoring state to Up and notifies the coordinator
         if this implies a state change.
         """
+        self.metrics['up_result_total'].labels(**self.metric_labels).inc()
         if self.active and self.up is False or self.firstCheck:
             self.up = True
             self.firstCheck = False
@@ -77,11 +81,12 @@
                 self.coordinator.resultUp(self)
 
             
self.metrics['up_transitions_total'].labels(**self.metric_labels).inc()
-
+            self.metrics['status'].labels(**self.metric_labels).set(1)
 
     def _resultDown(self, reason=None):
         """Sets own monitoring state to Down and notifies the
         coordinator if this implies a state change."""
+        self.metrics['down_result_total'].labels(**self.metric_labels).inc()
         if self.active and self.up is True or self.firstCheck:
             self.up = False
             self.firstCheck = False
@@ -89,6 +94,7 @@
                 self.coordinator.resultDown(self, reason)
 
             
self.metrics['down_transitions_total'].labels(**self.metric_labels).inc()
+            self.metrics['status'].labels(**self.metric_labels).set(0)
 
     def report(self, text, level=logging.DEBUG):
         """Common method for reporting/logging check results."""

-- 
To view, visit https://gerrit.wikimedia.org/r/371060
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2c28d40019338930ad093c407b85a9c235427723
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: master
Gerrit-Owner: Mark Bergsma <m...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to