Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: siimon/prom-client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v11.0.0
Choose a base ref
...
head repository: siimon/prom-client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v11.1.0
Choose a head ref
  • 8 commits
  • 30 files changed
  • 6 contributors

Commits on Mar 10, 2018

  1. 11.0.0

    siimon committed Mar 10, 2018
    Copy the full SHA
    50c340d View commit details

Commits on Mar 11, 2018

  1. upgrade dependencies (#175)

    SimenB authored Mar 11, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bb09c6d View commit details

Commits on Apr 12, 2018

  1. Fix startTimer utility to not mutate passed startLabels object (#188

    )
    
    Fixes #176.
    kdk authored and siimon committed Apr 12, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    SimenB Simen Bekkhus
    Copy the full SHA
    1d4123b View commit details

Commits on May 8, 2018

  1. Validate labels on inc on counters (#190)

    * Validate labels when inc is called on counter
    
    * Document changes
    
    * Update CHANGELOG.md
    
    * Fix typo
    eLVas authored and SimenB committed May 8, 2018
    Copy the full SHA
    f99a879 View commit details

Commits on Jun 29, 2018

  1. Fix aggregator method being lost when aggregating several registries (#…

    …193)
    
    * fix aggregator method being lost
    
    * update tests with aggregator functions in results
    
    * Update CHANGELOG.md
    Ratismal authored and siimon committed Jun 29, 2018
    Copy the full SHA
    cb7f8e4 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    SimenB Simen Bekkhus
    Copy the full SHA
    6f517d8 View commit details
  3. Prepare for 11.1.0

    siimon committed Jun 29, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    SimenB Simen Bekkhus
    Copy the full SHA
    e32827d View commit details
  4. 11.1.0

    siimon committed Jun 29, 2018
    Copy the full SHA
    ea992c2 View commit details
24 changes: 20 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -9,14 +9,30 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Breaking

* Fixed `gauge.setToCurrentTime()` to use seconds instead of milliseconds
* This conforms to Prometheus [best practices](https://prometheus.io/docs/practices/naming/#base-units)
* Dropped support for node 4

### Changed

### Added

## [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

### Breaking

* Fixed `gauge.setToCurrentTime()` to use seconds instead of milliseconds
* This conforms to Prometheus
[best practices](https://prometheus.io/docs/practices/naming/#base-units)
* Dropped support for node 4

## [10.2.3] - 2018-02-28

### Breaking
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -51,10 +51,10 @@ In addition, some Node-specific metrics are included, such as event loop lag,
active handles and Node.js version. See what metrics there are in
[lib/metrics](lib/metrics).

`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:

```js
const client = require('prom-client');
@@ -77,6 +77,17 @@ const register = new Registry();
collectDefaultMetrics({ register });
```

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
`client.collectDefaultMetrics.metricsList`.

3 changes: 3 additions & 0 deletions lib/counter.js
Original file line number Diff line number Diff line change
@@ -143,6 +143,9 @@ const inc = function(labels, hash) {
throw new Error('It is not possible to decrease a counter');
}

labels = labels || {};
validateLabels(this.labelNames, labels);

const incValue = value === null || value === undefined ? 1 : value;

this.hashMap = createValue(this.hashMap, incValue, timestamp, labels, hash);
2 changes: 1 addition & 1 deletion lib/defaultMetrics.js
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ module.exports = function startDefaultMetrics(config) {
);
}

return defaultMetric(normalizedConfig.register);
return defaultMetric(normalizedConfig.register, config);
});

function updateAllMetrics() {
2 changes: 1 addition & 1 deletion lib/gauge.js
Original file line number Diff line number Diff line change
@@ -184,7 +184,7 @@ function startTimer(startLabels) {
return endLabels => {
const delta = process.hrtime(start);
this.set(
Object.assign(startLabels || {}, endLabels),
Object.assign({}, startLabels, endLabels),
delta[0] + delta[1] / 1e9
);
};
2 changes: 1 addition & 1 deletion lib/histogram.js
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ function startTimer(startLabels) {
return endLabels => {
const delta = process.hrtime(start);
this.observe(
Object.assign(startLabels || {}, endLabels),
Object.assign({}, startLabels, endLabels),
delta[0] + delta[1] / 1e9
);
};
3 changes: 2 additions & 1 deletion lib/metricAggregators.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,8 @@ function AggregatorFactory(aggregatorFn) {
help: metrics[0].help,
name: metrics[0].name,
type: metrics[0].type,
values: []
values: [],
aggregator: metrics[0].aggregator
};
// Gather metrics by metricName and labels.
const byLabels = new util.Grouper();
6 changes: 4 additions & 2 deletions lib/metrics/eventLoopLag.js
Original file line number Diff line number Diff line change
@@ -12,9 +12,11 @@ function reportEventloopLag(start, gauge) {
gauge.set(seconds, Date.now());
}

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.',
registers: registry ? [registry] : undefined,
aggregator: 'average'
9 changes: 5 additions & 4 deletions lib/metrics/heapSizeAndUsed.js
Original file line number Diff line number Diff line change
@@ -7,20 +7,21 @@ const NODEJS_HEAP_SIZE_TOTAL = 'nodejs_heap_size_total_bytes';
const NODEJS_HEAP_SIZE_USED = 'nodejs_heap_size_used_bytes';
const NODEJS_EXTERNAL_MEMORY = 'nodejs_external_memory_bytes';

module.exports = registry => {
module.exports = (registry, config = {}) => {
if (typeof process.memoryUsage !== 'function') {
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.',
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.',
registers
});
@@ -29,7 +30,7 @@ module.exports = registry => {
const usage = safeMemoryUsage();
if (usage && usage.external) {
externalMemUsed = new Gauge({
name: NODEJS_EXTERNAL_MEMORY,
name: namePrefix + NODEJS_EXTERNAL_MEMORY,
help: 'Nodejs external memory size in bytes.',
registers
});
5 changes: 3 additions & 2 deletions lib/metrics/heapSpacesSizeAndUsed.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ METRICS.forEach(metricType => {
NODEJS_HEAP_SIZE[metricType] = `nodejs_heap_space_size_${metricType}_bytes`;
});

module.exports = registry => {
module.exports = (registry, config = {}) => {
if (
typeof v8 === 'undefined' ||
typeof v8.getHeapSpaceStatistics !== 'function'
@@ -27,12 +27,13 @@ module.exports = registry => {
}

const registers = registry ? [registry] : undefined;
const namePrefix = config.prefix ? config.prefix : '';

const gauges = {};

METRICS.forEach(metricType => {
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.`,
labelNames: ['space'],
registers
12 changes: 7 additions & 5 deletions lib/metrics/osMemoryHeap.js
Original file line number Diff line number Diff line change
@@ -6,9 +6,11 @@ const safeMemoryUsage = require('./helpers/safeMemoryUsage');

const PROCESS_RESIDENT_MEMORY = 'process_resident_memory_bytes';

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.',
registers: registry ? [registry] : undefined
});
@@ -23,10 +25,10 @@ function notLinuxVariant(registry) {
};
}

module.exports = registry =>
module.exports = (registry, config) =>
process.platform === 'linux'
? linuxVariant(registry)
: notLinuxVariant(registry);
? linuxVariant(registry, config)
: notLinuxVariant(registry, config);

module.exports.metricNames =
process.platform === 'linux'
10 changes: 6 additions & 4 deletions lib/metrics/osMemoryHeapLinux.js
Original file line number Diff line number Diff line change
@@ -31,20 +31,22 @@ function structureOutput(input) {
return returnValue;
}

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.',
registers
});
const virtualMemGauge = new Gauge({
name: PROCESS_VIRTUAL_MEMORY,
name: namePrefix + PROCESS_VIRTUAL_MEMORY,
help: 'Virtual memory size in bytes.',
registers
});
const heapSizeMemGauge = new Gauge({
name: PROCESS_HEAP,
name: namePrefix + PROCESS_HEAP,
help: 'Process heap size in bytes.',
registers
});
9 changes: 5 additions & 4 deletions lib/metrics/processCpuTotal.js
Original file line number Diff line number Diff line change
@@ -5,26 +5,27 @@ const PROCESS_CPU_USER_SECONDS = 'process_cpu_user_seconds_total';
const PROCESS_CPU_SYSTEM_SECONDS = 'process_cpu_system_seconds_total';
const PROCESS_CPU_SECONDS = 'process_cpu_seconds_total';

module.exports = registry => {
module.exports = (registry, config = {}) => {
// Don't do anything if the function doesn't exist (introduced in node@6.1.0)
if (typeof process.cpuUsage !== 'function') {
return () => {};
}

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.',
registers
});
const cpuSystemUsageCounter = new Counter({
name: PROCESS_CPU_SYSTEM_SECONDS,
name: namePrefix + PROCESS_CPU_SYSTEM_SECONDS,
help: 'Total system CPU time spent in seconds.',
registers
});
const cpuUsageCounter = new Counter({
name: PROCESS_CPU_SECONDS,
name: namePrefix + PROCESS_CPU_SECONDS,
help: 'Total user and system CPU time spent in seconds.',
registers
});
6 changes: 4 additions & 2 deletions lib/metrics/processHandles.js
Original file line number Diff line number Diff line change
@@ -4,14 +4,16 @@ const Gauge = require('../gauge');

const NODEJS_ACTIVE_HANDLES = 'nodejs_active_handles_total';

module.exports = registry => {
module.exports = (registry, config = {}) => {
// Don't do anything if the function is removed in later nodes (exists in node@6)
if (typeof process._getActiveHandles !== 'function') {
return () => {};
}

const namePrefix = config.prefix ? config.prefix : '';

const gauge = new Gauge({
name: NODEJS_ACTIVE_HANDLES,
name: namePrefix + NODEJS_ACTIVE_HANDLES,
help: 'Number of active handles.',
registers: registry ? [registry] : undefined
});
7 changes: 5 additions & 2 deletions lib/metrics/processMaxFileDescriptors.js
Original file line number Diff line number Diff line change
@@ -5,14 +5,17 @@ const fs = require('fs');

const PROCESS_MAX_FDS = 'process_max_fds';

module.exports = registry => {
module.exports = (registry, config = {}) => {
let isSet = false;

if (process.platform !== 'linux') {
return () => {};
}

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.',
registers: registry ? [registry] : undefined
});
6 changes: 4 additions & 2 deletions lib/metrics/processOpenFileDescriptors.js
Original file line number Diff line number Diff line change
@@ -5,13 +5,15 @@ const fs = require('fs');

const PROCESS_OPEN_FDS = 'process_open_fds';

module.exports = registry => {
module.exports = (registry, config) => {
if (process.platform !== 'linux') {
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.',
registers: registry ? [registry] : undefined
});
6 changes: 4 additions & 2 deletions lib/metrics/processRequests.js
Original file line number Diff line number Diff line change
@@ -4,14 +4,16 @@ const Gauge = require('../gauge');

const NODEJS_ACTIVE_REQUESTS = 'nodejs_active_requests_total';

module.exports = registry => {
module.exports = (registry, config = {}) => {
// Don't do anything if the function is removed in later nodes (exists in node@6)
if (typeof process._getActiveRequests !== 'function') {
return () => {};
}

const namePrefix = config.prefix ? config.prefix : '';

const gauge = new Gauge({
name: NODEJS_ACTIVE_REQUESTS,
name: namePrefix + NODEJS_ACTIVE_REQUESTS,
help: 'Number of active requests.',
registers: registry ? [registry] : undefined
});
6 changes: 4 additions & 2 deletions lib/metrics/processStartTime.js
Original file line number Diff line number Diff line change
@@ -5,9 +5,11 @@ const nowInSeconds = Math.round(Date.now() / 1000 - process.uptime());

const PROCESS_START_TIME = 'process_start_time_seconds';

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.',
registers: registry ? [registry] : undefined,
aggregator: 'omit'
6 changes: 4 additions & 2 deletions lib/metrics/version.js
Original file line number Diff line number Diff line change
@@ -9,9 +9,11 @@ const versionSegments = version

const NODE_VERSION_INFO = 'nodejs_version_info';

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.',
labelNames: ['version', 'major', 'minor', 'patch'],
registers: registry ? [registry] : undefined,
2 changes: 1 addition & 1 deletion lib/summary.js
Original file line number Diff line number Diff line change
@@ -183,7 +183,7 @@ function startTimer(startLabels) {
return endLabels => {
const delta = process.hrtime(start);
this.observe(
Object.assign(startLabels || {}, endLabels),
Object.assign({}, startLabels, endLabels),
delta[0] + delta[1] / 1e9
);
};
4 changes: 1 addition & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -86,9 +86,7 @@ exports.printDeprecationObjectConstructor = () => {

exports.printDeprecationCollectDefaultMetricsNumber = timeout => {
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} })\`.`
);
};

Loading