prom-client
Advanced tools
Comparing version 14.1.1 to 14.2.0
@@ -32,3 +32,3 @@ // Type definitions for prom-client | ||
*/ | ||
getMetricsAsJSON(): Promise<metric[]>; | ||
getMetricsAsJSON(): Promise<MetricObjectWithValues<MetricValue<string>>[]>; | ||
@@ -38,3 +38,3 @@ /** | ||
*/ | ||
getMetricsAsArray(): metric[]; | ||
getMetricsAsArray(): MetricObject[]; | ||
@@ -141,3 +141,3 @@ /** | ||
interface metric { | ||
interface MetricObject { | ||
name: string; | ||
@@ -150,2 +150,16 @@ help: string; | ||
interface MetricObjectWithValues<T extends MetricValue<string>> | ||
extends MetricObject { | ||
values: T[]; | ||
} | ||
type MetricValue<T extends string> = { | ||
value: number; | ||
labels: LabelValues<T>; | ||
}; | ||
type MetricValueWithName<T extends string> = MetricValue<T> & { | ||
metricName?: string; | ||
}; | ||
type LabelValues<T extends string> = Partial<Record<T, string | number>>; | ||
@@ -190,2 +204,7 @@ | ||
/** | ||
* Get counter metric object | ||
*/ | ||
get(): Promise<MetricObjectWithValues<MetricValue<T>>>; | ||
/** | ||
* Return the child for given labels | ||
@@ -286,2 +305,7 @@ * @param values Label values | ||
/** | ||
* Get gauge metric object | ||
*/ | ||
get(): Promise<MetricObjectWithValues<MetricValue<T>>>; | ||
/** | ||
* Set gauge value to current epoch time in ms | ||
@@ -396,2 +420,7 @@ * @param labels Object with label keys and values | ||
/** | ||
* Get histogram metric object | ||
*/ | ||
get(): Promise<MetricObjectWithValues<MetricValueWithName<T>>>; | ||
/** | ||
* Start a timer. Calling the returned function will observe the duration in | ||
@@ -499,2 +528,7 @@ * seconds in the histogram. | ||
/** | ||
* Get summary metric object | ||
*/ | ||
get(): Promise<MetricObjectWithValues<MetricValueWithName<T>>>; | ||
/** | ||
* Start a timer. Calling the returned function will observe the duration in | ||
@@ -501,0 +535,0 @@ * seconds in the summary. |
@@ -30,36 +30,23 @@ 'use strict'; | ||
const type = `# TYPE ${name} ${item.type}`; | ||
const defaultLabelNames = Object.keys(this._defaultLabels); | ||
const defaultLabels = | ||
Object.keys(this._defaultLabels).length > 0 ? this._defaultLabels : null; | ||
let values = ''; | ||
for (const val of item.values || []) { | ||
val.labels = val.labels || {}; | ||
const values = [help, type]; | ||
for (const { metricName = item.name, value, labels = {} } of item.values || | ||
[]) { | ||
const labelsWithDefaults = defaultLabels | ||
? { ...labels, ...defaultLabels, ...labels } | ||
: labels; | ||
if (defaultLabelNames.length > 0) { | ||
// Make a copy before mutating | ||
val.labels = Object.assign({}, val.labels); | ||
const formattedLabels = Object.entries(labelsWithDefaults).map( | ||
([n, v]) => `${n}="${escapeLabelValue(v)}"`, | ||
); | ||
const labelsString = formattedLabels.length | ||
? `{${formattedLabels.join(',')}}` | ||
: ''; | ||
for (const labelName of defaultLabelNames) { | ||
val.labels[labelName] = | ||
val.labels[labelName] || this._defaultLabels[labelName]; | ||
} | ||
} | ||
let metricName = val.metricName || item.name; | ||
const keys = Object.keys(val.labels); | ||
const size = keys.length; | ||
if (size > 0) { | ||
let labels = ''; | ||
let i = 0; | ||
for (; i < size - 1; i++) { | ||
labels += `${keys[i]}="${escapeLabelValue(val.labels[keys[i]])}",`; | ||
} | ||
labels += `${keys[i]}="${escapeLabelValue(val.labels[keys[i]])}"`; | ||
metricName += `{${labels}}`; | ||
} | ||
values += `${metricName} ${getValueAsString(val.value)}\n`; | ||
values.push(`${metricName}${labelsString} ${getValueAsString(value)}`); | ||
} | ||
return `${help}\n${type}\n${values}`.trim(); | ||
return values.join('\n'); | ||
} | ||
@@ -66,0 +53,0 @@ |
@@ -55,10 +55,18 @@ /** | ||
} | ||
const data = Object.values(this.hashMap); | ||
const hashKeys = Object.keys(this.hashMap); | ||
const values = []; | ||
data.forEach(s => { | ||
extractSummariesForExport(s, this.percentiles).forEach(v => { | ||
values.push(v); | ||
}); | ||
values.push(getSumForExport(s, this)); | ||
values.push(getCountForExport(s, this)); | ||
hashKeys.forEach(hashKey => { | ||
const s = this.hashMap[hashKey]; | ||
if (s) { | ||
if (this.pruneAgedBuckets && s.td.size() === 0) { | ||
delete this.hashMap[hashKey]; | ||
} else { | ||
extractSummariesForExport(s, this.percentiles).forEach(v => { | ||
values.push(v); | ||
}); | ||
values.push(getSumForExport(s, this)); | ||
values.push(getCountForExport(s, this)); | ||
} | ||
} | ||
}); | ||
@@ -65,0 +73,0 @@ |
@@ -20,2 +20,7 @@ 'use strict'; | ||
size() { | ||
const bucket = rotate.call(this); | ||
return bucket.size(); | ||
} | ||
percentile(quantile) { | ||
@@ -22,0 +27,0 @@ const bucket = rotate.call(this); |
{ | ||
"name": "prom-client", | ||
"version": "14.1.1", | ||
"version": "14.2.0", | ||
"description": "Client for prometheus", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -268,2 +268,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) | ||
ageBuckets: 5, | ||
pruneAgedBuckets: false, | ||
}); | ||
@@ -274,3 +275,5 @@ ``` | ||
`ageBuckets` configures how many buckets we will have in our sliding window for | ||
the summary. | ||
the summary. If `pruneAgedBuckets` is `false` (default), the metric value will | ||
always be present, even when empty (its percentile values will be `0`). Set | ||
`pruneAgedBuckets` to `true` if you don't want to export it when it is empty. | ||
@@ -277,0 +280,0 @@ ##### Examples |
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
109628
2698
569