prometheus-plugs
prometheus-plugs copied to clipboard
Forward-friendly exporter plug
The current exporter plug is serving metrics on given path (/metrics
by default), or passing the conn. This is for plug pipeline... and it doesn't work for phoenix router!
# phoenix example
# in endpoint
plug My.PrometheusExporter.
This works... but it sounds strange. For example, to change the path, I need to set it at application config of the exporter module, not when using it.
One option is to add plug option :path
.. but that is wrong approach, since plug can be composable!
Instead of we make this as "app" like plug having lots of configs... we can just have very simple exporter plug use forward mechanism. (Plug - forward/2
/ Phoenix - forward/4
).
# phoenix example
pipeline :default do
plug :accepts, ["json"]
end
scope "/" do
pipe_through :default
forward "/metrics", My.PrometheusExporter
end
In this case, path for metrics is configured at router, not on application config of the exporter module. Also the exporter plug runs only on that path (not for all requests as in pipeline)
I like that! what needs to be done?
Here's how the bamboo
library does it, they have an EmailPreviewPlug
plug that serves a page for viewing sent emails:
https://github.com/thoughtbot/bamboo/blob/master/lib/bamboo/plug/sent_email_viewer/email_preview_plug.ex