-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Added a prometheus metrics exporter to Ghost #21193
Merged
cmraible
merged 26 commits into
TryGhost:main
from
cmraible:chris-eng-1505-add-prometheus-metrics-server-to-allow-monitoring-ghost
Oct 3, 2024
Merged
Added a prometheus metrics exporter to Ghost #21193
cmraible
merged 26 commits into
TryGhost:main
from
cmraible:chris-eng-1505-add-prometheus-metrics-server-to-allow-monitoring-ghost
Oct 3, 2024
+833
−6
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmraible
changed the title
Chris eng 1505 add prometheus metrics server to allow monitoring ghost
Added a prometheus metrics exporter to Ghost
Oct 3, 2024
cmraible
force-pushed
the
chris-eng-1505-add-prometheus-metrics-server-to-allow-monitoring-ghost
branch
from
October 3, 2024 01:59
974143e
to
f172dcd
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #21193 +/- ##
==========================================
+ Coverage 73.70% 73.83% +0.13%
==========================================
Files 1285 1286 +1
Lines 76010 76128 +118
Branches 10114 10137 +23
==========================================
+ Hits 56021 56209 +188
+ Misses 19060 18983 -77
- Partials 929 936 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
…port, or to disable it
cmraible
force-pushed
the
chris-eng-1505-add-prometheus-metrics-server-to-allow-monitoring-ghost
branch
from
October 3, 2024 18:02
69eeee6
to
52f8f62
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ref https://linear.app/tryghost/issue/ENG-1505/add-prometheus-metrics-server-to-allow-monitoring-ghost-metrics
Summary
This commit includes two main components: a prometheus client class to collect metrics from Ghost, and a standalone metrics server that exposes a /metrics endpoint at a separate port (9416 by default) from the main Ghost app.
The prometheus client is a very thin wrapper around prom-client. We could use prom-client directly, but this approach should make it easier to switch to a different prometheus client package (or make our own) if we ever need to down the line.
The list of default metrics this enables is specified in an e2e test here. This also gives us the ability to create and collect custom metrics, although none are included in this commit yet.
Configuration
The prometheus client and the metrics server are both disabled by default, but can be enabled by setting the metrics_server:enabled flag to true.
You can also define a custom host and port using
metrics_server:host
andmetrics_server:port
.Why not expose the /metrics endpoint in one of the existing express apps?
The standalone express app exists for two main reasons:
We don't want these metrics to be public, and the easiest way to accomplish that is to expose the /metrics endpoint at a different port that won't be exposed to the internet.
Creating a standalone express instance decouples the metrics endpoint from the Ghost server, so if Ghost is not responding for whatever reason, we should still be able to scrape metrics to understand what's going on internally.
Impact on Boot & Shut down time
The prometheus client is initialized early in the boot process so we can collect metrics during the boot sequence. Testing locally has shown that this increases boot time by ~20ms. The metrics server which exposes the /metrics endpoint is not initialized until after the background services, and it is not awaited, to avoid impacting boot time. None of this code, including the requires, will run if the metrics_server:enabled flag is set to false (or not set).
Shutting down the metrics server is added as a cleanup task for the main Ghost server instance, and is setup to shut down with 0 grace period to avoid impacting shut down time.