Ema has submitted this change and it was merged. ( 
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(-)

Approvals:
  Ema: Verified; Looks good to me, approved
  Mark Bergsma: Looks good to me, but someone else must approve



diff --git a/pybal/metrics.py b/pybal/metrics.py
index fb740e5..4ccb064 100644
--- a/pybal/metrics.py
+++ b/pybal/metrics.py
@@ -21,7 +21,13 @@
     def inc(self, **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..5d3e5e8 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_results_total': Counter('up_results_total', 'Monitor up result 
count', **metric_keywords),
+        'down_results_total': Counter('down_results_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_results_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_results_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: merged
Gerrit-Change-Id: I2c28d40019338930ad093c407b85a9c235427723
Gerrit-PatchSet: 4
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: master
Gerrit-Owner: Mark Bergsma <m...@wikimedia.org>
Gerrit-Reviewer: Ema <e...@wikimedia.org>
Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org>
Gerrit-Reviewer: Mark Bergsma <m...@wikimedia.org>
Gerrit-Reviewer: Volans <rcocci...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to