UNPKG

grafana-cloud-graphite

Version:
67 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GraphiteStats = void 0; const utils_1 = require("../../utils"); class GraphiteStats { constructor(name, interval, tags) { this.name = name; this.interval = interval; this.tags = tags; this.count = 0; this.values = []; } get() { const median = (0, utils_1.calcMedian)(this.values); const avg = (0, utils_1.calculateAverage)(this.values); const time = Date.now(); if (!this.values.length) return []; return [ { name: `${this.name}.min`, interval: this.interval, value: Math.min(...this.values), time, tags: this.tags, }, { name: `${this.name}.max`, interval: this.interval, value: Math.max(...this.values), time, tags: this.tags, }, { name: `${this.name}.avg`, interval: this.interval, value: avg, time, tags: this.tags, }, { name: `${this.name}.median`, interval: this.interval, value: median ?? 0, time, tags: this.tags, }, ]; } clear() { const data = this.get(); this.reset(); return data; } add(value) { this.count = this.count + 1; if (value) { this.values.push(value); } } reset() { this.count = 0; this.values = []; } } exports.GraphiteStats = GraphiteStats; //# sourceMappingURL=stats.js.map