These metrics were [removed completely from the codebase](444bc56cda/docs/changelogs/CHANGES-2022.md (synapse-1730-2022-12-06)) in Synapse v1.73.0 (2022-12-06). 3-years is plenty enough time ⏩ The deprecation/removal is still in our [upgrade notes](444bc56cda/docs/upgrade.md (deprecation-of-legacy-prometheus-metric-names)) which points to a durable versioned link with the info still available: https://element-hq.github.io/synapse/v1.69/metrics-howto.html#renaming-of-metrics--deprecation-of-old-names-in-12
4.4 KiB
How to monitor Synapse metrics using Prometheus
-
Install Prometheus:
Follow instructions at http://prometheus.io/docs/introduction/install/
-
Enable Synapse metrics:
In
homeserver.yaml, make sureenable_metricsis set toTrue. -
Enable the
/_synapse/metricsSynapse endpoint that Prometheus uses to collect data:There are two methods of enabling the metrics endpoint in Synapse.
The first serves the metrics as a part of the usual web server and can be enabled by adding the
metricsresource to the existing listener as such as in this example:listeners: - port: 8008 tls: false type: http x_forwarded: true bind_addresses: ['::1', '127.0.0.1'] resources: # added "metrics" in this line - names: [client, federation, metrics] compress: falseThis provides a simple way of adding metrics to your Synapse installation, and serves under
/_synapse/metrics. If you do not wish your metrics be publicly exposed, you will need to either filter it out at your load balancer, or use the second method.The second method runs the metrics server on a different port, in a different thread to Synapse. This can make it more resilient to heavy load meaning metrics cannot be retrieved, and can be exposed to just internal networks easier. The served metrics are available over HTTP only, and will be available at
/_synapse/metrics.Add a new listener to homeserver.yaml as in this example:
listeners: - port: 8008 tls: false type: http x_forwarded: true bind_addresses: ['::1', '127.0.0.1'] resources: - names: [client, federation] compress: false # beginning of the new metrics listener - port: 9000 type: metrics bind_addresses: ['::1', '127.0.0.1'] -
Restart Synapse.
-
Add a Prometheus target for Synapse.
It needs to set the
metrics_pathto a non-default value (underscrape_configs):- job_name: "synapse" scrape_interval: 15s metrics_path: "/_synapse/metrics" static_configs: - targets: ["my.server.here:port"]where
my.server.hereis the IP address of Synapse, andportis the listener port configured with themetricsresource.If your prometheus is older than 1.5.2, you will need to replace
static_configsin the above withtarget_groups. -
Restart Prometheus.
-
Consider using the grafana dashboard and required recording rules
Monitoring workers
To monitor a Synapse installation using workers, every worker needs to be monitored independently, in addition to the main homeserver process. This is because workers don't send their metrics to the main homeserver process, but expose them directly (if they are configured to do so).
To allow collecting metrics from a worker, you need to add a
metrics listener to its configuration, by adding the following
under worker_listeners:
- type: metrics
bind_address: ''
port: 9101
The bind_address and port parameters should be set so that
the resulting listener can be reached by prometheus, and they
don't clash with an existing worker.
With this example, the worker's metrics would then be available
on http://127.0.0.1:9101.
Example Prometheus target for Synapse with workers:
- job_name: "synapse"
scrape_interval: 15s
metrics_path: "/_synapse/metrics"
static_configs:
- targets: ["my.server.here:port"]
labels:
instance: "my.server"
job: "master"
index: 1
- targets: ["my.workerserver.here:port"]
labels:
instance: "my.server"
job: "generic_worker"
index: 1
- targets: ["my.workerserver.here:port"]
labels:
instance: "my.server"
job: "generic_worker"
index: 2
- targets: ["my.workerserver.here:port"]
labels:
instance: "my.server"
job: "media_repository"
index: 1
Labels (instance, job, index) can be defined as anything.
The labels are used to group graphs in grafana.