UNPKG

inceptum

Version:

hipages take on the foundational library for enterprise-grade apps written in NodeJS

115 lines (114 loc) 3.61 kB
import { Context } from '../ioc/Context'; export interface LabelValues { [key: string]: string | number; } /** * A counter is a cumulative metric that represents a single numerical value that only ever goes up */ export interface Counter { /** * Increment for given labels * @param labels Object with label keys and values * @param value The number to increment with */ inc(labels: LabelValues, value?: number): void; /** * Increment with value * @param value The value to increment with */ inc(value?: number): void; } export interface Gauge { /** * Increment gauge for given labels * @param labels Object with label keys and values * @param value The value to increment with */ inc(labels: LabelValues, value?: number): void; /** * Increment gauge * @param value The value to increment with */ inc(value?: number): void; /** * Decrement gauge * @param labels Object with label keys and values * @param value Value to decrement with */ dec(labels: LabelValues, value?: number): void; /** * Decrement gauge * @param value The value to decrement with */ dec(value?: number): void; /** * Set gauge value for labels * @param lables Object with label keys and values * @param value The value to set */ set(labels: LabelValues, value: number): void; /** * Set gauge value * @param value The value to set */ set(value: number): void; /** * Set gauge value to current epoch time in ms * @param labels Object with label keys and values */ setToCurrentTime(labels?: LabelValues): void; /** * Start a timer where the gauges value will be the duration in seconds * @param labels Object with label keys and values * @return Function to invoke when timer should be stopped */ startTimer(labels?: LabelValues): (labels?: LabelValues) => void; } /** * A summary samples observations */ export interface Histogram { /** * Observe value in summary * @param value The value to observe */ observe(value: number): void; /** * Observe value for given labels * @param labels Object with label keys and values * @param value Value to observe */ observe(labels: LabelValues, value: number): void; /** * Start a timer where the value in seconds will observed * @param labels Object with label keys and values * @return Function to invoke when timer should be stopped */ startTimer(labels?: LabelValues): (labels?: LabelValues) => void; /** * Reset all values in the summary */ reset(): void; } export declare class MetricsServiceInternal { gaugeCache: Map<string, Gauge>; counterCache: Map<string, Counter>; histogramCache: Map<string, Histogram>; constructor(); protected getOrCreate(map: Map<string, any>, name: string, creator: () => any): any; counter(metricName: any, labels?: any[], metricHelp?: string): Counter; gauge(metricName: any, labels?: any[], metricHelp?: string): Gauge; /** * Get a histogram to update * @param metricName * @param labels * @param metricHelp * @return {Summary} */ histogram(metricName: any, labels?: any[], metricHelp?: string): Histogram; } export declare const MetricsService: MetricsServiceInternal; export declare class MetricsManager { static setup(appName: string, context: Context): void; static registerSingletons(appName: string, context: Context): void; }