-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
63 lines (59 loc) · 1.67 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as promClient from 'prom-client';
import { Router } from 'express';
const PREFIX = 'probot_';
if (process.env.NODE_ENV === 'production') {
promClient.register.clear();
promClient.collectDefaultMetrics({ prefix: PREFIX });
}
export const useCounter = (
options: promClient.CounterConfiguration<string>
) => {
const name = PREFIX + options.name;
try {
return new promClient.Counter({ ...options, name });
} catch {
return promClient.register.getSingleMetric(
name
) as promClient.Counter<string>;
}
};
export const useGauge = (options: promClient.GaugeConfiguration<string>) => {
const name = PREFIX + options.name;
try {
return new promClient.Gauge({ ...options, name });
} catch {
return promClient.register.getSingleMetric(
name
) as promClient.Gauge<string>;
}
};
export const useHistogram = (
options: promClient.HistogramConfiguration<string>
) => {
const name = PREFIX + options.name;
try {
return new promClient.Histogram({ ...options, name });
} catch {
return promClient.register.getSingleMetric(
name
) as promClient.Histogram<string>;
}
};
export const useSummary = (
options: promClient.SummaryConfiguration<string>
) => {
const name = PREFIX + options.name;
try {
return new promClient.Summary({ ...options, name });
} catch {
return promClient.register.getSingleMetric(
name
) as promClient.Summary<string>;
}
};
export const exposeMetrics = (router: Router, route = '/metrics') => {
router.get(route, async (_, response) => {
response.setHeader('Content-type', promClient.register.contentType);
response.end(await promClient.register.metrics());
});
};