Gather Prometheus metrics for your SailsJS application. Also it will opens /metrics
endpoint where Prometheus can scrap all statistics.
- sails-hook-prometheus
- Configuration
- Configuration in depth
defaultMetrics.enabled
(boolean)defaultMetrics.prefix
(string)httpMetric.enabled
(boolean)httpMetric.name
(string)httpMetric.type
(string)httpMetric.help
(string)httpMetric.buckets
(array of numbers)httpMetric.route.exclude
(array of strings)httpMetric.urlQueryString
(boolean)httpMetric.urlParams
(boolean)upMetric.enabled
(boolean)upMetric.name
(string)upMetric.help
(string)throughputMetric.enabled
(boolean)throughputMetric.name
(string)throughputMetric.help
(string)sockets.enabled
(boolean)
- Custom metrics
- Labels for custom metrics
- Custom
/metrics
endpoint
- Configuration in depth
- Contributors
- License
Install and save NPM dependency.
npm install --save sails-hook-prometheus
You can override default configuration. Create a file in /config/prometheus.js
with configuration values listed bellow.
All configuration values bellow are optional.
module.exports.prometheus = {
defaultMetrics: {
enabled: true
}
}
Enable/disable metric.
module.exports.prometheus = {
defaultMetrics: {
prefix: ``
}
}
Prefix for default collected metrics.
module.exports.prometheus = {
httpMetric: {
enabled: true
}
}
Enable/disable metric.
module.exports.prometheus = {
httpMetric: {
name: `http_request_duration_seconds`
}
}
Help text displayed as a metric title under /metrics page.
module.exports.prometheus = {
httpMetric: {
type: `histogram`
}
}
You can select between histogram or summary.
module.exports.prometheus = {
httpMetric: {
help: `duration histogram of http responses labeled with: `
}
}
Help text displayed next to the metric name.
module.exports.prometheus = {
httpMetric: {
buckets: [0.003, 0.03, 0.1, 0.3, 1.5, 10]
}
}
Buckets related to histogram metric.
module.exports.prometheus = {
httpMetric: {
exclude: [
'\\.css$',
'\\.js$',
'\\.(ico|gif|jpg|jpeg|png)$',
'\\.(eot|ttf|woff|woff2|svg)$'
]
}
}
Define which routes are excluded from histogram. Every element in array has to be a regular expression.
module.exports.prometheus = {
httpMetric: {
urlQueryString: true
}
}
Include URL query params in path
label. It is true
by default but please note your Prometheus server might not be ready for this amount of data (every unique URL).
module.exports.prometheus = {
httpMetric: {
urlParams: true
}
}
Include URL params in path
label. It is true
by default but please note your Prometheus server might not be ready for this amount of data (every unique URL).
module.exports.prometheus = {
upMetric: {
enabled: true
}
}
Enable/disable metric.
module.exports.prometheus = {
upMetric: {
name: `up`
}
}
module.exports.prometheus = {
upMetric: {
help: '1 = up, 0 = not up'
}
}
module.exports.prometheus = {
throughputMetric: {
enabled: false
}
}
Enable/disable metric.
module.exports.prometheus = {
throughputMetric: {
name: `throughput`
}
}
module.exports.prometheus = {
throughputMetric: {
help: 'The number of requests served'
}
}
module.exports.prometheus = {
sockets: {
enabled: false
}
}
Log socket requests as well. Due to the fact that status code is reserved for HTTP protocol only, the result of status code is always going to be 0.
You can add two kind of metrics on your own:
- counter (increase a metric)
- gauge (increase or decrease a metric)
let counter = sails.hooks.prometheus.counter.setup({
name: `testcounter`,
help: `help to the metric`
})
counter.inc() // increase a metric by default 1
// increase a metric by 2
counter.inc({
amount: 2
})
// increase a metric by 10
counter.inc({
amount: 10
})
let gauge = sails.hooks.prometheus.gauge.setup({
name: `testgauged`,
help: `help to the metric`
})
// increase a metric by default 1
gauge.inc()
// increase a metric by 10
gauge.inc({
amount: 10
})
// decrease a metric by default 1
gauge.dec()
// decrease a metric by 2
gauge.dec({
amount: 2
})
// set a metric to 100
gauge.set({
amount: 100
})
Both count and gauge metrics comes with labels feature as well.
let counter = sails.hooks.prometheus.counter.setup({
name: `testcounter`,
help: `help to the metric`
labelNames: [`counter1`, `counter2`]
})
counter.inc({
amount: 1,
labels: {
counter1: `value`
}
})
Note: Gauge metric goes the same.
You can configure your own public route by editing /config/routes.js
file.
module.exports.routes = {
'GET /api/v1/metrics': 'prometheus/metrics',
}
This project was originally created by Daniel Rataj.