import {
CounterFactory,
GaugeFactory,
HistogramFactory,
InvalidArg,
Providers,
TimerWrapperFactory
} from '@btilford/ts-base-core';
import {PromCounterFactory} from './counter';
import {PromHistogramFactory} from './histogram';
import {PromGaugeFactory} from './gauge';
import {PromTimerWrapperFactory} from './timer';
import {PromOptions} from './metric';
import {Registry} from 'prom-client';
export type PromFeature = {
name: 'counter'
| 'histogram'
| 'gauge'
| 'timer';
enabled: boolean;
options: PromOptions;
prefix?: string;
}
export function registerRootRegistry(registry: Registry): void {
Providers.register(registry, Registry);
}
export function registerPrometheusFeature(feature: PromFeature): void {
switch (feature.name) {
case 'counter':
Providers.register(new PromCounterFactory(feature.options), CounterFactory);
break;
case 'histogram':
Providers.register(new PromHistogramFactory(feature.options), HistogramFactory);
break;
case 'gauge':
Providers.register(new PromGaugeFactory(feature.options), GaugeFactory);
break;
case 'timer':
Providers.register(new PromTimerWrapperFactory(feature.options), TimerWrapperFactory);
break;
default:
throw InvalidArg.expected(
'name',
feature.name,
['counter', 'timer', 'histogram', 'gauge']
);
}
}
|