Skip to content

Commit

Permalink
add new config so that you can specify which data to index
Browse files Browse the repository at this point in the history
We've decided that we don't need the raw `timer` data when we have the `timerData`
data too. This keeps the default as indexing everything but allows users
of the backend to specify the types that they want to index.

The only thing that users need to be careful of, is if they choose to
override the setting then they need to use any custom names they've given
each data type.
  • Loading branch information
Bob Renwick committed Apr 14, 2016
1 parent fcead97 commit a90d237
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 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,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) );
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a90d237

Please sign in to comment.