add types for metricType: summary

This commit is contained in:
Konstantin Pogorelov
2021-04-03 10:37:07 +02:00
parent b569a71130
commit 661e7d5092
2 changed files with 25 additions and 2 deletions

10
types/index.d.ts vendored
View File

@@ -19,7 +19,6 @@ declare namespace express_prom_bundle {
interface Opts {
autoregister?: boolean;
buckets?: number[];
customLabels?: { [key: string]: any };
@@ -31,6 +30,15 @@ declare namespace express_prom_bundle {
bypass?: (req: Request) => boolean;
metricType?: 'summary' | 'histogram';
// https://github.com/siimon/prom-client#histogram
buckets?: number[];
// https://github.com/siimon/prom-client#summary
percentiles?: number[];
maxAgeSeconds?: number;
ageBuckets?: number;
metricsPath?: string;
httpDurationMetricName?: string;
promClient?: { collectDefaultMetrics?: DefaultMetricsCollectorConfiguration };

View File

@@ -40,7 +40,7 @@ promBundle({
...labels,
year: new Date().getFullYear()
}),
metricType: 'summary',
metricType: 'histogram',
metricsPath: '/prometheus',
promClient: {
collectDefaultMetrics: {
@@ -59,6 +59,21 @@ promBundle({
formatStatusCode: (res: Response) => res.statusCode + 100
});
promClient.register.clear();
promBundle({
metricType: 'summary',
maxAgeSeconds: 600,
ageBuckets: 5
});
promClient.register.clear();
promBundle({
metricType: 'summary',
percentiles: [0.01, 0.1, 0.9, 0.99]
});
// TypeScript workaround to write a readonly field
type Writable<T> = { -readonly [K in keyof T]: T[K] };
const wPromBundle: Writable<promBundle> = promBundle;