UNPKG

kibana-123

Version:

Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic

27 lines (20 loc) 559 B
import _ from 'lodash'; function Samples(max) { this.vals = {}; this.max = max || Infinity; this.length = 0; } Samples.prototype.add = function (sample) { let vals = this.vals; let length = this.length = Math.min(this.length + 1, this.max); _.forOwn(sample, function (val, name) { if (val == null) val = null; if (!vals[name]) vals[name] = new Array(length); vals[name].unshift([Date.now(), val]); vals[name].length = length; }); }; Samples.prototype.toJSON = function () { return this.vals; }; module.exports = Samples;