Skip to content

Commit a90d237

Browse files
author
Bob Renwick
committed
add new config so that you can specify which data to index
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.
1 parent fcead97 commit a90d237

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

lib/elasticsearch.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* To enable this backend, include 'elastic' in the backends
55
* configuration array:
66
*
7-
* backends: ['./backends/elastic']
7+
* backends: ['./backends/elastic']
88
* (if the config file is in the statsd folder)
99
*
1010
* A sample configuration can be found in exampleElasticConfig.js
@@ -33,9 +33,14 @@ var elasticIndex;
3333
var elasticIndexTimestamp;
3434
var elasticCountType;
3535
var elasticTimerType;
36+
var elasticTypesToIndex;
3637

3738
var elasticStats = {};
3839

40+
var should_index_type = function should_index_type(type) {
41+
return elasticTypesToIndex.indexOf(type) >= 0;
42+
}
43+
3944

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

@@ -147,24 +152,33 @@ var flush_stats = function elastic_flush(ts, metrics) {
147152
var gauges = metrics.gauges;
148153
var pctThreshold = metrics.pctThreshold;
149154
*/
155+
if (should_index_type(elasticCountType) >= 0) {
156+
for (key in metrics.counters) {
157+
numStats += fm.counters(key, metrics.counters[key], ts, array_counts);
158+
}
150159

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

155-
for (key in metrics.timers) {
156-
numStats += fm.timers(key, metrics.timers[key], ts, array_timers);
162+
if (should_index_type(elasticTimerType)) {
163+
for (key in metrics.timers) {
164+
numStats += fm.timers(key, metrics.timers[key], ts, array_timers);
165+
}
157166
}
158167

159-
if (array_timers.length > 0) {
160-
for (key in metrics.timer_data) {
161-
fm.timer_data(key, metrics.timer_data[key], ts, array_timer_data);
168+
if (should_index_type(elasticTimerDataType)) {
169+
if (array_timers.length > 0) {
170+
for (key in metrics.timer_data) {
171+
fm.timer_data(key, metrics.timer_data[key], ts, array_timer_data);
172+
}
162173
}
163174
}
164175

165-
for (key in metrics.gauges) {
166-
numStats += fm.gauges(key, metrics.gauges[key], ts, array_gauges);
176+
if (should_index_type(elasticGaugeDataType)) {
177+
for (key in metrics.gauges) {
178+
numStats += fm.gauges(key, metrics.gauges[key], ts, array_gauges);
179+
}
167180
}
181+
168182
if (debug) {
169183
lg.log('metrics:');
170184
lg.log( JSON.stringify(metrics) );
@@ -200,6 +214,7 @@ exports.init = function elasticsearch_init(startup_time, config, events, logger)
200214
elasticTimerDataType = configEs.timerDataType || elasticTimerType + '_stats';
201215
elasticGaugeDataType = configEs.gaugeDataType || 'gauge';
202216
elasticFormatter = configEs.formatter || 'default_format';
217+
elasticTypesToIndex = configEs.typesToIndex || [elasticCountType, elasticTimerType, elasticTimerDataType, elasticGaugeDataType];
203218

204219
fm = require('./' + elasticFormatter + '.js')
205220
if (debug) {

0 commit comments

Comments
 (0)