Compare commits

...

5 Commits

Author SHA1 Message Date
Naren 30e03aa0f4 prom-client 14.2.0 2023-03-09 08:13:00 -08:00
Naren 662c891b88 collectDefaultMetrics fn 2023-03-09 07:58:49 -08:00
Naren 5c71ce1f93 notes 2023-03-08 15:20:35 -08:00
Naren 38786a959b update tests 2023-03-07 17:38:07 -08:00
Naren c01d26b55e upgrade prom-client 2023-03-07 17:21:13 -08:00
4 changed files with 18 additions and 20 deletions

View File

@ -1,26 +1,19 @@
import promClient from 'prom-client'; import promClient from 'prom-client';
const collectDefaultMetricsIntervalMs =
process.env.COLLECT_DEFAULT_METRICS_INTERVAL_MS !== undefined ?
Number.parseInt(process.env.COLLECT_DEFAULT_METRICS_INTERVAL_MS, 10) :
10000;
promClient.collectDefaultMetrics({ timeout: collectDefaultMetricsIntervalMs });
export default class ZenkoMetrics { export default class ZenkoMetrics {
static createCounter(params: promClient.CounterConfiguration) { static createCounter(params: promClient.CounterConfiguration<string>) {
return new promClient.Counter(params); return new promClient.Counter(params);
} }
static createGauge(params: promClient.GaugeConfiguration) { static createGauge(params: promClient.GaugeConfiguration<string>) {
return new promClient.Gauge(params); return new promClient.Gauge(params);
} }
static createHistogram(params: promClient.HistogramConfiguration) { static createHistogram(params: promClient.HistogramConfiguration<string>) {
return new promClient.Histogram(params); return new promClient.Histogram(params);
} }
static createSummary(params: promClient.SummaryConfiguration) { static createSummary(params: promClient.SummaryConfiguration<string>) {
return new promClient.Summary(params); return new promClient.Summary(params);
} }
@ -28,11 +21,15 @@ export default class ZenkoMetrics {
return promClient.register.getSingleMetric(name); return promClient.register.getSingleMetric(name);
} }
static asPrometheus() { static async asPrometheus() {
return promClient.register.metrics(); return promClient.register.metrics();
} }
static asPrometheusContentType() { static asPrometheusContentType() {
return promClient.register.contentType; return promClient.register.contentType;
} }
static collectDefaultMetrics() {
promClient.collectDefaultMetrics();
}
} }

View File

@ -41,7 +41,7 @@
"level-sublevel": "~6.6.5", "level-sublevel": "~6.6.5",
"mongodb": "^3.0.1", "mongodb": "^3.0.1",
"node-forge": "^0.7.1", "node-forge": "^0.7.1",
"prom-client": "10.2.3", "prom-client": "14.2.0",
"simple-glob": "^0.2", "simple-glob": "^0.2",
"socket.io": "~2.3.0", "socket.io": "~2.3.0",
"socket.io-client": "~2.3.0", "socket.io-client": "~2.3.0",

View File

@ -65,7 +65,7 @@ describe('ZenkoMetrics', () => {
assert.strictEqual(ZenkoMetrics.getMetric('does_not_exist'), undefined); assert.strictEqual(ZenkoMetrics.getMetric('does_not_exist'), undefined);
}); });
it('should export metrics in prometheus format', () => { it('should export metrics in prometheus format', async () => {
const expectedLines = [ const expectedLines = [
'# HELP gizmo_counter Count gizmos', '# HELP gizmo_counter Count gizmos',
'# TYPE gizmo_counter counter', '# TYPE gizmo_counter counter',
@ -94,8 +94,9 @@ describe('ZenkoMetrics', () => {
'pet_counter{type="puppy"} 2', 'pet_counter{type="puppy"} 2',
]; ];
const lines = {}; const lines = {};
ZenkoMetrics.asPrometheus().split('\n').forEach(line => { const metrics = await ZenkoMetrics.asPrometheus();
lines[line.trimRight()] = true; metrics.split('\n').forEach(line => {
lines[line.trimEnd()] = true;
}); });
expectedLines.forEach(expectedLine => { expectedLines.forEach(expectedLine => {
assert.notStrictEqual( assert.notStrictEqual(

View File

@ -5384,10 +5384,10 @@ process-nextick-args@~2.0.0:
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==
prom-client@10.2.3: prom-client@14.2.0:
version "10.2.3" version "14.2.0"
resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-10.2.3.tgz#a51bf21c239c954a6c5be4b1361fdd380218bb41" resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-14.2.0.tgz#ca94504e64156f6506574c25fb1c34df7812cf11"
integrity sha512-Xboq5+TdUwuQtSSDRZRNnb5NprINlgQN999VqUjZxnLKydUNLeIPx6Eiahg6oJua3XBg2TGnh5Cth1s4I6+r7g== integrity sha512-sF308EhTenb/pDRPakm+WgiN+VdM/T1RaHj1x+MvAuT8UiQP8JmOEbxVqtkbfR4LrvOg5n7ic01kRBDGXjYikA==
dependencies: dependencies:
tdigest "^0.1.1" tdigest "^0.1.1"