@libp2p/prometheus-metrics 4.3.21 → 4.3.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/counter-group.d.ts +2 -5
- package/dist/src/counter-group.d.ts.map +1 -1
- package/dist/src/counter-group.js +4 -13
- package/dist/src/counter-group.js.map +1 -1
- package/dist/src/counter.d.ts +2 -5
- package/dist/src/counter.d.ts.map +1 -1
- package/dist/src/counter.js +1 -10
- package/dist/src/counter.js.map +1 -1
- package/dist/src/histogram-group.d.ts +2 -5
- package/dist/src/histogram-group.d.ts.map +1 -1
- package/dist/src/histogram-group.js +4 -13
- package/dist/src/histogram-group.js.map +1 -1
- package/dist/src/histogram.d.ts +1 -3
- package/dist/src/histogram.d.ts.map +1 -1
- package/dist/src/histogram.js +1 -11
- package/dist/src/histogram.js.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +30 -49
- package/dist/src/index.js.map +1 -1
- package/dist/src/metric-group.d.ts +2 -5
- package/dist/src/metric-group.d.ts.map +1 -1
- package/dist/src/metric-group.js +4 -13
- package/dist/src/metric-group.js.map +1 -1
- package/dist/src/metric.d.ts +1 -3
- package/dist/src/metric.d.ts.map +1 -1
- package/dist/src/metric.js +1 -10
- package/dist/src/metric.js.map +1 -1
- package/dist/src/summary-group.d.ts +2 -5
- package/dist/src/summary-group.d.ts.map +1 -1
- package/dist/src/summary-group.js +4 -13
- package/dist/src/summary-group.js.map +1 -1
- package/dist/src/summary.d.ts +1 -3
- package/dist/src/summary.d.ts.map +1 -1
- package/dist/src/summary.js +1 -11
- package/dist/src/summary.js.map +1 -1
- package/dist/src/utils.d.ts +0 -4
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js.map +1 -1
- package/package.json +7 -7
- package/src/counter-group.ts +6 -18
- package/src/counter.ts +3 -16
- package/src/histogram-group.ts +6 -18
- package/src/histogram.ts +2 -14
- package/src/index.ts +33 -65
- package/src/metric-group.ts +6 -18
- package/src/metric.ts +2 -14
- package/src/summary-group.ts +6 -18
- package/src/summary.ts +2 -14
- package/src/utils.ts +0 -6
package/dist/src/metric.js
CHANGED
|
@@ -2,21 +2,15 @@ import { Gauge } from 'prom-client';
|
|
|
2
2
|
import { normalizeString } from './utils.js';
|
|
3
3
|
export class PrometheusMetric {
|
|
4
4
|
gauge;
|
|
5
|
-
calculators;
|
|
6
5
|
constructor(name, opts) {
|
|
7
6
|
name = normalizeString(name);
|
|
8
7
|
const help = normalizeString(opts.help ?? name);
|
|
9
8
|
const labels = opts.label != null ? [normalizeString(opts.label)] : [];
|
|
10
9
|
let collect;
|
|
11
|
-
this.calculators = [];
|
|
12
10
|
// calculated metric
|
|
13
11
|
if (opts?.calculate != null) {
|
|
14
|
-
this.calculators.push(opts.calculate);
|
|
15
|
-
const self = this;
|
|
16
12
|
collect = async function () {
|
|
17
|
-
|
|
18
|
-
const sum = values.reduce((acc, curr) => acc + curr, 0);
|
|
19
|
-
this.set(sum);
|
|
13
|
+
this.set(await opts.calculate());
|
|
20
14
|
};
|
|
21
15
|
}
|
|
22
16
|
this.gauge = new Gauge({
|
|
@@ -27,9 +21,6 @@ export class PrometheusMetric {
|
|
|
27
21
|
collect
|
|
28
22
|
});
|
|
29
23
|
}
|
|
30
|
-
addCalculator(calculator) {
|
|
31
|
-
this.calculators.push(calculator);
|
|
32
|
-
}
|
|
33
24
|
update(value) {
|
|
34
25
|
this.gauge.set(value);
|
|
35
26
|
}
|
package/dist/src/metric.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metric.js","sourceRoot":"","sources":["../../src/metric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAK5C,MAAM,OAAO,gBAAgB;IACV,KAAK,CAAO;
|
|
1
|
+
{"version":3,"file":"metric.js","sourceRoot":"","sources":["../../src/metric.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,CAAA;IACvB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAA;IAChC,CAAC;CACF"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { PrometheusCalculatedSummaryOptions } from './index.js';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export declare class PrometheusSummaryGroup implements SummaryGroup, CalculatedMetric<Record<string, number>> {
|
|
2
|
+
import type { SummaryGroup, StopTimer } from '@libp2p/interface';
|
|
3
|
+
export declare class PrometheusSummaryGroup implements SummaryGroup {
|
|
5
4
|
private readonly summary;
|
|
6
5
|
private readonly label;
|
|
7
|
-
private readonly calculators;
|
|
8
6
|
constructor(name: string, opts: PrometheusCalculatedSummaryOptions<Record<string, number>>);
|
|
9
|
-
addCalculator(calculator: CalculateMetric<Record<string, number>>): void;
|
|
10
7
|
observe(values: Record<string, number>): void;
|
|
11
8
|
reset(): void;
|
|
12
9
|
timer(key: string): StopTimer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summary-group.d.ts","sourceRoot":"","sources":["../../src/summary-group.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAA;AACpE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"summary-group.d.ts","sourceRoot":"","sources":["../../src/summary-group.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAGhE,qBAAa,sBAAuB,YAAW,YAAY;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;gBAEjB,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kCAAkC,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IA+B3F,OAAO,CAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAM9C,KAAK,IAAK,IAAI;IAId,KAAK,CAAE,GAAG,EAAE,MAAM,GAAG,SAAS;CAK/B"}
|
|
@@ -3,24 +3,18 @@ import { normalizeString } from './utils.js';
|
|
|
3
3
|
export class PrometheusSummaryGroup {
|
|
4
4
|
summary;
|
|
5
5
|
label;
|
|
6
|
-
calculators;
|
|
7
6
|
constructor(name, opts) {
|
|
8
7
|
name = normalizeString(name);
|
|
9
8
|
const help = normalizeString(opts.help ?? name);
|
|
10
9
|
const label = this.label = normalizeString(opts.label ?? name);
|
|
11
10
|
let collect;
|
|
12
|
-
this.calculators = [];
|
|
13
11
|
// calculated metric
|
|
14
12
|
if (opts?.calculate != null) {
|
|
15
|
-
this.calculators.push(opts.calculate);
|
|
16
|
-
const self = this;
|
|
17
13
|
collect = async function () {
|
|
18
|
-
await
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
}));
|
|
14
|
+
const values = await opts.calculate();
|
|
15
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
16
|
+
this.observe({ [label]: key }, value);
|
|
17
|
+
});
|
|
24
18
|
};
|
|
25
19
|
}
|
|
26
20
|
this.summary = new PromSummary({
|
|
@@ -36,9 +30,6 @@ export class PrometheusSummaryGroup {
|
|
|
36
30
|
collect
|
|
37
31
|
});
|
|
38
32
|
}
|
|
39
|
-
addCalculator(calculator) {
|
|
40
|
-
this.calculators.push(calculator);
|
|
41
|
-
}
|
|
42
33
|
observe(values) {
|
|
43
34
|
Object.entries(values).forEach(([key, value]) => {
|
|
44
35
|
this.summary.observe({ [this.label]: key }, value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summary-group.js","sourceRoot":"","sources":["../../src/summary-group.ts"],"names":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,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC;YAC1E,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,IAAI;YACzC,UAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;YACxB,SAAS,EAAE,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;YACpE,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,CAAE,MAA8B;QACrC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC9C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,EAAE,KAAK,CAAC,CAAA;QACpD,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;IAED,KAAK,CAAE,GAAW;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YAC7B,CAAC,GAAG,CAAC,EAAE,CAAC;SACT,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/dist/src/summary.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { PrometheusCalculatedSummaryOptions } from './index.js';
|
|
2
|
-
import type { StopTimer,
|
|
2
|
+
import type { StopTimer, Summary } from '@libp2p/interface';
|
|
3
3
|
export declare class PrometheusSummary implements Summary {
|
|
4
4
|
private readonly summary;
|
|
5
|
-
private readonly calculators;
|
|
6
5
|
constructor(name: string, opts: PrometheusCalculatedSummaryOptions);
|
|
7
|
-
addCalculator(calculator: CalculateMetric): void;
|
|
8
6
|
observe(value: number): void;
|
|
9
7
|
reset(): void;
|
|
10
8
|
timer(): StopTimer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../src/summary.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAA;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../src/summary.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAA;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAG3D,qBAAa,iBAAkB,YAAW,OAAO;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;gBAExB,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kCAAkC;IA2BnE,OAAO,CAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B,KAAK,IAAK,IAAI;IAId,KAAK,IAAK,SAAS;CAGpB"}
|
package/dist/src/summary.js
CHANGED
|
@@ -2,22 +2,15 @@ import { Summary as PromSummary } from 'prom-client';
|
|
|
2
2
|
import { normalizeString } from './utils.js';
|
|
3
3
|
export class PrometheusSummary {
|
|
4
4
|
summary;
|
|
5
|
-
calculators;
|
|
6
5
|
constructor(name, opts) {
|
|
7
6
|
name = normalizeString(name);
|
|
8
7
|
const help = normalizeString(opts.help ?? name);
|
|
9
8
|
const labels = opts.label != null ? [normalizeString(opts.label)] : [];
|
|
10
9
|
let collect;
|
|
11
|
-
this.calculators = [];
|
|
12
10
|
// calculated metric
|
|
13
11
|
if (opts?.calculate != null) {
|
|
14
|
-
this.calculators.push(opts.calculate);
|
|
15
|
-
const self = this;
|
|
16
12
|
collect = async function () {
|
|
17
|
-
|
|
18
|
-
for (const value of values) {
|
|
19
|
-
this.observe(value);
|
|
20
|
-
}
|
|
13
|
+
this.observe(await opts.calculate());
|
|
21
14
|
};
|
|
22
15
|
}
|
|
23
16
|
this.summary = new PromSummary({
|
|
@@ -33,9 +26,6 @@ export class PrometheusSummary {
|
|
|
33
26
|
collect
|
|
34
27
|
});
|
|
35
28
|
}
|
|
36
|
-
addCalculator(calculator) {
|
|
37
|
-
this.calculators.push(calculator);
|
|
38
|
-
}
|
|
39
29
|
observe(value) {
|
|
40
30
|
this.summary.observe(value);
|
|
41
31
|
}
|
package/dist/src/summary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summary.js","sourceRoot":"","sources":["../../src/summary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAK5C,MAAM,OAAO,iBAAiB;IACX,OAAO,CAAa;
|
|
1
|
+
{"version":3,"file":"summary.js","sourceRoot":"","sources":["../../src/summary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAK5C,MAAM,OAAO,iBAAiB;IACX,OAAO,CAAa;IAErC,YAAa,IAAY,EAAE,IAAwC;QACjE,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,CAAA;QAC5B,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,CAAA;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QACtE,IAAI,OAAsD,CAAA;QAE1D,oBAAoB;QACpB,IAAI,IAAI,EAAE,SAAS,IAAI,IAAI,EAAE,CAAC;YAC5B,OAAO,GAAG,KAAK;gBACb,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,CAAA;YACtC,CAAC,CAAA;QACH,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,IAAI,WAAW,CAAC;YAC7B,IAAI;YACJ,IAAI;YACJ,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC;YAC1E,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,IAAI;YACzC,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;YACpE,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,CAAE,KAAa;QACpB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAA;IAClC,CAAC;CACF"}
|
package/dist/src/utils.d.ts
CHANGED
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,OAAO,CAAA;AAC9B,eAAO,MAAM,UAAU,QAAkB,CAAA;AAEzC;;;GAGG;AACH,wBAAgB,eAAe,CAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIpD"}
|
package/dist/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAA;AAC9B,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,GAAG,UAAU,CAAA;AAEzC;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAE,GAAW;IAC1C,OAAO,GAAG;SACP,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;SAC9B,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/prometheus-metrics",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.22",
|
|
4
4
|
"description": "Collect libp2p metrics for scraping by Prometheus or Graphana",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "Apache-2.0 OR MIT",
|
|
@@ -41,19 +41,19 @@
|
|
|
41
41
|
"test:electron-main": "aegir test -t electron-main --cov"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@libp2p/interface": "^2.10.
|
|
44
|
+
"@libp2p/interface": "^2.10.3",
|
|
45
45
|
"it-foreach": "^2.1.3",
|
|
46
46
|
"it-stream-types": "^2.0.2",
|
|
47
47
|
"prom-client": "^15.1.3",
|
|
48
48
|
"uint8arraylist": "^2.4.8"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@libp2p/crypto": "^5.1.
|
|
52
|
-
"@libp2p/interface-compliance-tests": "^6.4.
|
|
53
|
-
"@libp2p/logger": "^5.1.
|
|
54
|
-
"@libp2p/peer-id": "^5.1.
|
|
51
|
+
"@libp2p/crypto": "^5.1.5",
|
|
52
|
+
"@libp2p/interface-compliance-tests": "^6.4.9",
|
|
53
|
+
"@libp2p/logger": "^5.1.19",
|
|
54
|
+
"@libp2p/peer-id": "^5.1.6",
|
|
55
55
|
"@multiformats/multiaddr": "^12.4.0",
|
|
56
|
-
"aegir": "^47.0.
|
|
56
|
+
"aegir": "^47.0.14",
|
|
57
57
|
"it-drain": "^3.0.9",
|
|
58
58
|
"it-pipe": "^3.0.1",
|
|
59
59
|
"p-defer": "^4.0.1"
|
package/src/counter-group.ts
CHANGED
|
@@ -1,35 +1,27 @@
|
|
|
1
1
|
import { Counter as PromCounter } from 'prom-client'
|
|
2
2
|
import { normalizeString } from './utils.js'
|
|
3
3
|
import type { PrometheusCalculatedMetricOptions } from './index.js'
|
|
4
|
-
import type {
|
|
5
|
-
import type { CounterGroup, CalculateMetric } from '@libp2p/interface'
|
|
4
|
+
import type { CounterGroup } from '@libp2p/interface'
|
|
6
5
|
import type { CollectFunction } from 'prom-client'
|
|
7
6
|
|
|
8
|
-
export class PrometheusCounterGroup implements CounterGroup
|
|
7
|
+
export class PrometheusCounterGroup implements CounterGroup {
|
|
9
8
|
private readonly counter: PromCounter
|
|
10
9
|
private readonly label: string
|
|
11
|
-
private readonly calculators: Array<CalculateMetric<Record<string, number>>>
|
|
12
10
|
|
|
13
11
|
constructor (name: string, opts: PrometheusCalculatedMetricOptions<Record<string, number>>) {
|
|
14
12
|
name = normalizeString(name)
|
|
15
13
|
const help = normalizeString(opts.help ?? name)
|
|
16
14
|
const label = this.label = normalizeString(opts.label ?? name)
|
|
17
15
|
let collect: CollectFunction<PromCounter<any>> | undefined
|
|
18
|
-
this.calculators = []
|
|
19
16
|
|
|
20
17
|
// calculated metric
|
|
21
18
|
if (opts?.calculate != null) {
|
|
22
|
-
this.calculators.push(opts.calculate)
|
|
23
|
-
const self = this
|
|
24
|
-
|
|
25
19
|
collect = async function () {
|
|
26
|
-
await
|
|
27
|
-
const values = await calculate()
|
|
20
|
+
const values = await opts.calculate()
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}))
|
|
22
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
23
|
+
this.inc({ [label]: key }, value)
|
|
24
|
+
})
|
|
33
25
|
}
|
|
34
26
|
}
|
|
35
27
|
|
|
@@ -42,10 +34,6 @@ export class PrometheusCounterGroup implements CounterGroup, CalculatedMetric<Re
|
|
|
42
34
|
})
|
|
43
35
|
}
|
|
44
36
|
|
|
45
|
-
addCalculator (calculator: CalculateMetric<Record<string, number>>): void {
|
|
46
|
-
this.calculators.push(calculator)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
37
|
increment (values: Record<string, number | unknown>): void {
|
|
50
38
|
Object.entries(values).forEach(([key, value]) => {
|
|
51
39
|
const inc = typeof value === 'number' ? value : 1
|
package/src/counter.ts
CHANGED
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
import { Counter as PromCounter } from 'prom-client'
|
|
2
2
|
import { normalizeString } from './utils.js'
|
|
3
3
|
import type { PrometheusCalculatedMetricOptions } from './index.js'
|
|
4
|
-
import type {
|
|
5
|
-
import type { CalculateMetric, Counter } from '@libp2p/interface'
|
|
4
|
+
import type { Counter } from '@libp2p/interface'
|
|
6
5
|
import type { CollectFunction } from 'prom-client'
|
|
7
6
|
|
|
8
|
-
export class PrometheusCounter implements Counter
|
|
7
|
+
export class PrometheusCounter implements Counter {
|
|
9
8
|
private readonly counter: PromCounter
|
|
10
|
-
private readonly calculators: CalculateMetric[]
|
|
11
9
|
|
|
12
10
|
constructor (name: string, opts: PrometheusCalculatedMetricOptions) {
|
|
13
11
|
name = normalizeString(name)
|
|
14
12
|
const help = normalizeString(opts.help ?? name)
|
|
15
13
|
const labels = opts.label != null ? [normalizeString(opts.label)] : []
|
|
16
14
|
let collect: CollectFunction<PromCounter<any>> | undefined
|
|
17
|
-
this.calculators = []
|
|
18
15
|
|
|
19
16
|
// calculated metric
|
|
20
17
|
if (opts?.calculate != null) {
|
|
21
|
-
this.calculators.push(opts.calculate)
|
|
22
|
-
const self = this
|
|
23
|
-
|
|
24
18
|
collect = async function () {
|
|
25
|
-
|
|
26
|
-
const sum = values.reduce((acc, curr) => acc + curr, 0)
|
|
27
|
-
|
|
28
|
-
this.inc(sum)
|
|
19
|
+
this.inc(await opts.calculate())
|
|
29
20
|
}
|
|
30
21
|
}
|
|
31
22
|
|
|
@@ -38,10 +29,6 @@ export class PrometheusCounter implements Counter, CalculatedMetric {
|
|
|
38
29
|
})
|
|
39
30
|
}
|
|
40
31
|
|
|
41
|
-
addCalculator (calculator: CalculateMetric): void {
|
|
42
|
-
this.calculators.push(calculator)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
32
|
increment (value: number = 1): void {
|
|
46
33
|
this.counter.inc(value)
|
|
47
34
|
}
|
package/src/histogram-group.ts
CHANGED
|
@@ -1,35 +1,27 @@
|
|
|
1
1
|
import { Histogram as PromHistogram } from 'prom-client'
|
|
2
2
|
import { normalizeString } from './utils.js'
|
|
3
3
|
import type { PrometheusCalculatedHistogramOptions } from './index.js'
|
|
4
|
-
import type {
|
|
5
|
-
import type { CalculateMetric, HistogramGroup, StopTimer } from '@libp2p/interface'
|
|
4
|
+
import type { HistogramGroup, StopTimer } from '@libp2p/interface'
|
|
6
5
|
import type { CollectFunction } from 'prom-client'
|
|
7
6
|
|
|
8
|
-
export class PrometheusHistogramGroup implements HistogramGroup
|
|
7
|
+
export class PrometheusHistogramGroup implements HistogramGroup {
|
|
9
8
|
private readonly histogram: PromHistogram
|
|
10
9
|
private readonly label: string
|
|
11
|
-
private readonly calculators: Array<CalculateMetric<Record<string, number>>>
|
|
12
10
|
|
|
13
11
|
constructor (name: string, opts: PrometheusCalculatedHistogramOptions<Record<string, number>>) {
|
|
14
12
|
name = normalizeString(name)
|
|
15
13
|
const help = normalizeString(opts.help ?? name)
|
|
16
14
|
const label = this.label = normalizeString(opts.label ?? name)
|
|
17
15
|
let collect: CollectFunction<PromHistogram<any>> | undefined
|
|
18
|
-
this.calculators = []
|
|
19
16
|
|
|
20
17
|
// calculated metric
|
|
21
18
|
if (opts?.calculate != null) {
|
|
22
|
-
this.calculators.push(opts.calculate)
|
|
23
|
-
const self = this
|
|
24
|
-
|
|
25
19
|
collect = async function () {
|
|
26
|
-
await
|
|
27
|
-
const values = await calculate()
|
|
20
|
+
const values = await opts.calculate()
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}))
|
|
22
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
23
|
+
this.observe({ [label]: key }, value)
|
|
24
|
+
})
|
|
33
25
|
}
|
|
34
26
|
}
|
|
35
27
|
|
|
@@ -43,10 +35,6 @@ export class PrometheusHistogramGroup implements HistogramGroup, CalculatedMetri
|
|
|
43
35
|
})
|
|
44
36
|
}
|
|
45
37
|
|
|
46
|
-
addCalculator (calculator: CalculateMetric<Record<string, number>>): void {
|
|
47
|
-
this.calculators.push(calculator)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
38
|
observe (values: Record<string, number>): void {
|
|
51
39
|
Object.entries(values).forEach(([key, value]) => {
|
|
52
40
|
this.histogram.observe({ [this.label]: key }, value)
|
package/src/histogram.ts
CHANGED
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
import { Histogram as PromHistogram } from 'prom-client'
|
|
2
2
|
import { normalizeString } from './utils.js'
|
|
3
3
|
import type { PrometheusCalculatedHistogramOptions } from './index.js'
|
|
4
|
-
import type { StopTimer,
|
|
4
|
+
import type { StopTimer, Histogram } from '@libp2p/interface'
|
|
5
5
|
import type { CollectFunction } from 'prom-client'
|
|
6
6
|
|
|
7
7
|
export class PrometheusHistogram implements Histogram {
|
|
8
8
|
private readonly histogram: PromHistogram
|
|
9
|
-
private readonly calculators: CalculateMetric[]
|
|
10
9
|
|
|
11
10
|
constructor (name: string, opts: PrometheusCalculatedHistogramOptions) {
|
|
12
11
|
name = normalizeString(name)
|
|
13
12
|
const help = normalizeString(opts.help ?? name)
|
|
14
13
|
const labels = opts.label != null ? [normalizeString(opts.label)] : []
|
|
15
14
|
let collect: CollectFunction<PromHistogram<any>> | undefined
|
|
16
|
-
this.calculators = []
|
|
17
15
|
|
|
18
16
|
// calculated metric
|
|
19
17
|
if (opts?.calculate != null) {
|
|
20
|
-
this.calculators.push(opts.calculate)
|
|
21
|
-
const self = this
|
|
22
|
-
|
|
23
18
|
collect = async function () {
|
|
24
|
-
|
|
25
|
-
for (const value of values) {
|
|
26
|
-
this.observe(value)
|
|
27
|
-
}
|
|
19
|
+
this.observe(await opts.calculate())
|
|
28
20
|
}
|
|
29
21
|
}
|
|
30
22
|
|
|
@@ -38,10 +30,6 @@ export class PrometheusHistogram implements Histogram {
|
|
|
38
30
|
})
|
|
39
31
|
}
|
|
40
32
|
|
|
41
|
-
addCalculator (calculator: CalculateMetric): void {
|
|
42
|
-
this.calculators.push(calculator)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
33
|
observe (value: number): void {
|
|
46
34
|
this.histogram.observe(value)
|
|
47
35
|
}
|
package/src/index.ts
CHANGED
|
@@ -152,7 +152,7 @@ class PrometheusMetrics implements Metrics {
|
|
|
152
152
|
if (init?.preserveExistingMetrics !== true) {
|
|
153
153
|
this.log('Clearing existing metrics')
|
|
154
154
|
metrics.clear()
|
|
155
|
-
|
|
155
|
+
register?.clear()
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
if (init?.collectDefaultMetrics !== false) {
|
|
@@ -174,7 +174,7 @@ class PrometheusMetrics implements Metrics {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
// reset counts for next time
|
|
177
|
-
this.transferStats
|
|
177
|
+
this.transferStats.clear()
|
|
178
178
|
|
|
179
179
|
return output
|
|
180
180
|
}
|
|
@@ -216,6 +216,14 @@ class PrometheusMetrics implements Metrics {
|
|
|
216
216
|
'@libp2p/metrics'
|
|
217
217
|
]
|
|
218
218
|
|
|
219
|
+
start (): void {
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
stop (): void {
|
|
224
|
+
this.transferStats.clear()
|
|
225
|
+
}
|
|
226
|
+
|
|
219
227
|
/**
|
|
220
228
|
* Increment the transfer stat for the passed key, making sure
|
|
221
229
|
* it exists first
|
|
@@ -269,17 +277,12 @@ class PrometheusMetrics implements Metrics {
|
|
|
269
277
|
|
|
270
278
|
let metric = metrics.get(name)
|
|
271
279
|
|
|
272
|
-
if (
|
|
273
|
-
this.log('
|
|
274
|
-
|
|
275
|
-
if (opts.calculate != null) {
|
|
276
|
-
metric.addCalculator(opts.calculate)
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return metrics.get(name)
|
|
280
|
+
if (metric != null) {
|
|
281
|
+
this.log('reuse existing metric', name)
|
|
282
|
+
return metric
|
|
280
283
|
}
|
|
281
284
|
|
|
282
|
-
this.log('
|
|
285
|
+
this.log('register metric', name)
|
|
283
286
|
metric = new PrometheusMetric(name, { registry: this.registry, ...opts })
|
|
284
287
|
|
|
285
288
|
metrics.set(name, metric)
|
|
@@ -299,16 +302,11 @@ class PrometheusMetrics implements Metrics {
|
|
|
299
302
|
let metricGroup = metrics.get(name)
|
|
300
303
|
|
|
301
304
|
if (metricGroup != null) {
|
|
302
|
-
this.log('
|
|
303
|
-
|
|
304
|
-
if (opts.calculate != null) {
|
|
305
|
-
metricGroup.addCalculator(opts.calculate)
|
|
306
|
-
}
|
|
307
|
-
|
|
305
|
+
this.log('reuse existing metric', name)
|
|
308
306
|
return metricGroup
|
|
309
307
|
}
|
|
310
308
|
|
|
311
|
-
this.log('
|
|
309
|
+
this.log('register metric group', name)
|
|
312
310
|
metricGroup = new PrometheusMetricGroup(name, { registry: this.registry, ...opts })
|
|
313
311
|
|
|
314
312
|
metrics.set(name, metricGroup)
|
|
@@ -328,16 +326,11 @@ class PrometheusMetrics implements Metrics {
|
|
|
328
326
|
let counter = metrics.get(name)
|
|
329
327
|
|
|
330
328
|
if (counter != null) {
|
|
331
|
-
this.log('
|
|
332
|
-
|
|
333
|
-
if (opts.calculate != null) {
|
|
334
|
-
counter.addCalculator(opts.calculate)
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return metrics.get(name)
|
|
329
|
+
this.log('reuse existing counter', name)
|
|
330
|
+
return counter
|
|
338
331
|
}
|
|
339
332
|
|
|
340
|
-
this.log('
|
|
333
|
+
this.log('register counter', name)
|
|
341
334
|
counter = new PrometheusCounter(name, { registry: this.registry, ...opts })
|
|
342
335
|
|
|
343
336
|
metrics.set(name, counter)
|
|
@@ -357,16 +350,11 @@ class PrometheusMetrics implements Metrics {
|
|
|
357
350
|
let counterGroup = metrics.get(name)
|
|
358
351
|
|
|
359
352
|
if (counterGroup != null) {
|
|
360
|
-
this.log('
|
|
361
|
-
|
|
362
|
-
if (opts.calculate != null) {
|
|
363
|
-
counterGroup.addCalculator(opts.calculate)
|
|
364
|
-
}
|
|
365
|
-
|
|
353
|
+
this.log('reuse existing counter group', name)
|
|
366
354
|
return counterGroup
|
|
367
355
|
}
|
|
368
356
|
|
|
369
|
-
this.log('
|
|
357
|
+
this.log('register counter group', name)
|
|
370
358
|
counterGroup = new PrometheusCounterGroup(name, { registry: this.registry, ...opts })
|
|
371
359
|
|
|
372
360
|
metrics.set(name, counterGroup)
|
|
@@ -385,17 +373,12 @@ class PrometheusMetrics implements Metrics {
|
|
|
385
373
|
|
|
386
374
|
let metric = metrics.get(name)
|
|
387
375
|
|
|
388
|
-
if (
|
|
389
|
-
this.log('
|
|
390
|
-
|
|
391
|
-
if (opts.calculate != null) {
|
|
392
|
-
metric.addCalculator(opts.calculate)
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return metrics.get(name)
|
|
376
|
+
if (metric != null) {
|
|
377
|
+
this.log('reuse existing histogram', name)
|
|
378
|
+
return metric
|
|
396
379
|
}
|
|
397
380
|
|
|
398
|
-
this.log('
|
|
381
|
+
this.log('register histogram', name)
|
|
399
382
|
metric = new PrometheusHistogram(name, { registry: this.registry, ...opts })
|
|
400
383
|
|
|
401
384
|
metrics.set(name, metric)
|
|
@@ -415,16 +398,11 @@ class PrometheusMetrics implements Metrics {
|
|
|
415
398
|
let metricGroup = metrics.get(name)
|
|
416
399
|
|
|
417
400
|
if (metricGroup != null) {
|
|
418
|
-
this.log('
|
|
419
|
-
|
|
420
|
-
if (opts.calculate != null) {
|
|
421
|
-
metricGroup.addCalculator(opts.calculate)
|
|
422
|
-
}
|
|
423
|
-
|
|
401
|
+
this.log('reuse existing histogram group', name)
|
|
424
402
|
return metricGroup
|
|
425
403
|
}
|
|
426
404
|
|
|
427
|
-
this.log('
|
|
405
|
+
this.log('register histogram group', name)
|
|
428
406
|
metricGroup = new PrometheusHistogramGroup(name, { registry: this.registry, ...opts })
|
|
429
407
|
|
|
430
408
|
metrics.set(name, metricGroup)
|
|
@@ -443,17 +421,12 @@ class PrometheusMetrics implements Metrics {
|
|
|
443
421
|
|
|
444
422
|
let metric = metrics.get(name)
|
|
445
423
|
|
|
446
|
-
if (
|
|
447
|
-
this.log('
|
|
448
|
-
|
|
449
|
-
if (opts.calculate != null) {
|
|
450
|
-
metric.addCalculator(opts.calculate)
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
return metrics.get(name)
|
|
424
|
+
if (metric != null) {
|
|
425
|
+
this.log('reuse existing summary', name)
|
|
426
|
+
return metric
|
|
454
427
|
}
|
|
455
428
|
|
|
456
|
-
this.log('
|
|
429
|
+
this.log('register summary', name)
|
|
457
430
|
metric = new PrometheusSummary(name, { registry: this.registry, ...opts })
|
|
458
431
|
|
|
459
432
|
metrics.set(name, metric)
|
|
@@ -473,16 +446,11 @@ class PrometheusMetrics implements Metrics {
|
|
|
473
446
|
let metricGroup = metrics.get(name)
|
|
474
447
|
|
|
475
448
|
if (metricGroup != null) {
|
|
476
|
-
this.log('
|
|
477
|
-
|
|
478
|
-
if (opts.calculate != null) {
|
|
479
|
-
metricGroup.addCalculator(opts.calculate)
|
|
480
|
-
}
|
|
481
|
-
|
|
449
|
+
this.log('reuse existing summary group', name)
|
|
482
450
|
return metricGroup
|
|
483
451
|
}
|
|
484
452
|
|
|
485
|
-
this.log('
|
|
453
|
+
this.log('register summary group', name)
|
|
486
454
|
metricGroup = new PrometheusSummaryGroup(name, { registry: this.registry, ...opts })
|
|
487
455
|
|
|
488
456
|
metrics.set(name, metricGroup)
|