-
-
Notifications
You must be signed in to change notification settings - Fork 188
Add Prometheus Metrics Support #505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks again @Tigger2014 ! While I'm away I thought I'd ask a couple of questions to reduce later delays. Clearly you have experience with Prometheus, so I expect it'll be easy to answer. These three questions are linked, I know, but I think it's easier to break down:
To me it would make more sense to conditionally enable the API route to the existing http(s) via the flag, which would then also allow the HTTP and HTTPS (without having to "duplicate" flags), and then optionally limit it by op or subnet. In fact, a single flag could be sufficient with just Keen to hear your thoughts? |
Thanks for the feedback! I've updated the implementation since my initial PR description to address exactly these concerns. The current implementation now supports both approaches: Integrated Mode (Default): When Separate Server Mode: When set to an address like The flag design is: --enable-prometheus "true" # Uses existing web server (inherits HTTPS config)
--enable-prometheus ":9090" # Separate server on port 9090
--enable-prometheus "" # Disabled (default) This addresses your concerns:
The implementation defaults to the integrated approach (reusing existing infrastructure) while maintaining the separate server option for advanced use cases where network isolation is needed. Regarding IP restrictions - Likely not something Mailpit should handle directly. It's best left to other parts of the infrastructure (reverse proxies, firewalls, network policies) for environments where that's necessary. It's quite common to have Prometheus exposed over HTTP without auth within Kubernetes, for example, where each node scrapes pods internally. This adjusted approach provides the best of both worlds. Let me know your thoughts and I can update the docs/PR description accordingly! |
Hi @Tigger2014. Thanks for the updates/changes. Yes, I think we can get away with using just a single multi-purpose flag A few comments/requests:
I intend to add both this feature and your other MR to v1.26.0 once ready (just so you're aware re: docs). I already reviewed, tested and merged your other MR, so that release will depend a bit on how fast we can get this one finalised, tested etc - however I do not want to put any unnecessary pressure on you, so please do not stress. I am really grateful for what you have done! Thanks so much, and I'm looking forward to your revisions. |
Also I think there may be some issues with some of the metrics (float64):
|
389c3e9
to
b373b9f
Compare
Hi @axllent, thank you for taking the time to review my changes thoroughly. I've gone ahead and made the suggested changes. Regarding the float64 issue, I'm not sure that it is in fact, an issue; scientific notation should be valid. |
Thank you @Tigger2014. I'm still a bit concerned about the gauge format, as it looks to me like the output from a calculator which can't handle a large number :) , This is most likely because I'm simply inexperienced with Prometheus, so I am relying heavily on your feedback & experience here. I assume you use Prometheus and have tested this on a running Mailpit instance? Does it give meaningful values within Prometheus which can be used to monitor / chart? Assuming "yes" to the previous questions, how confident are you that this is "production ready"? |
Hello @axllent , Prometheus is something I use more than I write, so I had to do some digging into the floats. I've spun up a quick Prometheus server and scraped Mailpit below. It appears to me that everything is working as expected. This is an example of all the metrics as displayed in Prometheus, the This data displays in Grafana without difficulty: Simple Docker compose for testing.
Do let me know if you have any more questions or if I've been unclear. Many thanks |
That's very useful, and reassuring. I have no idea how those scientific notations result in seemingly accurate values, but your screenshots indicate it's working correctly so I won't argue. I'm afraid I'm going to have to push the release out a few days in order to further test, review and put the release together (I don't like rushing out new features without being as sure as I can be that it works). I hope that's not an issue given all the hard work you've put in? |
Add Prometheus Metrics Support
Closes #497
This PR implements Prometheus metrics support for Mailpit.
The same metrics as exposed on the info API endpoint are exposed here.
Integrated Mode: When
--enable-prometheus
is set to"true"
, metrics are served via the existing web server at /metrics. This automatically inherits all the existing server configurations.Separate Server Mode: When set to an address like
":9090"
, it runs a dedicated metrics server for users who need that separation.The flag design is:
--enable-prometheus "true" # Uses existing web server (inherits HTTPS config)
--enable-prometheus ":9090" # Separate server on port 9090
--enable-prometheus "false" # Disabled (default)
New Configuration Option:
--enable-prometheus
: Enable Prometheus metrics serverNew Environment Variable:
MP_ENABLE_PROMETHEUS
: Enable Prometheus metrics collection-Prometheus metrics are disabled by default - no impact on existing installations