Socket
Socket
Sign inDemoInstall

prom-client

Package Overview
Dependencies
Maintainers
1
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 4.1.0 to 5.0.0

60

lib/defaultMetrics.js

@@ -14,11 +14,11 @@ 'use strict';

var metrics = {
processCpuTotal: processCpuTotal,
processStartTime: processStartTime,
osMemoryHeap: osMemoryHeap,
processOpenFileDescriptors: processOpenFileDescriptors,
processMaxFileDescriptors: processMaxFileDescriptors,
eventLoopLag: eventLoopLag,
processHandles: processHandles,
processRequests: processRequests,
heapSizeAndUsed: heapSizeAndUsed
processCpuTotal: processCpuTotal,
processStartTime: processStartTime,
osMemoryHeap: osMemoryHeap,
processOpenFileDescriptors: processOpenFileDescriptors,
processMaxFileDescriptors: processMaxFileDescriptors,
eventLoopLag: eventLoopLag,
processHandles: processHandles,
processRequests: processRequests,
heapSizeAndUsed: heapSizeAndUsed
};

@@ -28,31 +28,31 @@

module.exports = function startDefaultMetrics (disabledMetrics, interval) {
if(existingInterval !== null) {
clearInterval(existingInterval);
}
module.exports = function startDefaultMetrics(disabledMetrics, interval) {
if(existingInterval !== null) {
clearInterval(existingInterval);
}
disabledMetrics = disabledMetrics || [];
interval = interval || 10000;
disabledMetrics = disabledMetrics || [];
interval = interval || 10000;
var metricsInUse = Object.keys(metrics)
.filter(function (metric) {
return disabledMetrics.indexOf(metric) < 0;
})
.map(function (metric) {
return metrics[metric]();
});
var metricsInUse = Object.keys(metrics)
.filter(function(metric) {
return disabledMetrics.indexOf(metric) < 0;
})
.map(function(metric) {
return metrics[metric]();
});
function updateAllMetrics () {
metricsInUse.forEach(function (metric) {
metric.call();
});
}
function updateAllMetrics() {
metricsInUse.forEach(function(metric) {
metric.call();
});
}
updateAllMetrics();
updateAllMetrics();
existingInterval = setInterval(updateAllMetrics, interval).unref();
existingInterval = setInterval(updateAllMetrics, interval).unref();
return existingInterval;
return existingInterval;
};
module.exports.metricsList = Object.keys(metrics);

@@ -72,3 +72,3 @@ /**

data.map(extractBucketValuesForExport(this))
.reduce(addSumAndCountForExport(this), []);
.reduce(addSumAndCountForExport(this), []);

@@ -234,3 +234,3 @@ return {

var infLabel = extend({ le: '+Inf'}, d.data.labels);
var infLabel = extend({ le: '+Inf' }, d.data.labels);
acc.push(createValuePair(infLabel, d.data.count, histogram.name + '_bucket'));

@@ -237,0 +237,0 @@ acc.push(createValuePair(d.data.labels, d.data.sum, histogram.name + '_sum'));

@@ -5,17 +5,17 @@ 'use strict';

function reportEventloopLag(start, gauge){
var delta = process.hrtime(start);
var nanosec = delta[0] * 1e9 + delta[1];
var ms = nanosec / 1e6;
function reportEventloopLag(start, gauge) {
var delta = process.hrtime(start);
var nanosec = delta[0] * 1e9 + delta[1];
var ms = nanosec / 1e6;
gauge.set(Math.round(ms));
gauge.set(Math.round(ms));
}
module.exports = function() {
var gauge = new Gauge('node_eventloop_lag_milliseconds', 'Lag of event loop in milliseconds.');
var gauge = new Gauge('nodejs_eventloop_lag_milliseconds', 'Lag of event loop in milliseconds.');
return function() {
var start = process.hrtime();
setImmediate(reportEventloopLag, start, gauge);
};
return function() {
var start = process.hrtime();
setImmediate(reportEventloopLag, start, gauge);
};
};

@@ -5,17 +5,17 @@ 'use strict';

module.exports = function() {
if(typeof process.memoryUsage !== 'function') {
return function () {
};
}
if(typeof process.memoryUsage !== 'function') {
return function() {
};
}
var heapSizeTotal = new Gauge('process_heap_size_node_bytes', 'Process heap size from node.js in bytes.');
var heapSizeUsed = new Gauge('process_heap_size_used_bytes', 'Process heap size used in bytes.');
var heapSizeTotal = new Gauge('nodejs_heap_size_total_bytes', 'Process heap size from node.js in bytes.');
var heapSizeUsed = new Gauge('nodejs_heap_size_used_bytes', 'Process heap size used from node.js in bytes.');
return function() {
var memUsage = process.memoryUsage();
heapSizeTotal.set(memUsage.heapTotal);
heapSizeUsed.set(memUsage.heapUsed);
return function() {
var memUsage = process.memoryUsage();
heapSizeTotal.set(memUsage.heapTotal);
heapSizeUsed.set(memUsage.heapUsed);
return { total: heapSizeTotal, used: heapSizeUsed };
};
return { total: heapSizeTotal, used: heapSizeUsed };
};
};

@@ -5,15 +5,15 @@ 'use strict';

var linuxVariant = require('./osMemoryHeapLinux');
var notLinuxVariant = function () {
var residentMemGauge = new Gauge('process_resident_memory_bytes', 'Resident memory size in bytes.');
var notLinuxVariant = function() {
var residentMemGauge = new Gauge('process_resident_memory_bytes', 'Resident memory size in bytes.');
return function () {
var memoryUsage = process.memoryUsage();
return function() {
var memoryUsage = process.memoryUsage();
// I don't think the other things returned from `process.memoryUsage()` is relevant to a standard export
residentMemGauge.set(null, memoryUsage.rss);
};
// I don't think the other things returned from `process.memoryUsage()` is relevant to a standard export
residentMemGauge.set(null, memoryUsage.rss);
};
};
module.exports = function () {
return process.platform === 'linux' ? linuxVariant() : notLinuxVariant();
module.exports = function() {
return process.platform === 'linux' ? linuxVariant() : notLinuxVariant();
};

@@ -8,44 +8,44 @@ 'use strict';

function structureOutput (input) {
var returnValue = {};
function structureOutput(input) {
var returnValue = {};
input.split('\n')
.filter(function (s) {
return values.some(function (value) {
return s.indexOf(value) === 0;
});
})
.forEach(function (string) {
var split = string.split(':');
input.split('\n')
.filter(function(s) {
return values.some(function(value) {
return s.indexOf(value) === 0;
});
})
.forEach(function(string) {
var split = string.split(':');
// Get the value
var value = split[1].trim();
// Remove trailing ` kb`
value = value.substr(0, value.length - 3);
// Make it into a number in bytes bytes
value = Number(value) * 1000;
// Get the value
var value = split[1].trim();
// Remove trailing ` kb`
value = value.substr(0, value.length - 3);
// Make it into a number in bytes bytes
value = Number(value) * 1000;
returnValue[split[0]] = value;
});
returnValue[split[0]] = value;
});
return returnValue;
return returnValue;
}
module.exports = function () {
var residentMemGauge = new Gauge('process_resident_memory_bytes', 'Resident memory size in bytes.');
var virtualMemGauge = new Gauge('process_virtual_memory_bytes', 'Virtual memory size in bytes.');
var heapSizeMemGauge = new Gauge('process_heap_bytes', 'Process heap size in bytes.');
module.exports = function() {
var residentMemGauge = new Gauge('process_resident_memory_bytes', 'Resident memory size in bytes.');
var virtualMemGauge = new Gauge('process_virtual_memory_bytes', 'Virtual memory size in bytes.');
var heapSizeMemGauge = new Gauge('process_heap_bytes', 'Process heap size in bytes.');
return function () {
fs.readFile('/proc/self/status', 'utf8', function (err, status) {
if(err) {
return;
}
var structuredOutput = structureOutput(status);
return function() {
fs.readFile('/proc/self/status', 'utf8', function(err, status) {
if(err) {
return;
}
var structuredOutput = structureOutput(status);
residentMemGauge.set(null, structuredOutput.VmRSS);
virtualMemGauge.set(null, structuredOutput.VmSize);
heapSizeMemGauge.set(null, structuredOutput.VmData);
});
};
residentMemGauge.set(null, structuredOutput.VmRSS);
virtualMemGauge.set(null, structuredOutput.VmSize);
heapSizeMemGauge.set(null, structuredOutput.VmData);
});
};
};

@@ -5,19 +5,19 @@ 'use strict';

module.exports = function () {
// Don't do anything if the function doesn't exist (introduced in node@6.1.0)
if(typeof process.cpuUsage !== 'function') {
return function () {
};
}
module.exports = function() {
// Don't do anything if the function doesn't exist (introduced in node@6.1.0)
if(typeof process.cpuUsage !== 'function') {
return function() {
};
}
var cpuUserCounter = new Counter('process_cpu_seconds_total', 'Total user and system CPU time spent in seconds.');
var lastCpuUsage = null;
var cpuUserCounter = new Counter('process_cpu_seconds_total', 'Total user and system CPU time spent in seconds.');
var lastCpuUsage = null;
return function () {
var cpuUsage = process.cpuUsage(lastCpuUsage);
lastCpuUsage = cpuUsage;
var totalUsageMicros = cpuUsage.user + cpuUsage.system;
return function() {
var cpuUsage = process.cpuUsage(lastCpuUsage);
lastCpuUsage = cpuUsage;
var totalUsageMicros = cpuUsage.user + cpuUsage.system;
cpuUserCounter.inc(totalUsageMicros / 1e6);
};
cpuUserCounter.inc(totalUsageMicros / 1e6);
};
};

@@ -6,13 +6,13 @@ 'use strict';

module.exports = function() {
// Don't do anything if the function is removed in later nodes (exists in node@6)
if(typeof process._getActiveHandles !== 'function') {
return function () {
};
}
// Don't do anything if the function is removed in later nodes (exists in node@6)
if(typeof process._getActiveHandles !== 'function') {
return function() {
};
}
var gauge = new Gauge('node_active_handles_total', 'Number of active handles.');
var gauge = new Gauge('nodejs_active_handles_total', 'Number of active handles.');
return function() {
gauge.set(process._getActiveHandles().length);
};
return function() {
gauge.set(process._getActiveHandles().length);
};
};

@@ -6,21 +6,21 @@ 'use strict';

module.exports = function () {
var isSet = false;
var fileDescriptorsGauge = new Gauge('process_max_fds', 'Maximum number of open file descriptors.');
module.exports = function() {
var isSet = false;
var fileDescriptorsGauge = new Gauge('process_max_fds', 'Maximum number of open file descriptors.');
return function () {
if(isSet || process.platform !== 'linux') {
return;
}
return function() {
if(isSet || process.platform !== 'linux') {
return;
}
fs.readFile('/proc/sys/fs/file-max', 'utf8', function (err, maxFds) {
if(err) {
return;
}
fs.readFile('/proc/sys/fs/file-max', 'utf8', function(err, maxFds) {
if(err) {
return;
}
isSet = true;
isSet = true;
fileDescriptorsGauge.set(null, maxFds);
});
};
fileDescriptorsGauge.set(null, maxFds);
});
};
};

@@ -6,20 +6,20 @@ 'use strict';

module.exports = function () {
if(process !== 'linux') {
return function () {
};
}
module.exports = function() {
if(process !== 'linux') {
return function() {
};
}
var fileDescriptorsGauge = new Gauge('process_open_fds', 'Number of open file descriptors.');
var fileDescriptorsGauge = new Gauge('process_open_fds', 'Number of open file descriptors.');
return function () {
fs.readdir('/proc/self/fd', function (err, list) {
if(err) {
return;
}
return function() {
fs.readdir('/proc/self/fd', function(err, list) {
if(err) {
return;
}
// Minus 1, as this invocation created one
fileDescriptorsGauge.set(null, list.length - 1);
});
};
// Minus 1, as this invocation created one
fileDescriptorsGauge.set(null, list.length - 1);
});
};
};

@@ -6,12 +6,12 @@ 'use strict';

module.exports = function() { // Don't do anything if the function is removed in later nodes (exists in node@6)
if(typeof process._getActiveRequests !== 'function') {
return function () {
};
}
if(typeof process._getActiveRequests !== 'function') {
return function() {
};
}
var gauge = new Gauge('node_active_requests_total', 'Number of active requests.');
var gauge = new Gauge('nodejs_active_requests_total', 'Number of active requests.');
return function() {
gauge.set(process._getActiveRequests().length);
};
return function() {
gauge.set(process._getActiveRequests().length);
};
};

@@ -6,13 +6,13 @@ 'use strict';

module.exports = function () {
var cpuUserGauge = new Gauge('process_start_time_seconds', 'Start time of the process since unix epoch in seconds.');
var isSet = false;
module.exports = function() {
var cpuUserGauge = new Gauge('process_start_time_seconds', 'Start time of the process since unix epoch in seconds.');
var isSet = false;
return function () {
if(isSet) {
return;
}
cpuUserGauge.set(null, nowInSeconds);
isSet = true;
};
return function() {
if(isSet) {
return;
}
cpuUserGauge.set(null, nowInSeconds);
isSet = true;
};
};

@@ -71,3 +71,3 @@ 'use strict';

return Object.keys(groupings).map(function(key) {
return [ '/', encodeURIComponent(key), '/', encodeURIComponent(groupings[key])].join('');
return ['/', encodeURIComponent(key), '/', encodeURIComponent(groupings[key])].join('');
}).join('');

@@ -74,0 +74,0 @@ }

'use strict';
var metrics = [];
var metrics = {};
function getMetricsAsArray() {
return Object.keys(metrics)
.map(function(key) {
return metrics[key];
});
}
var getMetrics = function getMetrics() {
return metrics.reduce(function(acc, metric) {
return getMetricsAsArray().reduce(function(acc, metric) {
var item = metric.get();
var name = escapeString(item.name);
var help = escapeString(item.help);
var help = ['#', 'HELP', name, help].join(' ');
help = ['#', 'HELP', name, help].join(' ');
var type = ['#', 'TYPE', name, item.type].join(' ');

@@ -44,15 +51,23 @@

var registerMetric = function registerMetric(metricFn) {
metrics.push(metricFn);
if(metrics[metricFn.name]) {
throw new Error('A metric with the name ' + metricFn.name + ' has already been registered.');
}
metrics[metricFn.name] = metricFn;
};
var clearMetrics = function clearMetrics() {
metrics = [];
metrics = {};
};
var getMetricsAsJSON = function getMetricsAsJSON() {
return metrics.map(function(metric) {
return metric.get();
});
return getMetricsAsArray().map(function(metric) {
return metric.get();
});
};
var removeSingleMetric = function removeSingleMetric(name) {
delete metrics[name];
};
module.exports = {

@@ -62,3 +77,4 @@ registerMetric: registerMetric,

clear: clearMetrics,
getMetricsAsJSON: getMetricsAsJSON
getMetricsAsJSON: getMetricsAsJSON,
removeSingleMetric: removeSingleMetric
};

@@ -65,3 +65,3 @@ /**

extractSummariesForExport(s, summary.percentiles).forEach(function(v) {
values.push(v);
values.push(v);
});

@@ -92,3 +92,3 @@ values.push(getSumForExport(s, summary));

return percentiles.map(function (percentile) {
return percentiles.map(function(percentile) {
var percentileValue = summaryOfLabels.td.percentile(percentile);

@@ -176,3 +176,3 @@ return {

function configurePercentiles(configuredPercentiles) {
var defaultPercentiles = [ 0.01, 0.05, 0.5, 0.9, 0.95, 0.99, 0.999 ];
var defaultPercentiles = [0.01, 0.05, 0.5, 0.9, 0.95, 0.99, 0.999];
return [].concat((configuredPercentiles || defaultPercentiles)).sort(sortAscending);

@@ -179,0 +179,0 @@ }

@@ -13,3 +13,3 @@ 'use strict';

exports.incValue = function createValue(hashMap, value, labels, hash) {
if(hashMap[hash]){
if(hashMap[hash]) {
hashMap[hash].value += value || 1;

@@ -34,3 +34,3 @@ } else {

var argsAsArray = Array.prototype.slice.call(args);
return labelNames.reduce(function(acc, label, index){
return labelNames.reduce(function(acc, label, index) {
acc[label] = argsAsArray[index];

@@ -60,5 +60,7 @@ return acc;

return elems.join(',');
};
}
exports.hashObject = hashObject;
function isNumber(obj) { return !isNaN(parseFloat(obj)); };
function isNumber(obj) {
return !isNaN(parseFloat(obj));
}
{
"name": "prom-client",
"version": "4.1.0",
"version": "5.0.0",
"description": "Client for prometheus",

@@ -15,3 +15,3 @@ "main": "index.js",

"test": "npm run lint && npm run test-unit",
"lint": "eslint --ignore-pattern doc/ --ignore-path .gitignore .",
"lint": "node-version-gte-4 && eslint . || node-version-lt-4",
"test-unit": "mocha --recursive test/"

@@ -33,6 +33,7 @@ },

"chai": "^3.4.1",
"eslint": "^2.13.1",
"eslint": "^3.5.0",
"express": "^4.13.3",
"mocha": "^2.3.4",
"nock": "^8.0.0",
"node-version-check": "^2.1.1",
"sinon": "^1.17.2"

@@ -39,0 +40,0 @@ },

@@ -193,2 +193,11 @@ # 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)

#### Register
You can get all metrics by running `register.metrics()`, which will output a string for prometheus to consume.
##### Removing metrics
You can remove all metrics by calling `register.clearMetrics()`. You can also remove a single metric by calling
`register.removeSingleMetric(*name of metric*)`.
#### Pushgateway

@@ -195,0 +204,0 @@

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