|
4 | 4 | * To enable this backend, include 'elastic' in the backends |
5 | 5 | * configuration array: |
6 | 6 | * |
7 | | - * backends: ['./backends/elastic'] |
| 7 | + * backends: ['./backends/elastic'] |
8 | 8 | * (if the config file is in the statsd folder) |
9 | 9 | * |
10 | 10 | * A sample configuration can be found in exampleElasticConfig.js |
@@ -33,9 +33,14 @@ var elasticIndex; |
33 | 33 | var elasticIndexTimestamp; |
34 | 34 | var elasticCountType; |
35 | 35 | var elasticTimerType; |
| 36 | +var elasticTypesToIndex; |
36 | 37 |
|
37 | 38 | var elasticStats = {}; |
38 | 39 |
|
| 40 | +var should_index_type = function should_index_type(type) { |
| 41 | + return elasticTypesToIndex.indexOf(type) >= 0; |
| 42 | +} |
| 43 | + |
39 | 44 |
|
40 | 45 | var es_bulk_insert = function elasticsearch_bulk_insert(listCounters, listTimers, listTimerData, listGaugeData) { |
41 | 46 |
|
@@ -147,24 +152,33 @@ var flush_stats = function elastic_flush(ts, metrics) { |
147 | 152 | var gauges = metrics.gauges; |
148 | 153 | var pctThreshold = metrics.pctThreshold; |
149 | 154 | */ |
| 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 | + } |
150 | 159 |
|
151 | | - for (key in metrics.counters) { |
152 | | - numStats += fm.counters(key, metrics.counters[key], ts, array_counts); |
153 | 160 | } |
154 | 161 |
|
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 | + } |
157 | 166 | } |
158 | 167 |
|
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 | + } |
162 | 173 | } |
163 | 174 | } |
164 | 175 |
|
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 | + } |
167 | 180 | } |
| 181 | + |
168 | 182 | if (debug) { |
169 | 183 | lg.log('metrics:'); |
170 | 184 | lg.log( JSON.stringify(metrics) ); |
@@ -200,6 +214,7 @@ exports.init = function elasticsearch_init(startup_time, config, events, logger) |
200 | 214 | elasticTimerDataType = configEs.timerDataType || elasticTimerType + '_stats'; |
201 | 215 | elasticGaugeDataType = configEs.gaugeDataType || 'gauge'; |
202 | 216 | elasticFormatter = configEs.formatter || 'default_format'; |
| 217 | + elasticTypesToIndex = configEs.typesToIndex || [elasticCountType, elasticTimerType, elasticTimerDataType, elasticGaugeDataType]; |
203 | 218 |
|
204 | 219 | fm = require('./' + elasticFormatter + '.js') |
205 | 220 | if (debug) { |
|
0 commit comments