AlexanderThaller / prometheus_exporter

Helper libary to export prometheus metrics using tiny_http and rust-prometheus.
MIT License
28 stars 10 forks source link

Support GET parameters from query string to /metrics #42

Open cooperlees opened 1 year ago

cooperlees commented 1 year ago

Are you open to adding supporting GET query string params to /metrics? It does feel like this depends on the move to hyper, as my very quick look @ tiny_http seems it doesn't process GET request query strings? I believe one can make prometheus send GET query stings from the following config:

    params:
      foo: ['bar']

I'd love to be able to send query params to make the exporter do different things depending on the query. For example for a prometheus exporter I wrote for systemd named monitord, I'd like to send a CSV list of systemd services to get extra stats on.

The tiny_http server seems to not like query strings from my testing

cooper@home1:~/repos/monitord-exporter$ cargo run -- -p 1469 -vv
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/monitord-exporter -p 1469 -vv`
[2023-05-15T01:16:28Z INFO  monitord_exporter] Starting monitord-exporter on port 1469
[2023-05-15T01:16:28Z DEBUG tiny_http] Server listening on [::]:1469
[2023-05-15T01:16:28Z INFO  prometheus_exporter] exporting metrics to http://[::]:1469/metrics
[2023-05-15T01:16:28Z DEBUG tiny_http] Running accept thread

Client:

cooper@home1:~$ curl -v http://localhost:1469/metrics?foo=bar
*   Trying 127.0.0.1:1469...
* Connected to localhost (127.0.0.1) port 1469 (#0)
> GET /metrics?foo=bar HTTP/1.1
> Host: localhost:1469
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: tiny-http (Rust)
< Date: Mon, 15 May 2023 01:29:06 GMT
< Content-Type: text/plain; charset=UTF-8
< Location: /metrics
< Content-Length: 25
<
try /metrics for metrics
* Connection #0 to host localhost left intact

If there is a way to do it and I missed it, I apologize. Please just point me at the code / example code :). I couldn't see it from your examples or docs.