FR: Metrics exporting #811

Closed
opened 2025-04-30 17:49:01 +00:00 by Jade · 13 comments
Owner

note we can't leave /metrics on by default as many people expose all routes on their continuwuity deployment

note we can't leave /metrics on by default as many people expose all routes on their continuwuity deployment
Contributor

I guess there's potentially an option to open a second listener for metrics, so it can run in a separate thread on a different port? That would add complexity, but would replicate one of the (unintentionally?) useful features of the multiple listeners in Synapse.

I guess there's potentially an option to open a second listener for metrics, so it can run in a separate thread on a different port? That would add complexity, but would replicate one of the (unintentionally?) useful features of the multiple listeners in Synapse.
Author
Owner

Yeah, this and HTML web interface ones are the ones I'd like people to be able to put on separate interfaces, although at that point, it makes sense to separate federation endpoints, too. The challenge is giving that flexibility without introducing a bunch of complexity in configuration.

Yeah, this and HTML web interface ones are the ones I'd like people to be able to put on separate interfaces, although at that point, it makes sense to separate federation endpoints, too. The challenge is giving that flexibility without introducing a bunch of complexity in configuration.
Contributor

I think separating client and federation mainly risks complicating reverse proxy setup, which at the moment is one of our strengths - people coming from Synapse are often amazed at the simplicity of just forwarding everything to one port.

That said, it wouldn't be terribly difficult to provide example config for all the major reverse proxies to show how to handle the metrics endpoint securely, so maybe it would be easier overall to just keep everything on one port? 🤔

I think separating client and federation mainly risks complicating reverse proxy setup, which at the moment is one of our strengths - people coming from Synapse are often amazed at the simplicity of just forwarding everything to one port. That said, it wouldn't be terribly difficult to provide example config for all the major reverse proxies to show how to handle the metrics endpoint securely, so maybe it would be easier overall to just keep everything on one port? 🤔
Author
Owner

Yeah the simplest default situation is to have everything on one port under matrix.sub and have sub/.well_know/matrix forwarded to matrix.sub, and then have the reverse proxy block /metrics. The challenge is when people want to start putting the HTML auth pages under a different domain. I guess that probably counts as an extra feature that's not needed for the initial implementation though.

Yeah the simplest default situation is to have everything on one port under matrix.sub and have sub/.well_know/matrix forwarded to matrix.sub, and then have the reverse proxy block /metrics. The challenge is when people want to start putting the HTML auth pages under a different domain. I guess that probably counts as an extra feature that's not needed for the initial implementation though.

what about making the metrics endpoint restrict requests to local connections only?

what about making the metrics endpoint restrict requests to local connections only?
Author
Owner

what about making the metrics endpoint restrict requests to local connections only?

I guess that would be possible, but it opens the doors to issues with misconfiguration or spoofing if we allow reading the IP from a header for reverse proxies.

We could also allow configuring basic authentication, as most Prometheus implementations support that

> what about making the metrics endpoint restrict requests to local connections only? I guess that would be possible, but it opens the doors to issues with misconfiguration or spoofing if we allow reading the IP from a header for reverse proxies. We could also allow configuring basic authentication, as most Prometheus implementations support that
Member

I’d like to suggest another pathway for exporting metrics: OpenTelemetry. Basically, since c10y already has some investment in it by way of allowing homeserver admins to send traces to an arbitrary OTLP-compliant receiver (as of v0.5.1, this includes both HTTP and gRPC), I think that simply sending metrics over the same “pipe” would both:

  • economize dependency use (I think we could get away with this using the same selection of crates from this list that are already being used for traces); and
  • simplify at least some observability pipelines where OTel collectors are already in use (e.g., wouldn’t need to add a Prometheus scrape config to my agent just to grab metrics in addition to traces)

However, as Jade notes here, this might not work out as well for setups where services write logs/metrics/traces directly to specific (different) backends.

I’d like to suggest another pathway for exporting metrics: OpenTelemetry. Basically, since c10y already has some investment in it by way of allowing homeserver admins to send traces to an arbitrary OTLP-compliant receiver (as of v0.5.1, this includes both HTTP *and* gRPC), I think that simply sending metrics over the same “pipe” would both: - economize dependency use (I *think* we could get away with this using the same selection of crates from [this list](https://github.com/open-telemetry/opentelemetry-rust?tab=readme-ov-file#overview-of-crates) that are already being used for traces); and - simplify at least some observability pipelines where OTel collectors are already in use (e.g., wouldn’t need to add a Prometheus scrape config to my agent just to grab metrics in addition to traces) However, as Jade notes [here](https://matrix.to/#/!ksTlboXVgcyWjv5GrlEeKyQuJ8ZCprnwQx2b6-BQ44Q/$BLmtI7NcYpfbzAO_KkqathGvaQW_lWTvIO8NZ6KnBOk?via=nexy7574.co.uk&via=continuwuity.org&via=envs.net), this might not work out as well for setups where services write logs/metrics/traces directly to specific (different) backends.
Member

I'm thinking of working on this, what kinda metrics can people imagine they'd like to have? Off the top of my head i can imagine:

  • users in db (remote and local as separate labels}
  • events/pdus being processed + how many in backlog
  • http requests handled since startup (based on path, e.g. for sync, federation, media, etc)
    • related: media uploaded and downloaded (bytes and count)
  • uptime?
  • memory and cpu usage?
  • db size?
  • media stored (remote, local)
  • federation lag?
    • unsure how this would be tracked, but could be useful to have

From asking in offtopic:

  • in-flight requests
  • busy threads
  • accepted/rejected requests (split out with rejection reason if possible)
  • stuff on spam filtering
  • "well, I'd like to see user actions (e.g., outgoing invites; inbound invites, ect), but resource-related stuff should be done first, like anything media-related, download and upload for examples"
  • "i'd like to have the types of edus/pdus handled"

Other examples and ideas:

I'm thinking of working on this, what kinda metrics can people imagine they'd like to have? Off the top of my head i can imagine: - users in db (remote and local as separate labels} - events/pdus being processed + how many in backlog - http requests handled since startup (based on path, e.g. for sync, federation, media, etc) - related: media uploaded and downloaded (bytes and count) - uptime? - memory and cpu usage? - db size? - media stored (remote, local) - federation lag? - unsure how this would be tracked, but could be useful to have From asking in offtopic: - in-flight requests - busy threads - accepted/rejected requests (split out with rejection reason if possible) - stuff on spam filtering - "well, I'd like to see user actions (e.g., outgoing invites; inbound invites, ect), but resource-related stuff should be done first, like anything media-related, download and upload for examples" - "i'd like to have the types of edus/pdus handled" Other examples and ideas: - https://matrix.to/#/!c10y-fNiMx5ijtgGFibzPUfNs9hpQvnJYPTV-fD2KPk/%24Kxf_loQH8SBpUqnxm9zZvBJAlovDqDaWXMkIk2mVqHU?via=wolfgirl.pet&via=explodie.org&via=matrix.org - https://element-hq.github.io/synapse/latest/usage/administration/understanding_synapse_through_grafana_graphs.html
Author
Owner

If jemalloc metrics are enabled, those should probably be exported too.

If jemalloc metrics are enabled, those should probably be exported too.
Member

Thinking a bit loud about possible implementation: Creating a new metrics service (if one doesnt exist already) used for responding to metric requests. Other services can add hooks for their own metrics when called, and otherwise increment counters in the metric service itself? Unsure about exact implementation there.

For when a request comes in to get metrics (on the /metrics endpoint) I imagine the service uses the hooks to gather metrics from the other services instead of doing all that collection itself? And then returns whatever data was collected.

If whatever frameworks we use implement some sort of metrics i might hook into that, otherwise I'll use something like the prometheus crate.

Thoughts?


Afterthought: An advantage of the above method could be that any missing or problematic services wouldn't take down the rest of the services, as they simply wouldn't add the hooks (or they would error immediately) instead of a potential service trying to get data itself and failing and crashing the rest of the metric collector

Thinking a bit loud about possible implementation: Creating a new `metrics` service (if one doesnt exist already) used for responding to metric requests. Other services can add hooks for their own metrics when called, and otherwise increment counters in the metric service itself? Unsure about exact implementation there. For when a request comes in to get metrics (on the `/metrics` endpoint) I imagine the service uses the hooks to gather metrics from the other services instead of doing all that collection itself? And then returns whatever data was collected. If whatever frameworks we use implement some sort of metrics i might hook into that, otherwise I'll use something like the [`prometheus`](https://docs.rs/prometheus/latest/prometheus/) crate. Thoughts? --- Afterthought: An advantage of the above method could be that any missing or problematic services wouldn't take down the rest of the services, as they simply wouldn't add the hooks (or they would error immediately) instead of a potential service trying to get data itself and failing and crashing the rest of the metric collector
Member

Summing up some conversation from the dev room today (starting around here) for posterity:

Tools

Two main pathways here:

  • OpenTelemetry aka OTel:
    • Pros: no new crate dependencies (heck, the metrics feature is already enabled), lets metrics go over the same "pipe" as traces (see some prior points I raised here); the opentelemetry_otlp crate docs already include an example of handling metrics within the crate, and the OTel Rust monorepo has some examples of metrics handling under the metrics-* directories; OTel is a CNCF graduated project and enjoys considerable adoption & contribution throughout the o11y ecosystem/industry as an agnostic standard under the auspices of the CNCF & thus the Linux Foundation - as such, OTel should be expected to stick around for quite a while. Users have plenty of options, open source and proprietary alike, for where to send & store OTel traces/metrics.
    • Cons: Not as familiar to handle for those used to the traditional scrape-based Prometheus experience, who aren't familiar with OTLP in general, or who already send logs/traces/metrics to separate destinations. (These shouldn't be tough to surpass: the opentelemetry_otlp crate docs correctly note that Prometheus natively accepts OTLP metrics, and deployers who wish to send their metrics to one store and traces to another could trivially do this using tools like Alloy, Vector, or even the vanilla OpenTelemetry Collector. I've previously shared a trivial example of a Vector config meeting approximately this use case.)
  • Prometheus exposure under a /metrics endpoint somewhere: This might be doable with the opentelemetry_prometheus crate.
    • Pros: Bog standard for those used to the traditional scrape-based Prometheus experience (even those who prefer OTLP for their o11y pipelines tend to have ways to capture metrics from endpoints like these).
    • Cons: Crate support for this in the Rust ecosystem has been flaky in the past - for example, the prometheus crate hasn't seen updates in over a year, and opentelemetry_prometheus actually went dormant for a while because of this. Recently, it was brought back to life after someone contributed an implementation without dependencies on the prometheus crate, but it's unclear how long that will stick around for. In addition, it is not yet clear from this thread where c10y would actually place the metrics endpoint and how it would choose to make them available (though I'll add that, as Jade noted, it's a decently common practice to simply make the /metrics endpoint reachable as much as worldwide but simply slap basic auth or other auth methods on the endpoint).

I currently maintain that of these, OpenTelemetry by OTLP would be the better choice, as it has stabler maintenance and o11y-community-wide uptake. However, as alluded to in the cons I wrote for Prometheus, I could ultimately make something work either way.

What to expose

  • Discussed today:
    • Histograms of transaction processing times, inbound and outbound (Jade)
    • [P|E]DUs queued/sent/failed (Jade)
    • Inbound/outbound transaction rate (Nex)
    • [P|E]DU handle time (Nex)
  • Previously raised by @s1lv3r above, curated today with an eye on keeping cardinality low:
    • Uptime
    • Memory/CPU usage
    • DB size, perhaps
    • Accepted/rejected requests w/ rejection reasons (as long as the list of possible rejection reasons is short, to keep cardinality low in turn)
  • Others previously raised:
    • jemalloc if metrics are available (Jade)

References

Linked by s1lv3r earlier in this issue:
https://matrix.to/#/!c10y-fNiMx5ijtgGFibzPUfNs9hpQvnJYPTV-fD2KPk/%24Kxf_loQH8SBpUqnxm9zZvBJAlovDqDaWXMkIk2mVqHU?via=wolfgirl.pet&via=explodie.org&via=matrix.org
https://element-hq.github.io/synapse/latest/usage/administration/understanding_synapse_through_grafana_graphs.html

Others from today (h/t Nex):
https://grafana.i-am.nexus/public-dashboards/30de2946878045a796e8777691f3dd01
...which is in turn derived from: https://demo.thefifthfleet.net/metrics

Summing up some conversation from the dev room today (starting around [here](matrix:roomid/ksTlboXVgcyWjv5GrlEeKyQuJ8ZCprnwQx2b6-BQ44Q/e/zPtzQCGmKclfhKMaiG8WlqeAzhdNIjaJ02VDwuVq24Y?via=julian45.net&via=explodie.org&via=matrix.org)) for posterity: ### Tools Two main pathways here: - OpenTelemetry aka OTel: - Pros: no new crate dependencies (heck, the metrics feature is [already enabled](https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/Cargo.toml#L421)), lets metrics go over the same "pipe" as traces (see some prior points I raised [here](https://forgejo.ellis.link/continuwuation/continuwuity/issues/811#issuecomment-22514)); the opentelemetry_otlp crate docs already include [an example](https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/#using-with-prometheus) of handling metrics within the crate, and the OTel Rust monorepo has [some examples](https://github.com/open-telemetry/opentelemetry-rust/tree/main/examples) of metrics handling under the `metrics-*` directories; OTel is a CNCF graduated project and enjoys considerable adoption & contribution throughout the o11y ecosystem/industry as an agnostic standard under the auspices of the CNCF & thus the Linux Foundation - as such, OTel should be expected to stick around for quite a while. Users have plenty of options, open source and proprietary alike, for where to send & store OTel traces/metrics. - Cons: Not as familiar to handle for those used to the traditional scrape-based Prometheus experience, who aren't familiar with OTLP in general, or who already send logs/traces/metrics to separate destinations. (These shouldn't be tough to surpass: the opentelemetry_otlp crate docs correctly note that Prometheus natively accepts OTLP metrics, and deployers who wish to send their metrics to one store and traces to another could trivially do this using tools like [Alloy](https://grafana.com/docs/alloy/latest/), [Vector](https://vector.dev/), or even the [vanilla OpenTelemetry Collector](https://opentelemetry.io/docs/collector/). I've previously shared [a trivial example of a Vector config meeting approximately this use case](matrix:roomid/ksTlboXVgcyWjv5GrlEeKyQuJ8ZCprnwQx2b6-BQ44Q/e/oFqjOwJGoeRc-R__G_wSl3EKtg4diVwjkmBNv9sMGgI?via=julian45.net&via=explodie.org&via=continuwuity.org).) - Prometheus exposure under a `/metrics` endpoint somewhere: This might be doable with the [opentelemetry_prometheus crate](https://docs.rs/opentelemetry-prometheus/0.32.0/opentelemetry_prometheus/). - Pros: Bog standard for those used to the traditional scrape-based Prometheus experience (even those who prefer OTLP for their o11y pipelines tend to have ways to capture metrics from endpoints like these). - Cons: Crate support for this in the Rust ecosystem has been flaky in the past - for example, the prometheus crate hasn't seen updates in over a year, and opentelemetry_prometheus actually went dormant for a while because of this. Recently, it was brought back to life after someone contributed an implementation without dependencies on the prometheus crate, but it's unclear how long that will stick around for. In addition, it is not yet clear from this thread where c10y would actually place the metrics endpoint and how it would choose to make them available (though I'll add that, as Jade noted, it's a decently common practice to simply make the /metrics endpoint reachable as much as worldwide but simply slap basic auth or other auth methods on the endpoint). I currently maintain that _of these, OpenTelemetry by OTLP would be the better choice_, as it has stabler maintenance and o11y-community-wide uptake. However, as alluded to in the cons I wrote for Prometheus, I could ultimately make something work either way. ### What to expose - Discussed today: - Histograms of transaction processing times, inbound and outbound (Jade) - [P|E]DUs queued/sent/failed (Jade) - Inbound/outbound transaction rate (Nex) - [P|E]DU handle time (Nex) - Previously raised by @s1lv3r [above](https://forgejo.ellis.link/continuwuation/continuwuity/issues/811#issuecomment-26352), curated today with an eye on keeping cardinality low: - Uptime - Memory/CPU usage - DB size, perhaps - Accepted/rejected requests w/ rejection reasons (as long as the list of possible rejection reasons is short, to keep cardinality low in turn) - Others previously raised: - jemalloc if metrics are available (Jade) #### References Linked by s1lv3r earlier in this issue: https://matrix.to/#/!c10y-fNiMx5ijtgGFibzPUfNs9hpQvnJYPTV-fD2KPk/%24Kxf_loQH8SBpUqnxm9zZvBJAlovDqDaWXMkIk2mVqHU?via=wolfgirl.pet&via=explodie.org&via=matrix.org https://element-hq.github.io/synapse/latest/usage/administration/understanding_synapse_through_grafana_graphs.html Others from today (h/t Nex): https://grafana.i-am.nexus/public-dashboards/30de2946878045a796e8777691f3dd01 ...which is in turn derived from: https://demo.thefifthfleet.net/metrics
Henry-Hiles changed title from Prometheus metrics exporting to FR: Prometheus metrics exporting 2026-09-17 16:26:47 +00:00
Member

Could someone please update the title to remove "Prometheus"? As evinced by the discussion history here, it's an open question whether Prometheus is the exposition method of choice.

Could someone please update the title to remove "Prometheus"? As evinced by the discussion history here, it's an open question whether Prometheus is the exposition method of choice.
stratself changed title from FR: Prometheus metrics exporting to FR: Metrics exporting 2026-09-17 19:54:43 +00:00
Owner

This was implemented in #2282

This was implemented in #2282
nex closed this issue 2026-10-24 14:44:40 +00:00
Sign in to join this conversation.
No milestone
No assignees
6 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
continuwuation/continuwuity#811
No description provided.