klaus icon indicating copy to clipboard operation
klaus copied to clipboard

Really basic implementation of a metrics target for use by prometheus

Open jelmer opened this issue 2 years ago • 5 comments

Really basic implementation of a metrics target for use by prometheus.

Some caveats:

  • this exposes /metrics on the same port as the rest of klaus; one might not want to expose internal metrics there
  • this doesn't yet add any really useful metrics (number of requests, failures, exceptions, etc). At the moment it just exports a bunch of python statstics.

jelmer avatar Jan 08 '22 12:01 jelmer

I wonder if this could be implemented as a WSGI middleware? (Maybe there already exists some pluggable WSGI middleware that we can just use?)

jonashaag avatar Jan 08 '22 12:01 jonashaag

Maybe one of those, didn't look into any closely though

https://github.com/benley/python-wsgi-prometheus https://github.com/prometheus/client_python#wsgi https://github.com/rycus86/prometheus_flask_exporter

jonashaag avatar Jan 08 '22 12:01 jonashaag

It can't be just middleware if you want to add klaus-specific metrics, and those are the most useful.

client_python (the second in your list) is what I'm using in this PR

jelmer avatar Jan 08 '22 13:01 jelmer

Sure, at least we will have to provide some hooks in the Klaus codebase or we can push metrics from Klaus (eg. increase some counters from Klaus views).

I was wondering more about the metrics endpoint. I wonder if it makes sense to use Prometheus-Flask-Exporter or something like this: https://github.com/prometheus/client_python#flask

But I am fine with a stand-alone implementation if you think that’s easier. I wonder if we should make the feature optional even if prometheus_client is installed.

jonashaag avatar Jan 08 '22 15:01 jonashaag

Maybe the best approach here is to have a separate port for the metrics. That's consistent with what other web apps do - so you don't have your metrics exposed to the internet. The other benefit is that we can then only import the metrics library when --metrics-port is specified.

jelmer avatar Oct 16 '22 17:10 jelmer