prom-client
Advanced tools
Comparing version 11.0.0 to 11.1.0
@@ -16,2 +16,13 @@ # Changelog | ||
## [11.1.0] - 2018-06-29 | ||
* Added ability to set a name prefix in the default metrics | ||
### Changed | ||
* Fixed `startTimer` utility to not mutate objects passed as `startLabels` | ||
* Fixed `Counter` to validate labels parameter of `inc()` against initial | ||
labelset | ||
* Fixed `AggregatorFactory` losing the aggregator method of metrics | ||
## [11.0.0] - 2018-03-10 | ||
@@ -18,0 +29,0 @@ |
@@ -146,2 +146,5 @@ /** | ||
labels = labels || {}; | ||
validateLabels(this.labelNames, labels); | ||
const incValue = value === null || value === undefined ? 1 : value; | ||
@@ -148,0 +151,0 @@ |
@@ -61,3 +61,3 @@ 'use strict'; | ||
return defaultMetric(normalizedConfig.register); | ||
return defaultMetric(normalizedConfig.register, config); | ||
}); | ||
@@ -64,0 +64,0 @@ |
@@ -187,3 +187,3 @@ /** | ||
this.set( | ||
Object.assign(startLabels || {}, endLabels), | ||
Object.assign({}, startLabels, endLabels), | ||
delta[0] + delta[1] / 1e9 | ||
@@ -190,0 +190,0 @@ ); |
@@ -157,3 +157,3 @@ /** | ||
this.observe( | ||
Object.assign(startLabels || {}, endLabels), | ||
Object.assign({}, startLabels, endLabels), | ||
delta[0] + delta[1] / 1e9 | ||
@@ -160,0 +160,0 @@ ); |
@@ -17,3 +17,4 @@ 'use strict'; | ||
type: metrics[0].type, | ||
values: [] | ||
values: [], | ||
aggregator: metrics[0].aggregator | ||
}; | ||
@@ -20,0 +21,0 @@ // Gather metrics by metricName and labels. |
@@ -15,5 +15,7 @@ 'use strict'; | ||
module.exports = registry => { | ||
module.exports = (registry, config = {}) => { | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
const gauge = new Gauge({ | ||
name: NODEJS_EVENTLOOP_LAG, | ||
name: namePrefix + NODEJS_EVENTLOOP_LAG, | ||
help: 'Lag of event loop in seconds.', | ||
@@ -20,0 +22,0 @@ registers: registry ? [registry] : undefined, |
@@ -10,3 +10,3 @@ 'use strict'; | ||
module.exports = registry => { | ||
module.exports = (registry, config = {}) => { | ||
if (typeof process.memoryUsage !== 'function') { | ||
@@ -17,5 +17,6 @@ return () => {}; | ||
const registers = registry ? [registry] : undefined; | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
const heapSizeTotal = new Gauge({ | ||
name: NODEJS_HEAP_SIZE_TOTAL, | ||
name: namePrefix + NODEJS_HEAP_SIZE_TOTAL, | ||
help: 'Process heap size from node.js in bytes.', | ||
@@ -25,3 +26,3 @@ registers | ||
const heapSizeUsed = new Gauge({ | ||
name: NODEJS_HEAP_SIZE_USED, | ||
name: namePrefix + NODEJS_HEAP_SIZE_USED, | ||
help: 'Process heap size used from node.js in bytes.', | ||
@@ -35,3 +36,3 @@ registers | ||
externalMemUsed = new Gauge({ | ||
name: NODEJS_EXTERNAL_MEMORY, | ||
name: namePrefix + NODEJS_EXTERNAL_MEMORY, | ||
help: 'Nodejs external memory size in bytes.', | ||
@@ -38,0 +39,0 @@ registers |
@@ -21,3 +21,3 @@ 'use strict'; | ||
module.exports = registry => { | ||
module.exports = (registry, config = {}) => { | ||
if ( | ||
@@ -31,2 +31,3 @@ typeof v8 === 'undefined' || | ||
const registers = registry ? [registry] : undefined; | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
@@ -37,3 +38,3 @@ const gauges = {}; | ||
gauges[metricType] = new Gauge({ | ||
name: NODEJS_HEAP_SIZE[metricType], | ||
name: namePrefix + NODEJS_HEAP_SIZE[metricType], | ||
help: `Process heap space size ${metricType} from node.js in bytes.`, | ||
@@ -40,0 +41,0 @@ labelNames: ['space'], |
@@ -9,5 +9,7 @@ 'use strict'; | ||
function notLinuxVariant(registry) { | ||
function notLinuxVariant(registry, config = {}) { | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
const residentMemGauge = new Gauge({ | ||
name: PROCESS_RESIDENT_MEMORY, | ||
name: namePrefix + PROCESS_RESIDENT_MEMORY, | ||
help: 'Resident memory size in bytes.', | ||
@@ -27,6 +29,6 @@ registers: registry ? [registry] : undefined | ||
module.exports = registry => | ||
module.exports = (registry, config) => | ||
process.platform === 'linux' | ||
? linuxVariant(registry) | ||
: notLinuxVariant(registry); | ||
? linuxVariant(registry, config) | ||
: notLinuxVariant(registry, config); | ||
@@ -33,0 +35,0 @@ module.exports.metricNames = |
@@ -34,6 +34,8 @@ 'use strict'; | ||
module.exports = registry => { | ||
module.exports = (registry, config = {}) => { | ||
const registers = registry ? [registry] : undefined; | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
const residentMemGauge = new Gauge({ | ||
name: PROCESS_RESIDENT_MEMORY, | ||
name: namePrefix + PROCESS_RESIDENT_MEMORY, | ||
help: 'Resident memory size in bytes.', | ||
@@ -43,3 +45,3 @@ registers | ||
const virtualMemGauge = new Gauge({ | ||
name: PROCESS_VIRTUAL_MEMORY, | ||
name: namePrefix + PROCESS_VIRTUAL_MEMORY, | ||
help: 'Virtual memory size in bytes.', | ||
@@ -49,3 +51,3 @@ registers | ||
const heapSizeMemGauge = new Gauge({ | ||
name: PROCESS_HEAP, | ||
name: namePrefix + PROCESS_HEAP, | ||
help: 'Process heap size in bytes.', | ||
@@ -52,0 +54,0 @@ registers |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = registry => { | ||
module.exports = (registry, config = {}) => { | ||
// Don't do anything if the function doesn't exist (introduced in node@6.1.0) | ||
@@ -16,5 +16,6 @@ if (typeof process.cpuUsage !== 'function') { | ||
const registers = registry ? [registry] : undefined; | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
const cpuUserUsageCounter = new Counter({ | ||
name: PROCESS_CPU_USER_SECONDS, | ||
name: namePrefix + PROCESS_CPU_USER_SECONDS, | ||
help: 'Total user CPU time spent in seconds.', | ||
@@ -24,3 +25,3 @@ registers | ||
const cpuSystemUsageCounter = new Counter({ | ||
name: PROCESS_CPU_SYSTEM_SECONDS, | ||
name: namePrefix + PROCESS_CPU_SYSTEM_SECONDS, | ||
help: 'Total system CPU time spent in seconds.', | ||
@@ -30,3 +31,3 @@ registers | ||
const cpuUsageCounter = new Counter({ | ||
name: PROCESS_CPU_SECONDS, | ||
name: namePrefix + PROCESS_CPU_SECONDS, | ||
help: 'Total user and system CPU time spent in seconds.', | ||
@@ -33,0 +34,0 @@ registers |
@@ -7,3 +7,3 @@ 'use strict'; | ||
module.exports = registry => { | ||
module.exports = (registry, config = {}) => { | ||
// Don't do anything if the function is removed in later nodes (exists in node@6) | ||
@@ -14,4 +14,6 @@ if (typeof process._getActiveHandles !== 'function') { | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
const gauge = new Gauge({ | ||
name: NODEJS_ACTIVE_HANDLES, | ||
name: namePrefix + NODEJS_ACTIVE_HANDLES, | ||
help: 'Number of active handles.', | ||
@@ -18,0 +20,0 @@ registers: registry ? [registry] : undefined |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = registry => { | ||
module.exports = (registry, config = {}) => { | ||
let isSet = false; | ||
@@ -15,4 +15,7 @@ | ||
} | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
const fileDescriptorsGauge = new Gauge({ | ||
name: PROCESS_MAX_FDS, | ||
name: namePrefix + PROCESS_MAX_FDS, | ||
help: 'Maximum number of open file descriptors.', | ||
@@ -19,0 +22,0 @@ registers: registry ? [registry] : undefined |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = registry => { | ||
module.exports = (registry, config) => { | ||
if (process.platform !== 'linux') { | ||
@@ -14,4 +14,6 @@ return () => {}; | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
const fileDescriptorsGauge = new Gauge({ | ||
name: PROCESS_OPEN_FDS, | ||
name: namePrefix + PROCESS_OPEN_FDS, | ||
help: 'Number of open file descriptors.', | ||
@@ -18,0 +20,0 @@ registers: registry ? [registry] : undefined |
@@ -7,3 +7,3 @@ 'use strict'; | ||
module.exports = registry => { | ||
module.exports = (registry, config = {}) => { | ||
// Don't do anything if the function is removed in later nodes (exists in node@6) | ||
@@ -14,4 +14,6 @@ if (typeof process._getActiveRequests !== 'function') { | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
const gauge = new Gauge({ | ||
name: NODEJS_ACTIVE_REQUESTS, | ||
name: namePrefix + NODEJS_ACTIVE_REQUESTS, | ||
help: 'Number of active requests.', | ||
@@ -18,0 +20,0 @@ registers: registry ? [registry] : undefined |
@@ -8,5 +8,7 @@ 'use strict'; | ||
module.exports = registry => { | ||
module.exports = (registry, config = {}) => { | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
const cpuUserGauge = new Gauge({ | ||
name: PROCESS_START_TIME, | ||
name: namePrefix + PROCESS_START_TIME, | ||
help: 'Start time of the process since unix epoch in seconds.', | ||
@@ -13,0 +15,0 @@ registers: registry ? [registry] : undefined, |
@@ -12,5 +12,7 @@ 'use strict'; | ||
module.exports = registry => { | ||
module.exports = (registry, config = {}) => { | ||
const namePrefix = config.prefix ? config.prefix : ''; | ||
const nodeVersionGauge = new Gauge({ | ||
name: NODE_VERSION_INFO, | ||
name: namePrefix + NODE_VERSION_INFO, | ||
help: 'Node.js version info.', | ||
@@ -17,0 +19,0 @@ labelNames: ['version', 'major', 'minor', 'patch'], |
@@ -186,3 +186,3 @@ /** | ||
this.observe( | ||
Object.assign(startLabels || {}, endLabels), | ||
Object.assign({}, startLabels, endLabels), | ||
delta[0] + delta[1] / 1e9 | ||
@@ -189,0 +189,0 @@ ); |
@@ -89,5 +89,3 @@ 'use strict'; | ||
printDeprecation( | ||
`prom-client - A number to defaultMetrics is deprecated, please use \`collectDefaultMetrics({ timeout: ${ | ||
timeout | ||
} })\`.` | ||
`prom-client - A number to defaultMetrics is deprecated, please use \`collectDefaultMetrics({ timeout: ${timeout} })\`.` | ||
); | ||
@@ -94,0 +92,0 @@ }; |
@@ -27,5 +27,5 @@ 'use strict'; | ||
throw new Error( | ||
`Added label "${ | ||
label | ||
}" is not included in initial labelset: ${util.inspect(savedLabels)}` | ||
`Added label "${label}" is not included in initial labelset: ${util.inspect( | ||
savedLabels | ||
)}` | ||
); | ||
@@ -32,0 +32,0 @@ } |
{ | ||
"name": "prom-client", | ||
"version": "11.0.0", | ||
"version": "11.1.0", | ||
"description": "Client for prometheus", | ||
@@ -30,6 +30,6 @@ "main": "index.js", | ||
"husky": "^0.14.3", | ||
"jest": "^21.2.1", | ||
"lint-staged": "^5.0.0", | ||
"jest": "^22.4.2", | ||
"lint-staged": "^7.0.0", | ||
"lolex": "^2.1.3", | ||
"prettier": "1.8.2", | ||
"prettier": "1.11.1", | ||
"typescript": "^2.5.2" | ||
@@ -36,0 +36,0 @@ }, |
@@ -54,6 +54,6 @@ # Prometheus client for node.js [![Build Status](https://travis-ci.org/siimon/prom-client.svg?branch=master)](https://travis-ci.org/siimon/prom-client) [![Build status](https://ci.appveyor.com/api/projects/status/k2e0gwonkcee3lp9/branch/master?svg=true)](https://ci.appveyor.com/project/siimon/prom-client/branch/master) | ||
`collectDefaultMetrics` takes 1 options object with 2 entries, a timeout for how | ||
often the probe should be fired and a registry to which metrics should be | ||
registered. By default probes are launched every 10 seconds, but this can be | ||
modified like this: | ||
`collectDefaultMetrics` takes 1 options object with 3 entries, a timeout for how | ||
often the probe should be fired, an optional prefix for metric names | ||
and a registry to which metrics should be registered. By default probes are | ||
launched every 10 seconds, but this can be modified like this: | ||
@@ -81,2 +81,13 @@ ```js | ||
To prefix metric names with your own arbitrary string, pass in a `prefix`: | ||
```js | ||
const client = require('prom-client'); | ||
const collectDefaultMetrics = client.collectDefaultMetrics; | ||
// Probe every 5th second. | ||
collectDefaultMetrics({ prefix: 'my_application_' }); | ||
``` | ||
You can get the full list of metrics by inspecting | ||
@@ -83,0 +94,0 @@ `client.collectDefaultMetrics.metricsList`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105027
2548
510