import { Pushgateway } from "prom-client"; import { loadConfig } from "my-nconf"; interface PromClientOptions { push_url: string; push_timeout: number; } export class PromClient { private _pushgateway: Pushgateway; private _client: Object; private _opts: PromClientOptions; private static _instance; static get Instance() { if (!this._instance) { this._instance = new PromClient( loadConfig().get("metrics_reporter.prometheus") ); } return this._instance; } constructor( options: PromClientOptions = { push_url: "localhost:9091", push_timeout: 5000 } ) { this._opts = options; this._client = require("prom-client"); this._pushgateway = new Pushgateway(this._opts.push_url, { timeout: this._opts.push_timeout }); } get client(): any { return this._client; } set pushgateway(instance: Pushgateway) { this._pushgateway = instance; } get pushgateway(): Pushgateway { return this._pushgateway; } }