import * as http from 'http' ; import { getConfig } from '../config-helper' ; import { collectDefaultMetrics , register , Counter , Registry , } from 'prom-client' ; collectDefaultMetrics ( { timeout : 5000 } ) ; export default class Prometheus { registry : Registry ; requests : Counter ; clip_cnt : Counter ; api_cnt : Counter ; prometheus_cnt : Counter ; constructor ( ) { this . registry = register ; if ( getConfig ( ) . PROD ) { this . requests = new Counter ( { name : 'voice_requests' , help : 'Total Requests Served' , } ) ; this . clip_cnt = new Counter ( { name : 'voice_clips_requests' , help : 'Total Clip Requests Served' , } ) ; this . api_cnt = new Counter ( { name : 'voice_api_requests' , help : 'Total API Requests Served' , } ) ; this . prometheus_cnt = new Counter ( { name : 'voice_prometheus_requests' , help : 'Total Prometheus Requests Served' , } ) ; } } countRequest ( request ) { this . requests && this . requests . inc ( ) ; } countClipRequest ( request ) { this . clip_cnt && this . clip_cnt . inc ( ) ; } countApiRequest ( request ) { this . api_cnt && this . api_cnt . inc ( ) ; } countPrometheusRequest ( request ) { this . prometheus_cnt && this . prometheus_cnt . inc ( ) ; } }