UNPKG

watchlog-metric

Version:

This is a package to communicate with watchlog.io agent

39 lines (28 loc) 1.06 kB
const axios = require('axios'); const serverURL = 'http://127.0.0.1:3774'; class SocketCli { #sendMetric(method, metric, value = 1) { if (typeof metric !== 'string' || typeof value !== 'number') return; const url = `${serverURL}?method=${method}&metric=${encodeURIComponent(metric)}&value=${value}`; axios.get(url).catch(() => {}); // Fail silently } increment(metric, value = 1) { if (value > 0) this.#sendMetric('increment', metric, value); } decrement(metric, value = 1) { if (value > 0) this.#sendMetric('decrement', metric, value); } distribution(metric, value) { this.#sendMetric('distribution', metric, value); } gauge(metric, value) { this.#sendMetric('gauge', metric, value); } percentage(metric, value) { if (value >= 0 && value <= 100) this.#sendMetric('percentage', metric, value); } systembyte(metric, value) { if (value > 0) this.#sendMetric('systembyte', metric, value); } } module.exports = new SocketCli();