diff --git a/lib/elasticsearch.js b/lib/elasticsearch.js index c067e1b..3ff55d8 100644 --- a/lib/elasticsearch.js +++ b/lib/elasticsearch.js @@ -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 @@ -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) { @@ -147,24 +152,33 @@ 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) { - for (key in metrics.timer_data) { - fm.timer_data(key, metrics.timer_data[key], ts, array_timer_data); + if (should_index_type(elasticTimerDataType)) { + if (array_timers.length > 0) { + 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) ); @@ -200,6 +214,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) {