miekg / caddy-prometheus

Prometheus metrics middleware for caddy
Apache License 2.0
65 stars 26 forks source link

Reuse exporter for custom metrics #21

Open samber opened 7 years ago

samber commented 7 years ago

Hi guys,

What about adding a route POST /metrics to use the same Prometheus exporter for Caddy and a microservice ?

Most of my service using Caddy are coded in php, and, as you probably know, we cannot natively export metrics from php app without a statsd or collectd.

Having one binary starting a reverse proxy, fpm and a prometheus exporter for my app looks very interesting !

ping @mholt

miekg commented 7 years ago

Sure. But what needs to be coded here?

samber commented 7 years ago

I think we should add a route PUT /metrics with the following body:

[
   {
      name: "api_custom_data1",
      help: "help message",
      type: "counter",
      labels: {
        foo: "bar",
        bar: "foo",
      },
      inc: 42
   },
   {
      name: "api_custom_data2",
      help: "help message",
      type: "gauge",
      labels: {
      },
      set: 1337
   }
]

At the first call, metric(s) is/are created, and then updated according to the inc/dec/set/whatever value.

Calling the prometheus endpoint would return:

# HELP api_custom_data1 help message.
# TYPE api_custom_data1 counter
api_custom_data1{foo="bar", bar="foo"} 42
# HELP api_custom_data2 help message.
# TYPE api_custom_data2 gauge
api_custom_data2{} 1337
...
miekg commented 7 years ago

Ah. you need to define an API and then reexport that. Ack. Don't really believe this should be done in this middleware.

Also: is there an official HTTP api for prometheus or something? You don't want to reinvent the wheel here.