summary refs log tree commit diff
path: root/synapse/util/metrics.py
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@arasphere.net>2018-07-23 10:03:28 +0100
committerGitHub <noreply@github.com>2018-07-23 10:03:28 +0100
commit9b34f3ea3af233d70412565290468092cf3c5984 (patch)
treedcfc00333a843cdc3a011249ef78f8438804dbd4 /synapse/util/metrics.py
parentadd trailing comma (diff)
parentMake the rest of the .iterwhatever go away (#3562) (diff)
downloadsynapse-9b34f3ea3af233d70412565290468092cf3c5984.tar.xz
Merge branch 'develop' into matthew/sync_deleted_devices
Diffstat (limited to 'synapse/util/metrics.py')
-rw-r--r--synapse/util/metrics.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/synapse/util/metrics.py b/synapse/util/metrics.py
index 6ba7107896..97f1267380 100644
--- a/synapse/util/metrics.py
+++ b/synapse/util/metrics.py
@@ -104,12 +104,19 @@ class Measure(object):
             logger.warn("Expected context. (%r)", self.name)
             return
 
-        usage = context.get_resource_usage() - self.start_usage
-        block_ru_utime.labels(self.name).inc(usage.ru_utime)
-        block_ru_stime.labels(self.name).inc(usage.ru_stime)
-        block_db_txn_count.labels(self.name).inc(usage.db_txn_count)
-        block_db_txn_duration.labels(self.name).inc(usage.db_txn_duration_sec)
-        block_db_sched_duration.labels(self.name).inc(usage.db_sched_duration_sec)
+        current = context.get_resource_usage()
+        usage = current - self.start_usage
+        try:
+            block_ru_utime.labels(self.name).inc(usage.ru_utime)
+            block_ru_stime.labels(self.name).inc(usage.ru_stime)
+            block_db_txn_count.labels(self.name).inc(usage.db_txn_count)
+            block_db_txn_duration.labels(self.name).inc(usage.db_txn_duration_sec)
+            block_db_sched_duration.labels(self.name).inc(usage.db_sched_duration_sec)
+        except ValueError:
+            logger.warn(
+                "Failed to save metrics! OLD: %r, NEW: %r",
+                self.start_usage, current
+            )
 
         if self.created_context:
             self.start_context.__exit__(exc_type, exc_val, exc_tb)