UNPKG

container.ts

Version:
53 lines 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /// <reference types="node" /> const assert = require("assert"); const container_1 = require("../../container"); const Metric_1 = require("./Metric"); // Package statsd-client types are out of date. const STATSD = require("statsd-client"); // TODO: Validation library. exports.ENV_STATSD_HOST = "STATSD_HOST"; exports.ENV_STATSD_PORT = "STATSD_PORT"; class StatsdMetric extends Metric_1.Metric { constructor(name, opts) { super(name, opts); // Get host and port environment values. const host = this.environment.get(exports.ENV_STATSD_HOST); const port = this.environment.get(exports.ENV_STATSD_PORT) || "8125"; assert(host != null, "StatsD host is undefined"); assert(port != null, "StatsD port is undefined"); this.debug(`host:port '${host}:${port}'`); // Create statsd client instance. // TODO: Handle more client options. this._statsd = new STATSD({ host, port }); } /** StatsD handler for incoming metric messages. */ handleMetric(metric) { // Map type to statsd methods. switch (metric.type) { case container_1.EMetricType.Increment: { this._statsd.increment(metric.name, metric.value, metric.tags); break; } case container_1.EMetricType.Decrement: { this._statsd.decrement(metric.name, metric.value, metric.tags); break; } case container_1.EMetricType.Gauge: { this._statsd.gauge(metric.name, metric.value, metric.tags); break; } case container_1.EMetricType.Timing: { this._statsd.timing(metric.name, metric.value, metric.tags); break; } case container_1.EMetricType.Histogram: { this._statsd.histogram(metric.name, metric.value, metric.tags); break; } } } } exports.StatsdMetric = StatsdMetric; //# sourceMappingURL=StatsdMetric.js.map