element-synapse/docs/metrics-howto.md
Eric Eastwood ace2614fad
Remove docs on dead legacy metric names (#19341)
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
2026-01-08 10:03:15 -06:00

4.4 KiB

How to monitor Synapse metrics using Prometheus

  1. Install Prometheus:

    Follow instructions at http://prometheus.io/docs/introduction/install/

  2. Enable Synapse metrics:

    In homeserver.yaml, make sure enable_metrics is set to True.

  3. Enable the /_synapse/metrics Synapse 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 metrics resource 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: false
    

    This 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']
    
  4. Restart Synapse.

  5. Add a Prometheus target for Synapse.

    It needs to set the metrics_path to a non-default value (under scrape_configs):

      - job_name: "synapse"
        scrape_interval: 15s
        metrics_path: "/_synapse/metrics"
        static_configs:
          - targets: ["my.server.here:port"]
    

    where my.server.here is the IP address of Synapse, and port is the listener port configured with the metrics resource.

    If your prometheus is older than 1.5.2, you will need to replace static_configs in the above with target_groups.

  6. Restart Prometheus.

  7. 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.