Strapi plugin logo for Prometheus

Prometheus
Plugin verified by Strapi

strapi-prometheus is a simple plugin that exposes a metrics url for prometheus to scrape.

Strapi prometheus plugin

strapi-prometheus-downloads strapi-prometheus-version

"Buy Me A Coffee"

A simple middleware plugin that adds prometheus metrics to strapi using prom-client;

✨ Features

  • Collect API metrics for each call
  • Process Metrics as recommended by Prometheus
  • Endpoint to retrieve the metrics - used for Prometheus scraping
  • Set custom labels

⏳ Installation

npm i strapi-prometheus

Plugin

1// config/plugins.js
2
3// enable plugin with default configuration.
4module.exports = [
5  prometheus: {
6    enabled: true,
7    config: {
8      // see collectDefaultMetricsOption of prom-client
9      collectDefaultMetrics: false || { prefix: '' }
10      labels: { name: "strapi-prometheus" },
11      server: false || { port: 9000, host: '0.0.0.0', path: '/metrics' }
12    }
13  }
14];

📊 Metrics

namedescriptiontype
http_request_duration_secondsDuration of HTTP requests in secondsHistogram
http_request_content_length_bytesHistogram of the size of payloads sent to the server, measured in bytes.Histogram
http_response_content_length_bytesHistogram of the size of payloads sent by the server, measured in bytes.Histogram
http_requests_totalTotal number of HTTP requestsCounter
http_active_requestsNumber of active HTTP requestsGauge
http_errors_totalTotal number of HTTP errorsCounter
strapi_version_infoStrapi version infoGauge
lifecycle_duration_seconds'Tracks the duration of Strapi lifecycle events in secondsHistogram

👮‍♀️ Security

!CAUTION Use at own risk. Metric data can sometimes hold sensitive data that should not be publically available.

To keep your information secure, the plugin by default starts a new server on port 9000 so that your metrics aren't available to the outside world.

If this is not an option for you. You can disable this by updating the server config and setting it to false. This will then create an /metrics endpoint on your strapi server. This is secured by the strapi auth middleware so you will need to create a API token to be able to access it. I well mention it again this is not the recommended way, you should try and use the separate server.

🖐 Supported Strapi versions

  • Strapi v4.x (strapi-prometheus v1.x.x)
  • Strapi v5.x

📊 Prometheus example

⚠️ You need to create your own prometheus instance for this. This plugin does not do that for you!

here is a basic example of prometheus config. In this example we assume that the metrics endpoint is not secured.

1# prometheus.yaml
2
3global:
4  scrape_interval: 10s
5scrape_configs:
6  - job_name: "strapi"
7    metrics_path: "/metrics"
8    static_configs:
9      - targets: ["localhost:9000"]

📊 Grafana dashboards

Here are some usefull dashboards you can start with. If you want to have your dashboard added feel free to open a PR.

v1 -> v2 migration guide

A lot has changed from v1 to v2 other then strapi v5 support.

Firstly check the new configuration options those have been simplified a lot. For starters the name has been updated a little bit to prometheus instead of strapi-prometheus From v2 forwards a separate server that runs disconnected from strapi is the default behaviour. This can be disabled by passing server: false to the config.

Setting a custom registry has also been removed in favor of using the default register provided by the prom-client package. This allows us to create any metric at any place in our apps, instead of having to register it using this plugin. This gives you all the freedom of what to do with your custom metrics.

People using the apollo plugin will need to look into finding a new plugin to add to their apolloServer config. I recommend this one as it was used as inspiration.

Some metric updates:

  • apollo metrics have been deleted
  • http_request_duration_s renamed to http_request_duration_seconds
  • http_{response/request}_size_bytes renamed to http_{response/request}_content_length_bytes
  • added http_requests_total
  • added http_errors_total
  • added http_active_requests

Install now

npm install strapi-prometheus

STATS

18 GitHub stars1495 weekly downloads

Last updated

4 days ago

Strapi Version

5.0.0 and above

Author

github profile image for XanderD99
XanderD99

Useful links

Create your own plugin

Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.