Socket
Socket
Sign inDemoInstall

prom-client

Package Overview
Dependencies
Maintainers
3
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 15.0.0-1 to 15.0.0

38

index.d.ts

@@ -12,5 +12,5 @@ // Type definitions for prom-client

export type OpenMetricsContentType =
`${OpenMetricsMIME}; version=${OpenMetricsVersion}; charset=${Charset}`;
export type PrometheusContentType =
`${OpenMetricsMIME}; version=${OpenMetricsVersion}; charset=${Charset}`;
export type OpenMetricsContentType =
`${PrometheusMIME}; version=${PrometheusMetricsVersion}; charset=${Charset}`;

@@ -123,3 +123,5 @@

export class AggregatorRegistry extends Registry {
export class AggregatorRegistry<
T extends RegistryContentType,
> extends Registry<T> {
/**

@@ -141,3 +143,5 @@ * Gets aggregated metrics for all workers.

*/
static aggregate(metricsArr: Array<Object>): Registry; // TODO Promise?
static aggregate<T extends RegistryContentType>(
metricsArr: Array<Object>,
): Registry<T>; // TODO Promise?

@@ -151,3 +155,10 @@ /**

*/
static setRegistries(regs: Array<Registry> | Registry): void;
static setRegistries(
regs:
| Array<
Registry<PrometheusContentType> | Registry<OpenMetricsContentType>
>
| Registry<PrometheusContentType>
| Registry<OpenMetricsContentType>,
): void;
}

@@ -366,3 +377,3 @@

/**
* Set gauge value to current epoch time in ms
* Set gauge value to current epoch time in seconds
* @param labels Object with label keys and values

@@ -563,2 +574,3 @@ */

ageBuckets?: number;
pruneAgedBuckets?: boolean;
compressCount?: number;

@@ -663,3 +675,3 @@ collect?: CollectFunction<Summary<T>>;

*/
export class Pushgateway {
export class Pushgateway<T extends RegistryContentType> {
/**

@@ -670,3 +682,3 @@ * @param url Complete url to the Pushgateway. If port is needed append url with :port

*/
constructor(url: string, options?: any, registry?: Registry);
constructor(url: string, options?: any, registry?: Registry<T>);

@@ -739,4 +751,6 @@ /**

export interface DefaultMetricsCollectorConfiguration {
register?: Registry;
export interface DefaultMetricsCollectorConfiguration<
T extends RegistryContentType,
> {
register?: Registry<T>;
prefix?: string;

@@ -752,4 +766,4 @@ gcDurationBuckets?: number[];

*/
export function collectDefaultMetrics(
config?: DefaultMetricsCollectorConfiguration,
export function collectDefaultMetrics<T extends RegistryContentType>(
config?: DefaultMetricsCollectorConfiguration<T>,
): void;

@@ -756,0 +770,0 @@

@@ -59,4 +59,4 @@ /**

{},
Object.assign({}, this.bucketValues),
Object.assign({}, this.bucketExemplars),
this.bucketValues,
this.bucketExemplars,
),

@@ -88,12 +88,13 @@ };

const hash = hashObject(labels);
const b = findBound(this.upperBounds, value);
if (!isObject(this.hashMap[hash].bucketExemplars[b])) {
this.hashMap[hash].bucketExemplars[b] = new Exemplar();
const bound = findBound(this.upperBounds, value);
const { bucketExemplars } = this.hashMap[hash];
let exemplar = bucketExemplars[bound];
if (!isObject(exemplar)) {
exemplar = new Exemplar();
bucketExemplars[bound] = exemplar;
}
this.hashMap[hash].bucketExemplars[b].validateExemplarLabelSet(
exemplarLabels,
);
this.hashMap[hash].bucketExemplars[b].labelSet = exemplarLabels;
this.hashMap[hash].bucketExemplars[b].value = value;
this.hashMap[hash].bucketExemplars[b].timestamp = nowTimestamp();
exemplar.validateExemplarLabelSet(exemplarLabels);
exemplar.labelSet = exemplarLabels;
exemplar.value = value;
exemplar.timestamp = nowTimestamp();
}

@@ -139,4 +140,4 @@

labels,
Object.assign({}, this.bucketValues),
Object.assign({}, this.bucketExemplars),
this.bucketValues,
this.bucketExemplars,
);

@@ -224,4 +225,4 @@ }

labelValuePair.labels,
Object.assign({}, this.bucketValues),
Object.assign({}, this.bucketExemplars),
this.bucketValues,
this.bucketExemplars,
);

@@ -246,4 +247,4 @@ }

labels,
bucketValues,
bucketExemplars,
bucketValues: { ...bucketValues },
bucketExemplars: { ...bucketExemplars },
sum: 0,

@@ -255,31 +256,27 @@ count: 0,

function convertLabelsAndValues(labels, value) {
if (!isObject(labels)) {
return {
value: labels,
labels: {},
};
}
return {
labels,
value,
};
return isObject(labels)
? {
labels,
value,
}
: {
value: labels,
labels: {},
};
}
function extractBucketValuesForExport(histogram) {
const name = `${histogram.name}_bucket`;
return bucketData => {
const buckets = [];
let acc = 0;
for (const upperBound of histogram.upperBounds) {
const buckets = histogram.upperBounds.map(upperBound => {
acc += bucketData.bucketValues[upperBound];
const lbls = { le: upperBound };
buckets.push(
setValuePair(
lbls,
acc,
`${histogram.name}_bucket`,
bucketData.bucketExemplars[upperBound],
bucketData.labels,
),
return setValuePair(
{ le: upperBound },
acc,
name,
bucketData.bucketExemplars[upperBound],
bucketData.labels,
);
}
});
return { buckets, data: bucketData };

@@ -286,0 +283,0 @@ };

@@ -75,3 +75,9 @@ 'use strict';

resp.on('end', () => {
resolve({ resp, body });
if (resp.statusCode >= 400) {
reject(
new Error(`push failed with status ${resp.statusCode}, ${body}`),
);
} else {
resolve({ resp, body });
}
});

@@ -83,2 +89,6 @@ });

req.on('timeout', () => {
req.destroy(new Error('Pushgateway request timed out'));
});
if (method !== 'DELETE') {

@@ -85,0 +95,0 @@ this.registry

@@ -45,9 +45,9 @@ 'use strict';

const isOpenMetrics =
this.contentType === Registry.OPENMETRICS_CONTENT_TYPE;
for (const val of metric.values || []) {
let { metricName = name, labels = {} } = val;
const { sharedLabels = {} } = val;
if (
this.contentType === Registry.OPENMETRICS_CONTENT_TYPE &&
metric.type === 'counter'
) {
if (isOpenMetrics && metric.type === 'counter') {
metricName = `${metricName}_total`;

@@ -62,9 +62,3 @@ }

// between the base labels and the shared labels
const formattedLabels = [];
for (const [n, v] of Object.entries(labels)) {
if (Object.prototype.hasOwnProperty.call(sharedLabels, n)) {
continue;
}
formattedLabels.push(`${n}="${escapeLabelValue(v)}"`);
}
const formattedLabels = formatLabels(labels, sharedLabels);

@@ -79,3 +73,3 @@ const flattenedShared = flattenSharedLabels(sharedLabels);

const { exemplar } = val;
if (exemplar && this.contentType === Registry.OPENMETRICS_CONTENT_TYPE) {
if (exemplar && isOpenMetrics) {
const formattedExemplars = formatLabels(exemplar.labelSet);

@@ -93,21 +87,17 @@ fullMetricLine += ` # {${formattedExemplars.join(

async metrics() {
const promises = [];
const isOpenMetrics =
this.contentType === Registry.OPENMETRICS_CONTENT_TYPE;
for (const metric of this.getMetricsAsArray()) {
if (
this.contentType === Registry.OPENMETRICS_CONTENT_TYPE &&
metric.type === 'counter'
) {
const promises = this.getMetricsAsArray().map(metric => {
if (isOpenMetrics && metric.type === 'counter') {
metric.name = standardizeCounterName(metric.name);
}
promises.push(this.getMetricsAsString(metric));
}
return this.getMetricsAsString(metric);
});
const resolves = await Promise.all(promises);
if (this.contentType === Registry.OPENMETRICS_CONTENT_TYPE) {
return `${resolves.join('\n')}\n# EOF\n`;
} else {
return `${resolves.join('\n\n')}\n`;
}
return isOpenMetrics
? `${resolves.join('\n')}\n# EOF\n`
: `${resolves.join('\n\n')}\n`;
}

@@ -219,6 +209,11 @@

function formatLabels(labels) {
return Object.entries(labels).map(
([n, v]) => `${n}="${escapeLabelValue(v)}"`,
);
function formatLabels(labels, exclude) {
const { hasOwnProperty } = Object.prototype;
const formatted = [];
for (const [name, value] of Object.entries(labels)) {
if (!exclude || !hasOwnProperty.call(exclude, name)) {
formatted.push(`${name}="${escapeLabelValue(value)}"`);
}
}
return formatted;
}

@@ -225,0 +220,0 @@

{
"name": "prom-client",
"version": "15.0.0-1",
"version": "15.0.0",
"description": "Client for prometheus",

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

"engines": {
"node": ">=14"
"node": "^16 || ^18 || >=20"
},

@@ -47,4 +47,4 @@ "scripts": {

"nock": "^13.0.5",
"prettier": "2.8.3",
"typescript": "^4.0.2"
"prettier": "2.8.8",
"typescript": "^5.0.4"
},

@@ -51,0 +51,0 @@ "dependencies": {

@@ -191,3 +191,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)

```js
// Set value to current time:
// Set value to current time in seconds:
gauge.setToCurrentTime();

@@ -411,3 +411,3 @@

### Registy type
### Registry type

@@ -414,0 +414,0 @@ The library supports both the old Prometheus format and the OpenMetrics format.

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