Socket
Socket
Sign inDemoInstall

prom-client

Package Overview
Dependencies
Maintainers
2
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prom-client - npm Package Compare versions

Comparing version 10.2.2 to 10.2.3

126

CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Breaking
### Changed
### Added
## [10.2.3] - 2018-02-28
### Breaking
### Changed
* Fixed issue that `registry.getMetricsAsJSON()` ignores registry default labels
### Added
## [10.2.2] - 2017-11-02
### Changed
- Fixed invalid `process_virtual_memory_bytes` reported under linux
* Fixed invalid `process_virtual_memory_bytes` reported under linux
## [10.2.1] - 2017-10-27
### Changed
- Only resolve/reject `clusterMetrics` promise if no callback is provided
* Only resolve/reject `clusterMetrics` promise if no callback is provided
## [10.2.0] - 2017-10-16
### Changed
- Don't add event listeners if cluster module is not used.
- Fixed issue with counters having extra records when using empty labels
* Don't add event listeners if cluster module is not used.
* Fixed issue with counters having extra records when using empty labels
### Added
- Added `reset` to Counter and Gauge
- Added `resetMetrics` to register to calling `reset` of all metric instances
* Added `reset` to Counter and Gauge
* Added `resetMetrics` to register to calling `reset` of all metric instances
## [10.1.1] - 2017-09-26
### Changed
- Update TypeScript definitions and JSDoc comments to match JavaScript sources
- Fix lexical scope of `arguments` in cluster code
* Update TypeScript definitions and JSDoc comments to match JavaScript sources
* Fix lexical scope of `arguments` in cluster code
## [10.1.0] - 2017-09-04
### Added
- Support aggregating metrics across workers in a Node.js cluster.
* Support aggregating metrics across workers in a Node.js cluster.
## [10.0.4] - 2017-08-22
### Changed
- Include invalid values in the error messages
* Include invalid values in the error messages
## [10.0.3] - 2017-08-07
### Added
- Added registerMetric to definitions file
* Added registerMetric to definitions file
### Changed
- Fixed typing of DefaultMetricsCollectorConfiguration in definitions file
- Don't pass timestamps through to pushgateway by default
* Fixed typing of DefaultMetricsCollectorConfiguration in definitions file
* Don't pass timestamps through to pushgateway by default
## [10.0.2] - 2017-07-07
### Changed
- Don't poll default metrics every single tick
* Don't poll default metrics every single tick
## [10.0.1] - 2017-07-06
### Added
- Metrics should be initialized to 0 when there are no labels
* Metrics should be initialized to 0 when there are no labels
## [10.0.0] - 2017-07-04
### Breaking
- Print deprecation warning when metrics are constructed using non-objects
- Print deprecation warning when `collectDefaultMetrics` is called with a number
* Print deprecation warning when metrics are constructed using non-objects
* Print deprecation warning when `collectDefaultMetrics` is called with a number
### Added
- Ability to set default labels by registry
- Allow passing in `registry` as second argument to `collectDefaultMetrics` to use that instead of the default registry
* Ability to set default labels by registry
* Allow passing in `registry` as second argument to `collectDefaultMetrics` to
use that instead of the default registry
### Changed
- Convert code base to ES2015 code (node 4)
- add engines field to package.json
- Use object shorthand
- Remove `util-extend` in favor of `Object.assign`
- Arrow functions over binding or putting `this` in a variable
- Use template strings
- `prototype` -> `class`
* Convert code base to ES2015 code (node 4)
* add engines field to package.json
* Use object shorthand
* Remove `util-extend` in favor of `Object.assign`
* Arrow functions over binding or putting `this` in a variable
* Use template strings
* `prototype` -> `class`
## [9.1.1] - 2017-06-17
### Changed
- Don't set timestamps for metrics that are never updated
* Don't set timestamps for metrics that are never updated
## [9.1.0] - 2017-06-07
### Added
- Ability to merge registries
* Ability to merge registries
### Changed
- Correct typedefs for object constructor of metrics
* Correct typedefs for object constructor of metrics
## [9.0.0] - 2017-05-06
### Added
- Support for multiple registers
- Support for object literals in metric constructors
- Timestamp support
* Support for multiple registers
* Support for object literals in metric constructors
* Timestamp support
### Changed
- Collection of default metrics is now disabled by default. Start collection by running `collectDefaultMetrics()`.
* Collection of default metrics is now disabled by default. Start collection by
running `collectDefaultMetrics()`.
### Deprecated
- Creating metrics with one argument per parameter - use object literals instead.
* Creating metrics with one argument per parameter - use object literals
instead.
[Unreleased]: https://github.com/siimon/prom-client/compare/v10.2.2...HEAD
[unreleased]: https://github.com/siimon/prom-client/compare/v10.2.2...HEAD
[10.2.2]: https://github.com/siimon/prom-client/compare/v10.2.1...v10.2.2

@@ -97,0 +151,0 @@ [10.2.1]: https://github.com/siimon/prom-client/compare/v10.2.0...v10.2.1

@@ -135,4 +135,4 @@ /**

* makeExpensiveXHRRequest(function(err, res) {
* end(); //Observe the duration of expensiveXHRRequest
* });
* end(); //Observe the duration of expensiveXHRRequest
* });
*/

@@ -139,0 +139,0 @@ startTimer(labels) {

@@ -85,3 +85,17 @@ 'use strict';

getMetricsAsJSON() {
return this.getMetricsAsArray().map(metric => metric.get());
return this.getMetricsAsArray().map(metric => {
const item = metric.get();
if (!item.values) {
return item;
}
item.values = item.values.map(val =>
// Avoid mutation and merge metric labels with registry default labels
Object.assign({}, val, {
labels: Object.assign({}, this._defaultLabels, val.labels)
})
);
return item;
});
}

@@ -88,0 +102,0 @@

@@ -89,3 +89,5 @@ '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
} })\`.`
);

@@ -92,0 +94,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": "10.2.2",
"description": "Client for prometheus",
"main": "index.js",
"files": [
"lib/",
"index.js",
"index.d.ts"
],
"engines": {
"node": ">=4"
},
"scripts": {
"test": "npm run lint && npm run compile-typescript && npm run test-unit",
"lint": "eslint .",
"test-unit": "jest",
"compile-typescript": "tsc index.d.ts --noImplicitAny",
"precommit": "lint-staged"
},
"repository": {
"type": "git",
"url": "git@github.com:siimon/prom-client.git"
},
"keywords": [
"Prometheus",
"Metrics",
"Client"
],
"author": "Simon Nyberg",
"license": "Apache-2.0",
"homepage": "https://github.com/siimon/prom-client",
"devDependencies": {
"eslint": "^4.1.1",
"eslint-plugin-prettier": "^2.1.2",
"express": "^4.13.3",
"husky": "^0.14.3",
"jest": "^21.2.1",
"lint-staged": "^4.0.0",
"lolex": "^2.1.3",
"prettier": "1.7.4",
"typescript": "^2.5.2"
},
"dependencies": {
"tdigest": "^0.1.1"
},
"types": "./index.d.ts",
"jest": {
"testEnvironment": "node",
"testRegex": ".*Test\\.js$"
},
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
],
"*.ts": [
"prettier --write --use-tabs --single-quote",
"git add"
]
}
"name": "prom-client",
"version": "10.2.3",
"description": "Client for prometheus",
"main": "index.js",
"files": [
"lib/",
"index.js",
"index.d.ts"
],
"engines": {
"node": ">=4"
},
"scripts": {
"test": "npm run lint && npm run compile-typescript && npm run test-unit",
"lint": "eslint .",
"test-unit": "jest",
"compile-typescript": "tsc index.d.ts --noImplicitAny",
"precommit": "lint-staged"
},
"repository": {
"type": "git",
"url": "git@github.com:siimon/prom-client.git"
},
"keywords": [
"Prometheus",
"Metrics",
"Client"
],
"author": "Simon Nyberg",
"license": "Apache-2.0",
"homepage": "https://github.com/siimon/prom-client",
"devDependencies": {
"eslint": "^4.1.1",
"eslint-plugin-prettier": "^2.1.2",
"express": "^4.13.3",
"husky": "^0.14.3",
"jest": "^21.2.1",
"lint-staged": "^5.0.0",
"lolex": "^2.1.3",
"prettier": "1.8.2",
"typescript": "^2.5.2"
},
"dependencies": {
"tdigest": "^0.1.1"
},
"types": "./index.d.ts",
"jest": {
"testEnvironment": "node",
"testRegex": ".*Test\\.js$"
},
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
],
"*.{ts,md,json}": [
"prettier --write",
"git add"
],
".eslintrc": [
"prettier --write",
"git add"
]
},
"prettier": {
"singleQuote": true,
"useTabs": true,
"overrides": [
{
"files": "*.md",
"options": {
"useTabs": false
}
},
{
"files": ".eslintrc",
"options": {
"parser": "json"
}
}
]
}
}
# 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)
A prometheus client for node.js that supports histogram, summaries, gauges and counters.
A prometheus client for node.js that supports histogram, summaries, gauges and
counters.
### Usage
See example folder for a sample usage. The library does not bundle any web framework, to expose the metrics just return the `metrics()` function in the registry.
See example folder for a sample usage. The library does not bundle any web
framework, to expose the metrics just return the `metrics()` function in the
registry.
#### Usage with Node.js's `cluster` module
Node.js's `cluster` module spawns multiple processes and hands off socket connections to those workers. Returning metrics from a worker's local registry will only reveal that individual worker's metrics, which is generally undesirable. To solve this, you can aggregate all of the workers' metrics in the master process. See `example/cluster.js` for an example.
Node.js's `cluster` module spawns multiple processes and hands off socket
connections to those workers. Returning metrics from a worker's local registry
will only reveal that individual worker's metrics, which is generally
undesirable. To solve this, you can aggregate all of the workers' metrics in the
master process. See `example/cluster.js` for an example.
Default metrics use sensible aggregation methods. Custom metrics are summed across workers by default. To use a different aggregation method, set the `aggregator` property in the metric config to one of 'sum', 'first', 'min', 'max', 'average' or 'omit'. (See `lib/metrics/version.js` for an example.)
Default metrics use sensible aggregation methods. Custom metrics are summed
across workers by default. To use a different aggregation method, set the
`aggregator` property in the metric config to one of 'sum', 'first', 'min',
'max', 'average' or 'omit'. (See `lib/metrics/version.js` for an example.)
If you need to expose metrics about an individual worker, you can include a value that is unique to the worker (such as the worker ID or process ID) in a label. (See `example/server.js` for an example using `worker_${cluster.worker.id}` as a label value.)
If you need to expose metrics about an individual worker, you can include a
value that is unique to the worker (such as the worker ID or process ID) in a
label. (See `example/server.js` for an example using
`worker_${cluster.worker.id}` as a label value.)
Metrics are aggregated from the global registry by default. To use a different registry, call `client.AggregatorRegistry.setRegistries(registryOrArrayOfRegistries)` from the worker processes.
Metrics are aggregated from the global registry by default. To use a different
registry, call
`client.AggregatorRegistry.setRegistries(registryOrArrayOfRegistries)` from the
worker processes.

@@ -31,9 +47,12 @@ ### API

NOTE: Some of the metrics, concerning File Descriptors and Memory, are only available on Linux.
NOTE: Some of the metrics, concerning File Descriptors and Memory, are only
available on Linux.
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
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
`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:

@@ -48,3 +67,3 @@

collectDefaultMetrics({ timeout: 5000 });
````
```

@@ -61,10 +80,13 @@ To register metrics to another registry, pass it in as `register`:

collectDefaultMetrics({ register });
````
```
You can get the full list of metrics by inspecting `client.collectDefaultMetrics.metricsList`.
You can get the full list of metrics by inspecting
`client.collectDefaultMetrics.metricsList`.
`collectDefaultMetrics` returns an identification when invoked, which is a reference to the `Timer` used to keep the probes going. This can be
passed to `clearInterval` in order to stop all probes.
`collectDefaultMetrics` returns an identification when invoked, which is a
reference to the `Timer` used to keep the probes going. This can be passed to
`clearInterval` in order to stop all probes.
NOTE: Existing intervals are automatically cleared when calling `collectDefaultMetrics`.
NOTE: Existing intervals are automatically cleared when calling
`collectDefaultMetrics`.

@@ -81,10 +103,12 @@ ```js

clearInterval(interval);
````
```
NOTE: `unref` is called on the `interval` internally, so it will not keep your node process going indefinitely if it's the only thing
keeping it from shutting down.
NOTE: `unref` is called on the `interval` internally, so it will not keep your
node process going indefinitely if it's the only thing keeping it from shutting
down.
##### Stop polling default metrics
To stop collecting the default metrics, you have to call the function and pass it to `clearInterval`.
To stop collecting the default metrics, you have to call the function and pass
it to `clearInterval`.

@@ -106,3 +130,6 @@ ```js

const client = require('prom-client');
const counter = new client.Counter({ name: 'metric_name', help: 'metric_help' });
const counter = new client.Counter({
name: 'metric_name',
help: 'metric_help'
});
counter.inc(); // Inc with 1

@@ -133,2 +160,3 @@ counter.inc(10); // Inc with 10

```
A gauge can be reset manually. This removes the label-values combinations and

@@ -149,3 +177,3 @@ initializes to 0.

xhrRequest(function(err, res) {
end(); // Sets value to xhrRequests duration in seconds
end(); // Sets value to xhrRequests duration in seconds
});

@@ -160,11 +188,24 @@ ```

The defaults buckets are intended to cover usual web/rpc requests, this can however be overriden.
The defaults buckets are intended to cover usual web/rpc requests, this can
however be overriden.
```js
const client = require('prom-client');
new client.Histogram({ name: 'metric_name', help: 'metric_help', buckets: [ 0.10, 5, 15, 50, 100, 500 ] });
new client.Histogram({
name: 'metric_name',
help: 'metric_help',
buckets: [0.1, 5, 15, 50, 100, 500]
});
```
You can include all label names as a property as well.
```js
const client = require('prom-client');
new client.Histogram({ name: 'metric_name', help: 'metric_help', labelNames: [ 'status_code' ], buckets: [ 0.10, 5, 15, 50, 100, 500 ] });
new client.Histogram({
name: 'metric_name',
help: 'metric_help',
labelNames: ['status_code'],
buckets: [0.1, 5, 15, 50, 100, 500]
});
```

@@ -176,3 +217,6 @@

const client = require('prom-client');
const histogram = new client.Histogram({ name: 'metric_name', help: 'metric_help' });
const histogram = new client.Histogram({
name: 'metric_name',
help: 'metric_help'
});
histogram.observe(10); // Observe value in histogram

@@ -182,11 +226,13 @@ ```

Utility to observe request durations
```js
const end = histogram.startTimer();
xhrRequest(function(err, res) {
end(); // Observes the value to xhrRequests duration in seconds
end(); // Observes the value to xhrRequests duration in seconds
});
```
A Histogram can be reset manually. This removes the label-values combinations and
reinitializes the observations.
A Histogram can be reset manually. This removes the label-values combinations
and reinitializes the observations.
```js

@@ -202,7 +248,12 @@ histogram.reset();

The default percentiles are: 0.01, 0.05, 0.5, 0.9, 0.95, 0.99, 0.999. But they can be overriden like this:
The default percentiles are: 0.01, 0.05, 0.5, 0.9, 0.95, 0.99, 0.999. But they
can be overriden like this:
```js
const client = require('prom-client');
new client.Summary({ name: 'metric_name', help: 'metric_help', percentiles: [ 0.01, 0.1, 0.9, 0.99 ] });
new client.Summary({
name: 'metric_name',
help: 'metric_help',
percentiles: [0.01, 0.1, 0.9, 0.99]
});
```

@@ -214,3 +265,6 @@

const client = require('prom-client');
const summary = new client.Summary({ name: 'metric_name', help: 'metric_help' });
const summary = new client.Summary({
name: 'metric_name',
help: 'metric_help'
});
summary.observe(10);

@@ -220,6 +274,7 @@ ```

Utility to observe request durations
```js
const end = summary.startTimer();
xhrRequest(function(err, res) {
end(); // Observes the value to xhrRequests duration in seconds
end(); // Observes the value to xhrRequests duration in seconds
});

@@ -237,6 +292,13 @@ ```

All metrics can take a labelNames property in the configuration object. All labelNames that the metric support needs to be declared here. There are 2 ways to add values to the labels
All metrics can take a labelNames property in the configuration object. All
labelNames that the metric support needs to be declared here. There are 2 ways
to add values to the labels
```js
const client = require('prom-client');
const gauge = new client.Gauge({ name: 'metric_name', help: 'metric_help', labelNames: [ 'method', 'statusCode' ] });
const gauge = new client.Gauge({
name: 'metric_name',
help: 'metric_help',
labelNames: ['method', 'statusCode']
});

@@ -247,11 +309,13 @@ gauge.set({ method: 'GET', statusCode: '200' }, 100); // 1st version, Set value 100 with method set to GET and statusCode to 200

It is also possible to use timers with labels, both before and after the timer is created:
It is also possible to use timers with labels, both before and after the timer
is created:
```js
const end = startTimer({ method: 'GET' }); // Set method to GET, we don't know statusCode yet
xhrRequest(function(err, res) {
if (err) {
end({ statusCode: '500' }); // Sets value to xhrRequest duration in seconds with statusCode 500
} else {
end({ statusCode: '200' }); // Sets value to xhrRequest duration in seconds with statusCode 200
}
if (err) {
end({ statusCode: '500' }); // Sets value to xhrRequest duration in seconds with statusCode 500
} else {
end({ statusCode: '200' }); // Sets value to xhrRequest duration in seconds with statusCode 200
}
});

@@ -263,5 +327,6 @@ ```

Static labels may be applied to every metric emitted by a registry:
```js
const client = require('prom-client');
const defaultLabels = { serviceName: "api-v1" };
const defaultLabels = { serviceName: 'api-v1' };
client.register.setDefaultLabels(defaultLabels);

@@ -271,2 +336,3 @@ ```

This will output metrics in the following way:
```

@@ -284,4 +350,5 @@ # HELP process_resident_memory_bytes Resident memory size in bytes.

Counter and gauge metrics can take a timestamp argument after the value argument.
This argument must be a Date or a number (milliseconds since Unix epoch, i.e. 1970-01-01 00:00:00 UTC, excluding leap seconds).
Counter and gauge metrics can take a timestamp argument after the value
argument. This argument must be a Date or a number (milliseconds since Unix
epoch, i.e. 1970-01-01 00:00:00 UTC, excluding leap seconds).

@@ -296,3 +363,2 @@ ```js

counter.inc(1, new Date()); // Increment counter with timestamp
```

@@ -302,9 +368,14 @@

By default, metrics are automatically registered to the global registry (located at `require('prom-client').register`).
You can prevent this by setting last parameter when creating the metric to `false` (depending on metric, this might be 4th or 5th parameter).
By default, metrics are automatically registered to the global registry (located
at `require('prom-client').register`). You can prevent this by setting last
parameter when creating the metric to `false` (depending on metric, this might
be 4th or 5th parameter).
Using non-global registries requires creating Registry instance and adding it inside `registers` inside the configuration object. Alternatively
you can pass an empty `registers` array and register it manually.
Using non-global registries requires creating Registry instance and adding it
inside `registers` inside the configuration object. Alternatively you can pass
an empty `registers` array and register it manually.
Registry has a `merge` function that enables you to expose multiple registries on the same endpoint. If the same metric name exists in both registries, an error will be thrown.
Registry has a `merge` function that enables you to expose multiple registries
on the same endpoint. If the same metric name exists in both registries, an
error will be thrown.

@@ -314,4 +385,12 @@ ```js

const registry = new client.Registry();
const counter = new client.Counter({name: 'metric_name', help: 'metric_help', registers: [ registry ]});
const histogram = new client.Histogram({name: 'metric_name', help: 'metric_help', registers: [ ]});
const counter = new client.Counter({
name: 'metric_name',
help: 'metric_help',
registers: [registry]
});
const histogram = new client.Histogram({
name: 'metric_name',
help: 'metric_help',
registers: []
});
registry.registerMetric(histogram);

@@ -323,3 +402,4 @@ counter.inc();

If you want to use multiple or non-default registries with the Node.js `cluster` module, you will need to set the registry/registries to aggregate from:
If you want to use multiple or non-default registries with the Node.js `cluster`
module, you will need to set the registry/registries to aggregate from:

@@ -335,22 +415,28 @@ ```js

You can get all metrics by running `register.metrics()`, which will output a string for prometheus to consume.
You can get all metrics by running `register.metrics()`, which will output a
string for prometheus to consume.
`register.metrics()` takes an optional object with a `timestamps` field. Setting this to false will strip timestamps from the string.
`register.metrics()` takes an optional object with a `timestamps` field. Setting
this to false will strip timestamps from the string.
##### Getting a single metric for Prometheus displaying
If you need to output a single metric for Prometheus, you can use `register.getSingleMetricAsString(*name of metric*)`, it will output a string for Prometheus to consume.
If you need to output a single metric for Prometheus, you can use
`register.getSingleMetricAsString(*name of metric*)`, it will output a string
for Prometheus to consume.
##### Getting a single metric
If you need to get a reference to a previously registered metric, you can use `register.getSingleMetric(*name of metric*)`.
If you need to get a reference to a previously registered metric, you can use
`register.getSingleMetric(*name of metric*)`.
##### Removing metrics
You can remove all metrics by calling `register.clear()`. You can also remove a single metric by calling
`register.removeSingleMetric(*name of metric*)`.
You can remove all metrics by calling `register.clear()`. You can also remove a
single metric by calling `register.removeSingleMetric(*name of metric*)`.
##### Resetting metrics
If you need to reset all metrics, you can use `register.resetMetrics()`. The metrics will remain present in the register and can be used without the need to
If you need to reset all metrics, you can use `register.resetMetrics()`. The
metrics will remain present in the register and can be used without the need to
instantiate them again, like you would need to do after `register.clear()`.

@@ -360,8 +446,16 @@

You can get aggregated metrics for all workers in a node.js cluster with `register.clusterMetrics()`. This method both returns a promise and accepts a callback, both of which resolve with a metrics string suitable for Prometheus to consume.
You can get aggregated metrics for all workers in a node.js cluster with
`register.clusterMetrics()`. This method both returns a promise and accepts a
callback, both of which resolve with a metrics string suitable for Prometheus to
consume.
```js
register.clusterMetrics()
.then(metrics => { /* ... */ })
.catch(err => { /* ... */ });
register
.clusterMetrics()
.then(metrics => {
/* ... */
})
.catch(err => {
/* ... */
});

@@ -371,3 +465,3 @@ // - or -

register.clusterMetrics((err, metrics) => {
// ...
// ...
});

@@ -378,5 +472,7 @@ ```

It is possible to push metrics via a [Pushgateway](https://github.com/prometheus/pushgateway).
It is possible to push metrics via a
[Pushgateway](https://github.com/prometheus/pushgateway).
Note that timestamps will be stripped before the metrics are pushed, since pushgateway >= 0.4 does not accept timestamps.
Note that timestamps will be stripped before the metrics are pushed, since
pushgateway >= 0.4 does not accept timestamps.

@@ -387,8 +483,12 @@ ```js

gateway.pushAdd({ jobName: 'test' }, function(err, resp, body) { }); //Add metric and overwrite old ones
gateway.push({ jobName: 'test' }, function(err, resp, body) { }); //Overwrite all metrics (use PUT)
gateway.delete({ jobName: 'test' }, function(err, resp, body) { }); //Delete all metrics for jobName
gateway.pushAdd({ jobName: 'test' }, function(err, resp, body) {}); //Add metric and overwrite old ones
gateway.push({ jobName: 'test' }, function(err, resp, body) {}); //Overwrite all metrics (use PUT)
gateway.delete({ jobName: 'test' }, function(err, resp, body) {}); //Delete all metrics for jobName
//All gateway requests can have groupings on it
gateway.pushAdd({ jobName: 'test', groupings: { key: 'value' } }, function(err, resp, body) { });
gateway.pushAdd({ jobName: 'test', groupings: { key: 'value' } }, function(
err,
resp,
body
) {});

@@ -399,6 +499,6 @@ //It's possible to extend the Pushgateway with request options from nodes core http/https library

#### Utilites
For convenience, there are 2 bucket generator functions - linear and exponential.
For convenience, there are 2 bucket generator functions - linear and
exponential.

@@ -408,18 +508,20 @@ ```js

new client.Histogram({
name: 'metric_name',
help: 'metric_help',
buckets: client.linearBuckets(0, 10, 20) //Create 20 buckets, starting on 0 and a width of 10
name: 'metric_name',
help: 'metric_help',
buckets: client.linearBuckets(0, 10, 20) //Create 20 buckets, starting on 0 and a width of 10
});
new client.Histogram({
name: 'metric_name',
help: 'metric_help',
buckets: client.exponentialBuckets(1, 2, 5) //Create 5 buckets, starting on 1 and with a factor of 2
name: 'metric_name',
help: 'metric_help',
buckets: client.exponentialBuckets(1, 2, 5) //Create 5 buckets, starting on 1 and with a factor of 2
});
```
The content-type prometheus expects is also exported as a constant, both on the `register` and from the main file of this project, called `contentType`.
The content-type prometheus expects is also exported as a constant, both on the
`register` and from the main file of this project, called `contentType`.
### Garbage Collection
To avoid dependencies in this module, GC stats are kept outside of it. If you want GC stats, you can use https://github.com/SimenB/node-prometheus-gc-stats
To avoid dependencies in this module, GC stats are kept outside of it. If you
want GC stats, you can use https://github.com/SimenB/node-prometheus-gc-stats
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc