miekg / caddy-prometheus

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

Added a hostname parameter #32

Closed NegativeBlue closed 6 years ago

NegativeBlue commented 6 years ago

This PR adds a hostname parameter to the configuration, enabling differentiation between two sites hosted on the same domain.

Consider the following example:

http://127.0.0.1:1234 {
    prometheus
}

http://127.0.0.1:4567 {
    prometheus
}

Previously these two would have been indifferent in the generated metrics. They would both count towards stats with the parameter as host="127.0.0.1".

This PR adds a hostname parameter, which can be specified if wanted, allowing the following:

http://127.0.0.1:1234 {
    prometheus {
        hostname local-1
    }
}

http://127.0.0.1:4567 {
    prometheus {
        hostname local-2
    }
}

Now two different hosts running on the same domain or IP can be differentiated via their host parameter.

There should not be any conflicts with existing configurations as this parameter is completely new and optional.

This is pretty much the first bit of Go that I have written, so I'd appreciate any criticism or corrections if I did anything wrong.

miekg commented 6 years ago

This is good to add. This needs a few words in the README.md as well.

Gives me an idea for CoreDNS as well :)

NegativeBlue commented 6 years ago

I've added the hostname parameter to the README.md and changed the formatting a bit. Hopefully it is clear enough to understand what the hostname parameter does.