-
-
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 prometheus client and metrics server to Ghost #21192
Closed
cmraible
wants to merge
22
commits into
TryGhost:main
from
cmraible:chris-eng-1505-add-prometheus-metrics-server-to-allow-monitoring-ghost
Closed
Added prometheus client and metrics server to Ghost #21192
cmraible
wants to merge
22
commits into
TryGhost:main
from
cmraible:chris-eng-1505-add-prometheus-metrics-server-to-allow-monitoring-ghost
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
…port, or to disable it
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](https://github.com/siimon/prom-client)
. We could useprom-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 enabled by default, but can be disabled by setting the
metrics_server:disabled
flag totrue
.Why not expose the
/metrics
endpoint in one of the existing express apps?The standalone express app exists for two main reasons:
/metrics
endpoint at a different port that won't be exposed to the internet.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 therequire
s, will run if themetrics_server:disabled
flag is set totrue
.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.