import { Tags } from 'hot-shots'; import winston = require('winston'); export declare enum MetricsType { GAUGE = "gauge", INCREMENT = "increment" } export interface InitOptions { /** * interval to send stats to datadog in ms (default = 10 minutes) */ timerInMs?: number; /** * Used to init or not the stats client. * When running production, NODE_ENV should be "production". * If running tests, NODE_ENV should be "development". */ environment?: string | undefined; /** * An optional logger to send Metrics into logs (in debug mode) */ logger?: winston.Logger; } export interface addOrUpdateMetricsOptions { /** * @example * ``` * declare your metrics, their types, value and optionals tags. * {metrics: {processed_users: { type: MetricsType.GAUGE, value: 4, tags: {datamart_id: '4521'}}, users_with_mobile_id_count: {type: MetricsType.INCREMENT, value: 1, tags: {datamart_id: '4521'}}}} * {processed_users: 4} */ metrics: { [metricName: string]: MetricOptions; }; } export interface MetricOptions { type: MetricsType; value: number; tags?: Tags; } export type MetricsSet = Map; export interface MetricsOptionsWithName extends MetricOptions { metricName: string; } /** * Send stats to datadog */ export declare class StatsClient { private static instance; private interval; private metrics; private client; private constructor(); /** * @example * ``` * private this.statsClient: StatsClient * constructor() { * this.statsClient = StatsClient.init({ environment: process.env.NODE_ENV }); * } * ``` */ static init({ timerInMs, environment, logger }: InitOptions): StatsClient; /** * Increment some metrics * @example * ``` * this.statClient.addOrUpdateMetrics({metrics: {processed_users: { type: MetricsType.GAUGE, value: 4, tags: {datamart_id: '4521'}}, users_with_mobile_id_count: {type: MetricsType.INCREMENT, value: 1, tags: {datamart_id: '4521'}}}}) * this.statClient.addOrUpdateMetrics({metrics: {apiCallsError: { type: MetricsType.GAUGE, value: 10, tags: {statusCode: '500'}}}}) * ``` */ addOrUpdateMetrics({ metrics }: addOrUpdateMetricsOptions): void; private sendStats; private resetIncrementMetric; }