import { EventEmitter } from 'events'; export declare const NOT_PREDEFINED_VALUE = "NOT_PREDEFINED_VALUE"; export type TNOT_PREDEFINED_VALUE = typeof NOT_PREDEFINED_VALUE; export type TMetricsConfig> = { [key in TMetricsTypes]: { metric: TMetricsClasses; labels?: Partial; help?: string; buckets?: number[]; method?: 'inc' | 'dec' | 'set' | 'observe'; name?: string; }; }; export type TMetricsClasses = 'Counter' | 'Histogram' | 'Gauge'; /** * Create instance of a EventEmitter for emitting prometheus metrics ( https://prometheus.io/ ) * * This single common implementation aims to provide a common implementation * that all services can use. * * @param metricsConfig - configuration for all allowed AND required metrics * @param prefix - string prefix added to all metrics names * * ------- * * Metrics configuration * * ```typescript * // allowed AND required metrics * type TMetricsEvents = 'metric_counter_inc_with_label' | 'metric_counter_inc_with_label_and_value'; * * const type1Labels = ['type1_label1', 'type1_label2', 'type1_label3'] as const; * * // allowed labels * type TLabelsTypes = { * type1: typeof type1Labels; * }; * * let metricsConfig: TMetricsConfig = { * metric_counter_inc_with_label: { * // metrics type (one of Counter, Gauge, Histogram) * metric: Counter, * help: 'metric_counter_inc help', * // metrics method * method: 'inc', * // allowed labels * labels: { type1: type1Labels }, * // metrics name - `key` of this configuration is used if not provided (`metric_counter_inc_with_label` in this case) * name: 'some_name', * }, * } * * const metrics = new Metrics({ metricsConfig, prefix: 'sos_test_' }); * * ``` * * ------- * * Emit metrics: * * ```typescript * metrics.emit('metric_counter_inc_with_label', { type1: 'type1_label1' }, 10); * metrics.emit('metric_counter_inc_with_label', { type1: 'type1_label1' }); * metrics.emit('metric_counter_inc_with_label', 10); * ``` */ export declare class Metrics> extends EventEmitter { private metricsConfig; private metrics; private prefix?; constructor({ metricsConfig, prefix }: { metricsConfig: TMetricsConfig; prefix?: string; }); emit(eventName: TMetricsTypes, labels: { [key in keyof TLabelsTypes]?: TLabelsTypes[key][number]; }, value?: number, method?: 'inc' | 'dec' | 'set' | 'observe'): boolean; emit(eventName: TMetricsTypes, value?: number): boolean; on(eventName: TMetricsTypes, listener: (labels?: Partial>, value?: number, method?: 'inc' | 'dec' | 'set' | 'observe') => void): this; private getMetricsClass; private registerMetrics; private validateLabels; private getMetricsMethod; }