Peep.Plug (peep v4.2.0)
View SourceUse this plug to expose your metrics on an endpoint for scraping. This is useful if you are using Prometheus.
This plug accepts the following options:
:peep_worker
- The name of the Peep worker to use. This is required.:path
- The path to expose the metrics on. Defaults to"/metrics"
.:on_unmatched_path
- The intended behavior of this plug when handling a request to a different path. There are two possible values::continue
(default) - This allows for subsequent Plugs in a router to be executed. This option is useful when Peep.Plug is part of a router for a Phoenix application, or a router that matches other paths after Peep.Plug.:halt
- Responds to requests with 404. This option is useful when Peep.Plug is used for serving metrics on a separate port, which is a practice that is encouraged by other libraries that export Prometheus metrics.
Usage
You can use this plug in your Phoenix endpoint like this:
plug Peep.Plug, peep_worker: :my_peep_worker
Or if you'd rather use a different path:
plug Peep.Plug, path: "/my-metrics"
If you are not using Phoenix, you can use it directly with Cowboy by adding this to your applications's supervision tree:
{Plug.Cowboy, scheme: :http, plug: Peep.Plug, options: [port: 9000]}
Similarly, if you are using Bandit, you can use it like so:
{Bandit, [
scheme: :http,
plug: {Peep.Plug, peep_worker: :my_app},
port: 9000
]}