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.4.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.5.0
Choose a head ref
  • 7 commits
  • 13 files changed
  • 4 contributors

Commits on Jun 4, 2019

  1. fix(types): incorrect return type of collectDefaultMetrics(), should …

    …be Timeout in Node (#264)
    nazar-pc authored and SimenB committed Jun 4, 2019
    Copy the full SHA
    3784984 View commit details
  2. Verified

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

    This commit was signed with the committer’s verified signature.
    SimenB Simen Bekkhus
    Copy the full SHA
    fb7fa63 View commit details
  4. Copy the full SHA
    e8fe74f View commit details
  5. Copy the full SHA
    76b5435 View commit details
  6. chore: prepare for publish

    SimenB committed Jun 4, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    SimenB Simen Bekkhus
    Copy the full SHA
    888559f View commit details
  7. 11.5.0

    SimenB committed Jun 4, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    SimenB Simen Bekkhus
    Copy the full SHA
    210960e View commit details
Showing with 1,547 additions and 2,446 deletions.
  1. +7 −4 .eslintrc
  2. +7 −0 CHANGELOG.md
  3. +11 −0 README.md
  4. +9 −1 index.d.ts
  5. +1 −0 index.js
  6. +8 −2 lib/defaultMetrics.js
  7. +13 −5 lib/metrics/heapSizeAndUsed.js
  8. +6 −2 lib/metrics/helpers/processMetricsHelpers.js
  9. +13 −5 lib/metrics/processHandles.js
  10. +1,438 −2,422 package-lock.json
  11. +6 −5 package.json
  12. +20 −0 test/defaultMetricsTest.js
  13. +8 −0 tsconfig.json
11 changes: 7 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"plugins": ["prettier"],
"extends": ["eslint:recommended", "plugin:node/recommended"],
"extends": [
"eslint:recommended",
"plugin:node/recommended",
"plugin:prettier/recommended"
],
"env": {
"node": true,
"es6": true
@@ -45,8 +49,7 @@
"as-needed",
{ "requireReturnForObjectLiteral": true }
],
"prefer-template": "error",
"prettier/prettier": "error"
"prefer-template": "error"
},
"overrides": [
{
@@ -62,7 +65,7 @@
}
},
{
"files": ["example/**/*.js","benchmarks/**/*.js"],
"files": ["example/**/*.js", "benchmarks/**/*.js"],
"rules": {
"no-console": "off"
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,13 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Added

## [11.5.0] - 2019-06-04

### Added

- Added `timestamps` toggle to `collectDefaultMetrics` options
- Export `validateMetricName`

## [11.4.0] - 2019-06-04

### Added
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -88,6 +88,17 @@ const collectDefaultMetrics = client.collectDefaultMetrics;
collectDefaultMetrics({ prefix: 'my_application_' });
```

To disable metric timestamps set `timestamps` to `false` (You can find the list of metrics that support this feature in `test/defaultMetricsTest.js`):

```js
const client = require('prom-client');

const collectDefaultMetrics = client.collectDefaultMetrics;

// Probe every 5th second.
collectDefaultMetrics({ timestamps: false });
```

You can get the full list of metrics by inspecting
`client.collectDefaultMetrics.metricsList`.

10 changes: 9 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -644,6 +644,7 @@ export function exponentialBuckets(

export interface DefaultMetricsCollectorConfiguration {
timeout?: number;
timestamps?: boolean;
register?: Registry;
prefix?: string;
}
@@ -655,7 +656,7 @@ export interface DefaultMetricsCollectorConfiguration {
*/
export function collectDefaultMetrics(
config?: DefaultMetricsCollectorConfiguration
): number;
): ReturnType<typeof setInterval>;

/**
* Configure default metrics
@@ -671,3 +672,10 @@ export interface defaultMetrics {
*/
metricsList: string[];
}

/**
* Validate a metric name
* @param name The name to validate
* @return True if the metric name is valid, false if not
*/
export function validateMetricName(name: string): boolean;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
exports.register = require('./lib/registry').globalRegistry;
exports.Registry = require('./lib/registry');
exports.contentType = require('./lib/registry').globalRegistry.contentType;
exports.validateMetricName = require('./lib/validation').validateMetricName;

exports.Counter = require('./lib/counter');
exports.Gauge = require('./lib/gauge');
10 changes: 8 additions & 2 deletions lib/defaultMetrics.js
Original file line number Diff line number Diff line change
@@ -42,7 +42,13 @@ module.exports = function startDefaultMetrics(config) {
normalizedConfig = { timeout: config };
}

normalizedConfig = Object.assign({ timeout: 10000 }, normalizedConfig);
normalizedConfig = Object.assign(
{
timestamps: true,
timeout: 10000
},
normalizedConfig
);

if (existingInterval !== null) {
clearInterval(existingInterval);
@@ -57,7 +63,7 @@ module.exports = function startDefaultMetrics(config) {
);
}

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

function updateAllMetrics() {
18 changes: 13 additions & 5 deletions lib/metrics/heapSizeAndUsed.js
Original file line number Diff line number Diff line change
@@ -40,11 +40,19 @@ module.exports = (registry, config = {}) => {
// process.memoryUsage() can throw EMFILE errors, see #67
const memUsage = safeMemoryUsage();
if (memUsage) {
const now = Date.now();
heapSizeTotal.set(memUsage.heapTotal, now);
heapSizeUsed.set(memUsage.heapUsed, now);
if (memUsage.external && externalMemUsed) {
externalMemUsed.set(memUsage.external, now);
if (config.timestamps) {
const now = Date.now();
heapSizeTotal.set(memUsage.heapTotal, now);
heapSizeUsed.set(memUsage.heapUsed, now);
if (memUsage.external && externalMemUsed) {
externalMemUsed.set(memUsage.external, now);
}
} else {
heapSizeTotal.set(memUsage.heapTotal);
heapSizeUsed.set(memUsage.heapUsed);
if (memUsage.external && externalMemUsed) {
externalMemUsed.set(memUsage.external);
}
}
}

8 changes: 6 additions & 2 deletions lib/metrics/helpers/processMetricsHelpers.js
Original file line number Diff line number Diff line change
@@ -13,10 +13,14 @@ function aggregateByObjectName(list) {
return data;
}

function updateMetrics(gauge, data) {
function updateMetrics(gauge, data, includeTimestamp) {
gauge.reset();
for (const key in data) {
gauge.set({ type: key }, data[key], Date.now());
if (includeTimestamp) {
gauge.set({ type: key }, data[key], Date.now());
} else {
gauge.set({ type: key }, data[key]);
}
}
}

18 changes: 13 additions & 5 deletions lib/metrics/processHandles.js
Original file line number Diff line number Diff line change
@@ -28,11 +28,19 @@ module.exports = (registry, config = {}) => {
registers: registry ? [registry] : undefined
});

return () => {
const handles = process._getActiveHandles();
updateMetrics(gauge, aggregateByObjectName(handles));
totalGauge.set(handles.length, Date.now());
};
const updater = config.timestamps
? () => {
const handles = process._getActiveHandles();
updateMetrics(gauge, aggregateByObjectName(handles), true);
totalGauge.set(handles.length, Date.now());
}
: () => {
const handles = process._getActiveHandles();
updateMetrics(gauge, aggregateByObjectName(handles), false);
totalGauge.set(handles.length);
};

return updater;
};

module.exports.metricNames = [
Loading