Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add a build info metric to Prometheus (#6005)
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Feb 25, 2020
2 parents f7ae2c7 + aeb9b21 commit 0a3f3e3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/6005.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The new Prometheus metric `synapse_build_info` exposes the Python version, OS version, and Synapse version of the running server.
12 changes: 12 additions & 0 deletions synapse/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@

from twisted.internet import reactor

import synapse
from synapse.metrics._exposition import (
MetricsResource,
generate_latest,
start_http_server,
)
from synapse.util.versionstring import get_version_string

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -385,6 +387,16 @@ def collect(self):
# finished being processed.
event_processing_lag = Gauge("synapse_event_processing_lag", "", ["name"])

# Build info of the running server.
build_info = Gauge(
"synapse_build_info", "Build information", ["pythonversion", "version", "osversion"]
)
build_info.labels(
" ".join([platform.python_implementation(), platform.python_version()]),
get_version_string(synapse),
" ".join([platform.system(), platform.release()]),
).set(1)

last_ticked = time.time()


Expand Down
22 changes: 20 additions & 2 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2018 New Vector Ltd
# Copyright 2019 Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,8 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.


from synapse.metrics import InFlightGauge
from synapse.metrics import REGISTRY, InFlightGauge, generate_latest

from tests import unittest

Expand Down Expand Up @@ -111,3 +111,21 @@ def get_metrics_from_gauge(self, gauge):
}

return results


class BuildInfoTests(unittest.TestCase):
def test_get_build(self):
"""
The synapse_build_info metric reports the OS version, Python version,
and Synapse version.
"""
items = list(
filter(
lambda x: b"synapse_build_info{" in x,
generate_latest(REGISTRY).split(b"\n"),
)
)
self.assertEqual(len(items), 1)
self.assertTrue(b"osversion=" in items[0])
self.assertTrue(b"pythonversion=" in items[0])
self.assertTrue(b"version=" in items[0])

0 comments on commit 0a3f3e3

Please sign in to comment.