Ema has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/371061 )

Change subject: Add monitoring specific metric to ProxyFetch
......................................................................


Add monitoring specific metric to ProxyFetch

pybal_monitor_proxyfetch_request_duration_seconds is a gauge that
represents the request latency, differentiated by the 'result' label
(successful/failed).

Bug: T171710
Change-Id: I18fc7bdc679d5c339487d2d87c515d1254d37d4b
---
M pybal/monitors/proxyfetch.py
1 file changed, 29 insertions(+), 2 deletions(-)

Approvals:
  Ema: Verified; Looks good to me, approved



diff --git a/pybal/monitors/proxyfetch.py b/pybal/monitors/proxyfetch.py
index 3468e73..74187a5 100644
--- a/pybal/monitors/proxyfetch.py
+++ b/pybal/monitors/proxyfetch.py
@@ -6,6 +6,7 @@
 """
 
 from pybal import monitor, util
+from pybal.metrics import Gauge
 
 from twisted.internet import reactor, defer
 from twisted.web import client
@@ -49,6 +50,20 @@
     from twisted.internet import error
     from twisted.web import error as weberror
     catchList = ( defer.TimeoutError, weberror.Error, error.ConnectError, 
error.DNSLookupError )
+
+    metric_labelnames = ('service', 'host', 'monitor')
+    metric_keywords = {
+        'namespace': 'pybal',
+        'subsystem': 'monitor_' + __name__.lower()
+    }
+
+    proxyfetch_metrics = {
+        'request_duration_seconds': Gauge(
+            'request_duration_seconds',
+            'HTTP(S) request duration',
+            labelnames=metric_labelnames + ('result',), # TODO: statuscode
+            **metric_keywords)
+    }
 
     def __init__(self, coordinator, server, configuration={}):
         """Constructor"""
@@ -115,8 +130,14 @@
     def _fetchSuccessful(self, result):
         """Called when getProxyPage is finished successfully."""
 
-        self.report('Fetch successful, %.3f s' % (seconds() - 
self.checkStartTime))
+        duration = seconds() - self.checkStartTime
+        self.report('Fetch successful, %.3f s' % (duration))
         self._resultUp()
+
+        self.proxyfetch_metrics['request_duration_seconds'].labels(
+            result='successful',
+            **self.metric_labels
+            ).set(duration)
 
         return result
 
@@ -127,11 +148,17 @@
         if failure.check(defer.CancelledError):
             return None
 
-        self.report('Fetch failed, %.3f s' % (seconds() - self.checkStartTime),
+        duration = seconds() - self.checkStartTime
+        self.report('Fetch failed, %.3f s' % (duration),
                     level=logging.WARN)
 
         self._resultDown(failure.getErrorMessage())
 
+        self.proxyfetch_metrics['request_duration_seconds'].labels(
+            result='failed',
+            **self.metric_labels
+            ).set(duration)
+
         failure.trap(*self.catchList)
 
     def _checkFinished(self, result):

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I18fc7bdc679d5c339487d2d87c515d1254d37d4b
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: 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