Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions lib/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* To enable this backend, include 'elastic' in the backends
* configuration array:
*
* backends: ['./backends/elastic']
* backends: ['./backends/elastic']
* (if the config file is in the statsd folder)
*
* A sample configuration can be found in exampleElasticConfig.js
Expand Down Expand Up @@ -33,9 +33,14 @@ var elasticIndex;
var elasticIndexTimestamp;
var elasticCountType;
var elasticTimerType;
var elasticTypesToIndex;

var elasticStats = {};

var should_index_type = function should_index_type(type) {
return elasticTypesToIndex.indexOf(type) >= 0;
}


var es_bulk_insert = function elasticsearch_bulk_insert(listCounters, listTimers, listTimerData, listGaugeData) {

Expand Down Expand Up @@ -147,24 +152,31 @@ var flush_stats = function elastic_flush(ts, metrics) {
var gauges = metrics.gauges;
var pctThreshold = metrics.pctThreshold;
*/
if (should_index_type(elasticCountType) >= 0) {
for (key in metrics.counters) {
numStats += fm.counters(key, metrics.counters[key], ts, array_counts);
}

for (key in metrics.counters) {
numStats += fm.counters(key, metrics.counters[key], ts, array_counts);
}

for (key in metrics.timers) {
numStats += fm.timers(key, metrics.timers[key], ts, array_timers);
if (should_index_type(elasticTimerType)) {
for (key in metrics.timers) {
numStats += fm.timers(key, metrics.timers[key], ts, array_timers);
}
}

if (array_timers.length > 0) {
if (should_index_type(elasticTimerDataType)) {
for (key in metrics.timer_data) {
fm.timer_data(key, metrics.timer_data[key], ts, array_timer_data);
}
}

for (key in metrics.gauges) {
numStats += fm.gauges(key, metrics.gauges[key], ts, array_gauges);
if (should_index_type(elasticGaugeDataType)) {
for (key in metrics.gauges) {
numStats += fm.gauges(key, metrics.gauges[key], ts, array_gauges);
}
}

if (debug) {
lg.log('metrics:');
lg.log( JSON.stringify(metrics) );
Expand Down Expand Up @@ -200,6 +212,7 @@ exports.init = function elasticsearch_init(startup_time, config, events, logger)
elasticTimerDataType = configEs.timerDataType || elasticTimerType + '_stats';
elasticGaugeDataType = configEs.gaugeDataType || 'gauge';
elasticFormatter = configEs.formatter || 'default_format';
elasticTypesToIndex = configEs.typesToIndex || [elasticCountType, elasticTimerType, elasticTimerDataType, elasticGaugeDataType];

fm = require('./' + elasticFormatter + '.js')
if (debug) {
Expand Down