
strapi-prometheus is a simple plugin that exposes a metrics url for prometheus to scrape.
released October 21, 2025
npm install strapi-prometheusA powerful middleware plugin that adds comprehensive Prometheus metrics to your Strapi application using prom-client ๐. Monitor your API performance, track system resources, and gain valuable insights into your application's behavior with just a few lines of configuration! ๐
npm install strapi-prometheus
# or
yarn add strapi-prometheus
# or
pnpm add strapi-prometheusnpm install prom-client
# or
yarn add prom-client
# or
pnpm add prom-clientCreate or update your config/plugins.js (or config/plugins.ts for TypeScript):
// config/plugins.js
module.exports = {
// ...other plugins
prometheus: {
enabled: true,
config: {
// Optional: Collect Node.js default metrics
// See collectDefaultMetricsOption of prom-client for all options
collectDefaultMetrics: false, // or { prefix: 'my_app_' }
// Optional: Add custom labels to all metrics
labels: {
app: "my-strapi-app",
environment: "production"
},
// Server configuration
// Set to false to expose metrics on your main Strapi server (not recommended)
server: {
port: 9000, // Metrics server port
host: '0.0.0.0', // Metrics server host
path: '/metrics' // Metrics endpoint path
},
// OR disable separate server (use with caution):
// server: false
// ๐ฏ Path Normalization Rules
normalize: [
[/\/(?:[a-z0-9]{24,25}|\d+)(?=\/|$)/, '/:id'], // Document IDs or numeric IDs
[/\/uploads\/[^\/]+\.[a-zA-Z0-9]+/, '/uploads/:file'], // Uploaded files with extensions
]
}
}
};For TypeScript projects:
// config/plugins.ts
export default {
prometheus: {
enabled: true,
config: {
collectDefaultMetrics: false,
labels: {
app: "my-strapi-app",
environment: process.env.NODE_ENV || "development"
},
server: {
port: parseInt(process.env.METRICS_PORT || '9000'),
host: process.env.METRICS_HOST || '0.0.0.0',
path: '/metrics'
},
// Custom normalization function (alternative to array rules)
normalize: (ctx) => {
let path = ctx.path;
// Custom logic for your specific needs
if (path.startsWith('/api/')) {
path = path.replace(/\/\d+/g, '/:id'); // Replace numeric IDs
}
return path;
}
}
}
};The plugin automatically collects the following metrics with intelligent route pattern detection โจ:
| Metric Name | Description | Type | Labels |
|---|---|---|---|
http_request_duration_seconds | Duration of HTTP requests in seconds โฑ๏ธ | Histogram | method, route, status |
http_request_content_length_bytes | Size of request payloads in bytes ๐ค | Histogram | method, route, status |
http_response_content_length_bytes | Size of response payloads in bytes ๐ฅ | Histogram | method, route, status |
strapi_version_info | Strapi version information ๐ท๏ธ | Gauge | version |
lifecycle_duration_seconds | Duration of Strapi database lifecycle events ๐พ | Histogram | event |
When collectDefaultMetrics is enabled, you'll also get Node.js process metrics:
process_cpu_user_seconds_total - CPU time spent in user modeprocess_cpu_system_seconds_total - CPU time spent in system modeprocess_start_time_seconds - Process start timeprocess_resident_memory_bytes - Resident memory sizenodejs_heap_size_total_bytes - Total heap sizenodejs_heap_size_used_bytes - Used heap sizenodejs_external_memory_bytes - External memory usageThe plugin features intelligent path normalization to ensure optimal metric cardinality by grouping similar routes together โจ
You can configure path normalization in two ways:
Use an array of [RegExp, replacement] tuples to define normalization patterns:
normalize: [
[/\/(?:[a-z0-9]{24,25}|\d+)(?=\/|$)/, '/:id'], // Document IDs or numeric IDs
[/\/uploads\/[^\/]+\.[a-zA-Z0-9]+/, '/uploads/:file'], // Uploaded files with extensions
// Custom patterns
[/\/users\/\d+/, '/users/:id'], // /users/123
[/\/orders\/ORD\d+/, '/orders/:orderCode'] // /orders/ORD12345
]Use a function for dynamic normalization logic:
normalize: (ctx) => {
let path = ctx.path;
// Custom normalization logic
if (path.startsWith('/api/')) {
path = path.replace(/\/\d+/g, '/:id'); // Replace numeric IDs
path = path.replace(/\/[a-f0-9-]{36}/gi, '/:uuid'); // Replace UUIDs
}
// Multi-tenant example
if (path.startsWith('/tenant/')) {
path = path.replace(/^\/tenant\/[^\/]+/, '/tenant/:id');
}
return path;
}The plugin includes pre-configured patterns for common Strapi routes:
| Original Path | Normalized Path | Description |
|---|---|---|
/api/posts/123 | /api/posts/:id | API resource with ID |
/api/posts/123/comments/456 | /api/posts/:id/comments/:id | Nested resources |
/admin/content-manager/collection-types/api::post.post/123 | /admin/content-manager/:type/:contentType/:id | Admin content manager |
/uploads/image.jpg | /uploads/:file | File uploads |
/en/api/posts/123 | /:locale/api/posts/:id | i18n localized routes |
/fr-FR/dashboard | /:locale/dashboard | Locale-specific pages |
http://localhost:9000/metricsBy default, metrics are served on a separate server:
curl http://localhost:9000/metricsIf you set server: false, metrics will be available on your main Strapi server:
# Requires authentication token
curl -H "Authorization: Bearer YOUR_API_TOKEN" http://localhost:1337/api/metrics[!CAUTION] Metrics can contain sensitive information about your application's usage patterns, performance characteristics, and potentially user behavior. Always secure your metrics endpoint appropriately.
The plugin starts a separate server on port 9000 by default, isolated from your main application:
You can expose metrics on your main Strapi server by setting server: false:
We strongly recommend using the dedicated server approach.
| Strapi Version | Plugin Version | Status |
|---|---|---|
| v5.x | v2.x.x | โ Fully Supported โญ |
| v4.x | v1.x.x | โ EOL ๐ง |
Note: For new projects, we recommend using Strapi v5.x with the latest plugin version! ๐ฏ
Ready-to-use Grafana dashboards for visualizing your Strapi metrics:
Have a great dashboard? We'd love to feature it! Please open a pull request with your dashboard JSON. ๐จ
config/plugins.jsprom-client is installedcollectDefaultMetrics if not neededVersion 2.0 brings significant improvements and Strapi v5 support. Here's what you need to know:
Old (v1):
module.exports = {
'strapi-prometheus': {
enabled: true,
config: {
// v1 config
}
}
};New (v2):
module.exports = {
prometheus: { // โ Plugin name simplified
enabled: true,
config: {
// v2 config (see configuration section above)
}
}
};| v1 Metric | v2 Metric | Change |
|---|---|---|
http_request_duration_s | http_request_duration_seconds | โ Renamed for clarity |
http_request_size_bytes | http_request_content_length_bytes | โ Renamed for accuracy |
http_response_size_bytes | http_response_content_length_bytes | โ Renamed for accuracy |
Labels: path | Labels: route | โ More consistent route patterns |
| Apollo metrics | โ | ๐๏ธ Removed - use apollo-prometheus-exporter |
| - | http_requests_total | โ New counter metric |
| - | http_active_requests | โ New gauge metric |
v2 Improvements:
_matchedRoute when available for accurate patterns/api/articles/123 โ /api/articles/:idserver settings)prom-client registry (this actually gives you more flexibility!)We welcome contributions! Here's how you can help:
git checkout -b feature/amazing-feature ๐ฟgit commit -m 'Add amazing feature' ๐ฌgit push origin feature/amazing-feature ๐This project is licensed under the MIT License - see the LICENSE file for details.
Xander Denecker (@XanderD99)
โญ If this plugin helps you, please consider giving it a star on GitHub!
Share your work with the community and get it listed in the Strapi ecosystem for everyone to discover and use.
Submit
