prom-client
Advanced tools
Comparing version 14.0.1 to 14.1.0
@@ -37,3 +37,3 @@ // Type definitions for prom-client | ||
*/ | ||
getMetricsAsArray(): Promise<metric[]>; | ||
getMetricsAsArray(): metric[]; | ||
@@ -120,3 +120,3 @@ /** | ||
*/ | ||
export type Metric<T extends string> = | ||
export type Metric<T extends string = string> = | ||
| Counter<T> | ||
@@ -168,3 +168,3 @@ | Gauge<T> | ||
*/ | ||
export class Counter<T extends string> { | ||
export class Counter<T extends string = string> { | ||
/** | ||
@@ -238,3 +238,3 @@ * @param configuration Configuration when creating a Counter metric. Name and Help is required. | ||
*/ | ||
export class Gauge<T extends string> { | ||
export class Gauge<T extends string = string> { | ||
/** | ||
@@ -291,7 +291,9 @@ * @param configuration Configuration when creating a Gauge metric. Name and Help is mandatory | ||
/** | ||
* Start a timer where the gauges value will be the duration in seconds | ||
* Start a timer. Calling the returned function will set the gauge's value | ||
* to the observed duration in seconds. | ||
* @param labels Object with label keys and values | ||
* @return Function to invoke when timer should be stopped | ||
* @return Function to invoke when timer should be stopped. The value it | ||
* returns is the timed duration. | ||
*/ | ||
startTimer(labels?: LabelValues<T>): (labels?: LabelValues<T>) => void; | ||
startTimer(labels?: LabelValues<T>): (labels?: LabelValues<T>) => number; | ||
@@ -356,6 +358,8 @@ /** | ||
/** | ||
* Start a timer where the gauges value will be the duration in seconds | ||
* @return Function to invoke when timer should be stopped | ||
* Start a timer. Calling the returned function will set the gauge's value | ||
* to the observed duration in seconds. | ||
* @return Function to invoke when timer should be stopped. The value it | ||
* returns is the timed duration. | ||
*/ | ||
startTimer(): (labels?: LabelValues<T>) => void; | ||
startTimer(): (labels?: LabelValues<T>) => number; | ||
} | ||
@@ -373,3 +377,3 @@ } | ||
*/ | ||
export class Histogram<T extends string> { | ||
export class Histogram<T extends string = string> { | ||
/** | ||
@@ -393,5 +397,7 @@ * @param configuration Configuration when creating the Histogram. Name and Help is mandatory | ||
/** | ||
* Start a timer where the value in seconds will observed | ||
* Start a timer. Calling the returned function will observe the duration in | ||
* seconds in the histogram. | ||
* @param labels Object with label keys and values | ||
* @return Function to invoke when timer should be stopped | ||
* @return Function to invoke when timer should be stopped. The value it | ||
* returns is the timed duration. | ||
*/ | ||
@@ -446,5 +452,7 @@ startTimer(labels?: LabelValues<T>): (labels?: LabelValues<T>) => number; | ||
/** | ||
* Start a timer where the value in seconds will observed | ||
* Start a timer. Calling the returned function will observe the | ||
* duration in seconds in the histogram. | ||
* @param labels Object with label keys and values | ||
* @return Function to invoke when timer should be stopped | ||
* @return Function to invoke when timer should be stopped. The value it | ||
* returns is the timed duration. | ||
*/ | ||
@@ -474,3 +482,3 @@ startTimer(): (labels?: LabelValues<T>) => void; | ||
*/ | ||
export class Summary<T extends string> { | ||
export class Summary<T extends string = string> { | ||
/** | ||
@@ -494,7 +502,8 @@ * @param configuration Configuration when creating Summary metric. Name and Help is mandatory | ||
/** | ||
* Start a timer where the value in seconds will observed | ||
* Start a timer. Calling the returned function will observe the duration in | ||
* seconds in the summary. | ||
* @param labels Object with label keys and values | ||
* @return Function to invoke when timer should be stopped | ||
*/ | ||
startTimer(labels?: LabelValues<T>): (labels?: LabelValues<T>) => void; | ||
startTimer(labels?: LabelValues<T>): (labels?: LabelValues<T>) => number; | ||
@@ -542,7 +551,9 @@ /** | ||
/** | ||
* Start a timer where the value in seconds will observed | ||
* Start a timer. Calling the returned function will observe the | ||
* duration in seconds in the summary. | ||
* @param labels Object with label keys and values | ||
* @return Function to invoke when timer should be stopped | ||
* @return Function to invoke when timer should be stopped. The value it | ||
* returns is the timed duration. | ||
*/ | ||
startTimer(): (labels?: LabelValues<T>) => void; | ||
startTimer(): (labels?: LabelValues<T>) => number; | ||
} | ||
@@ -575,3 +586,3 @@ | ||
params: Pushgateway.Parameters, | ||
): Promise<{ resp?: unknown, body?: unknown }>; | ||
): Promise<{ resp?: unknown; body?: unknown }>; | ||
@@ -584,3 +595,3 @@ /** | ||
params: Pushgateway.Parameters, | ||
): Promise<{ resp?: unknown, body?: unknown }>; | ||
): Promise<{ resp?: unknown; body?: unknown }>; | ||
@@ -593,3 +604,3 @@ /** | ||
params: Pushgateway.Parameters, | ||
): Promise<{ resp?: unknown, body?: unknown }>; | ||
): Promise<{ resp?: unknown; body?: unknown }>; | ||
} | ||
@@ -596,0 +607,0 @@ |
@@ -14,2 +14,3 @@ 'use strict'; | ||
const processRequests = require('./metrics/processRequests'); | ||
const processResources = require('./metrics/processResources'); | ||
const heapSizeAndUsed = require('./metrics/heapSizeAndUsed'); | ||
@@ -27,2 +28,5 @@ const heapSpacesSizeAndUsed = require('./metrics/heapSpacesSizeAndUsed'); | ||
eventLoopLag, | ||
...(typeof process.getActiveResourcesInfo === 'function' | ||
? { processResources } | ||
: {}), | ||
processHandles, | ||
@@ -29,0 +33,0 @@ processRequests, |
@@ -11,2 +11,3 @@ /** | ||
setValue, | ||
setValueDelta, | ||
getLabels, | ||
@@ -54,3 +55,3 @@ hashObject, | ||
if (value === undefined) value = 1; | ||
set(this, labels, this._getValue(labels) + value); | ||
setDelta(this, labels, value); | ||
} | ||
@@ -68,3 +69,3 @@ | ||
if (value === undefined) value = 1; | ||
set(this, labels, this._getValue(labels) - value); | ||
setDelta(this, labels, -value); | ||
} | ||
@@ -100,3 +101,5 @@ | ||
const delta = process.hrtime(start); | ||
this.set(Object.assign({}, labels, endLabels), delta[0] + delta[1] / 1e9); | ||
const value = delta[0] + delta[1] / 1e9; | ||
this.set(Object.assign({}, labels, endLabels), value); | ||
return value; | ||
}; | ||
@@ -152,2 +155,12 @@ } | ||
function setDelta(gauge, labels, delta) { | ||
if (typeof delta !== 'number') { | ||
throw new TypeError(`Delta is not a valid number: ${util.format(delta)}`); | ||
} | ||
validateLabel(gauge.labelNames, labels); | ||
const hash = hashObject(labels); | ||
setValueDelta(gauge.hashMap, delta, labels, hash); | ||
} | ||
function getLabelArg(labels) { | ||
@@ -154,0 +167,0 @@ return isObject(labels) ? labels : {}; |
@@ -6,2 +6,3 @@ 'use strict'; | ||
const https = require('https'); | ||
const { gzipSync } = require('zlib'); | ||
const { globalRegistry } = require('./registry'); | ||
@@ -83,2 +84,8 @@ | ||
.then(metrics => { | ||
if ( | ||
options.headers && | ||
options.headers['Content-Encoding'] === 'gzip' | ||
) { | ||
metrics = gzipSync(metrics); | ||
} | ||
req.write(metrics); | ||
@@ -85,0 +92,0 @@ req.end(); |
@@ -146,6 +146,5 @@ /** | ||
const delta = process.hrtime(start); | ||
this.observe( | ||
Object.assign({}, startLabels, endLabels), | ||
delta[0] + delta[1] / 1e9, | ||
); | ||
const value = delta[0] + delta[1] / 1e9; | ||
this.observe(Object.assign({}, startLabels, endLabels), value); | ||
return value; | ||
}; | ||
@@ -152,0 +151,0 @@ }; |
@@ -31,2 +31,17 @@ 'use strict'; | ||
exports.setValueDelta = function setValueDelta( | ||
hashMap, | ||
deltaValue, | ||
labels, | ||
hash = '', | ||
) { | ||
const value = typeof deltaValue === 'number' ? deltaValue : 0; | ||
if (hashMap[hash]) { | ||
hashMap[hash].value += value; | ||
} else { | ||
hashMap[hash] = { value, labels }; | ||
} | ||
return hashMap; | ||
}; | ||
exports.getLabels = function (labelNames, args) { | ||
@@ -33,0 +48,0 @@ if (typeof args[0] === 'object') { |
{ | ||
"name": "prom-client", | ||
"version": "14.0.1", | ||
"version": "14.1.0", | ||
"description": "Client for prometheus", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -313,3 +313,3 @@ # Prometheus client for node.js [![Actions Status](https://github.com/siimon/prom-client/workflows/Node.js%20CI/badge.svg?branch=master)](https://github.com/siimon/prom-client/actions) | ||
gauge.labels({ method: 'GET', statusCode: '200' }).set(100); | ||
// 3nd version: And again the same effect as above | ||
// 3rd version: And again the same effect as above | ||
gauge.labels('GET', '200').set(100); | ||
@@ -316,0 +316,0 @@ ``` |
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
108485
35
2671