Add prometheus metrics at /api/v1/metrics#3576
Add prometheus metrics at /api/v1/metrics#3576Wint3rmute wants to merge 7 commits intoiv-org:masterfrom
Conversation
8e938bc to
c57505a
Compare
|
Not a bad idea and without any external dependency, so it's great. |
I've had the idea of more metrics in mind for quite a while. I think that once I'm done with #3628, we'll be able to add various metrics. A non-exhaustive list of (imo) useful metrics:
I'm not sure about that one. Statistics are metrics.
In my opinion, this should be handled in the reverse proxy config. We need to inform the maintainers across the documentation, but I don't think we should add all that complexity. |
|
Seems like a nice feature, just make sure it doesn't compromise the privacy of users. |
92e08af to
81f0bc4
Compare
|
I've learned more about the Kemal framework and rewrote the metrics collection, trying to fullfill the ideas described by @SamantazFox:
*response latency per X hours can be calculated using a monitoring system such as Prometheus, imo such aggregation should not be performed by Invidious. Metrics that this MR provides return the sum of seconds spent on handling a particular route, which can be used to calculate the latency per X hours. Afaik this is also what Prometheus suggests to do in this scenario. Here's a sample of the new metrics, running on a local instance of Invidious: @alx-alexpark as you can see, there are no metrics which would compromise the privacy :) Implementation notes
Problems encounteredFor some reason, the metrics collection handler is not called when the Other notesImo adding database metrics to this PR would make it too large, so I'd prefer to split it into another PR :) |
40a7381 to
7cbf78a
Compare
|
Oh, sorry, I didn't notice that you update your code! That's looking great :D |
7ef3b00 to
bc826b5
Compare
05294ab to
7075465
Compare
|
I've tried this PR on my personal private instance (running this PR rebased on latest master commit ( iv-org:master 90e94d4 ) as a docker ). It works fine, thank you for the PR! Extra infos if needed: To add it on a Prometheus server: - job_name: invidious
static_configs:
- targets: ['localhost:3088']
metrics_path: /api/v1/metricsHere is a prototype dashboard you may use in Grafana for testing: grafana_invidious_panel.json (sorry units are wrong on the HTTP rates, feel free to correct!) |
|
@Soblow Thanks for trying it out :D |
|
I know that this pull request is really old but works fine with a single instance of Invidious running! With replicas, it doesn't work really great, all the metrics look messed up when two processes of Invidious are running under the same domain but this is not a problem that should be addressed on this PR anyways. What is keeping this from getting merged? |
|
It has a bug!. When using any URL that is not in any registered route by invidious like https://inv.nadeko.net/health, one should expect being redirected to https://inv.nadeko.net/channel/UCF11Yrx9bAy2Q6j6lgo0JwQ, but with this PR you get "500 Internal Server Error" instead with this backtrace: Maybe because it's too old? |
… into invidious.cr
…MetricsCollector is no longer initialized as a singleton
7075465 to
5999dc3
Compare
|
Woah, I almost forgot about this MR now :) I rebased it against the I don't have the resources or the required Crystal knowledge to debug this. If anyone is willing to continue the work on adding metrics to Invidious, feel free to use this MR as a starting point. |
This reverts commit e5c0f15 due to iv-org/invidious#3576 (comment) , reversing changes made to ecacbab.


Hello,
Please note that this MR is purely a suggestion for a feature. If you don't think that such a feature is needed, feel free to close it :)
This MR adds a prometheus-compatible
/api/v1/metricsendpoint, which serves the subset of metrics (only numeric ones) contained in the/api/v1/stats, but in Prometheus-compatible format. The endpoint will only work ifstatistics_enabled: truein the configuration.Motivation
Having a prometheus-compatible endpoint could make it easier for instance maintainers to monitor their instance. I can only speak for myself, but I've found Prometheus to be quite useful both for monitoring and for setting alerts when one of my services goes down. There's not much useful information contained in the metrics added by this MR, however I can imagine that more useful metrics could be extracted from invidious. Unfortunately, I'm not familiar with the project's code at the moment, so I'm trying to take small steps here :)
Possible paths for further development
statistics_enabled