diff --git a/lib/ns_format.js b/lib/ns_format.js new file mode 100644 index 0000000..3e8c703 --- /dev/null +++ b/lib/ns_format.js @@ -0,0 +1,64 @@ +const counters = function (key, value, ts, bucket) { + if (value) { + var listKeys = key.split('.'); + var act = listKeys.slice(3, listKeys.length).join('.'); + bucket.push({ + "ns": listKeys[0] || '', + "grp":listKeys[1] || '', + "tgt":listKeys[2] || '', + "act":act || '', + "val": value, + "@timestamp": ts + }); + return 1; + } + + return 0; +}; + +const timers = function (key, series, ts, bucket) { + let counter = 0; + var listKeys = key.split('.'); + var act = listKeys.slice(3, listKeys.length).join('.'); + for (let keyTimer in series) { + if (series[keyTimer]) { + bucket.push({ + "ns": listKeys[0] || '', + "grp":listKeys[1] || '', + "tgt":listKeys[2] || '', + "act":act || '', + "val": series[keyTimer], + "@timestamp": ts + }); + counter++; + } + } + return counter; +}; + +const timer_data = function (key, value, ts, bucket) { + var listKeys = key.split('.'); + var act = listKeys.slice(3, listKeys.length).join('.'); + value["@timestamp"] = ts; + value["ns"] = listKeys[0] || ''; + value["grp"] = listKeys[1] || ''; + value["tgt"] = listKeys[2] || ''; + value["act"] = act || ''; + let shouldPush = false; + if (value['histogram']) { + for (var keyH in value['histogram']) { + shouldPush = shouldPush || !!value['histogram'][keyH]; + value[keyH] = value['histogram'][keyH]; + } + delete value['histogram']; + } + + if (shouldPush) { + bucket.push(value); + } +}; + +exports.counters = counters; +exports.timers = timers; +exports.timer_data = timer_data; +exports.gauges = counters; diff --git a/scipts/es-index-ns-template.sh b/scipts/es-index-ns-template.sh new file mode 100644 index 0000000..b3f277a --- /dev/null +++ b/scipts/es-index-ns-template.sh @@ -0,0 +1,98 @@ +curl -XPUT -H 'Content-Type: application/json' "${ES_HOST:-localhost}:${ES_PORT:-9200}/_template/statsd-template" -d ' +{ + "index_patterns" : ["*-statsd-*"], + "settings" : { + "number_of_shards" : 1 + }, + "mappings" : { + "_source" : { "enabled" : true }, + "properties" : { + "type": { + "type": "keyword" + }, + "@timestamp": { + "type": "date" + }, + "val": { + "type": "double", + "index": "true" + }, + "tgt": { + "index": "true", + "type": "keyword" + }, + "act": { + "index": "true", + "type": "keyword" + }, + "grp": { + "index": "true", + "type": "keyword" + }, + "ns": { + "index": "true", + "type": "keyword" + }, + "count_ps": { + "type": "float", + "index": "true" + }, + "count": { + "type": "float", + "index": "true" + }, + "upper": { + "type": "float", + "index": "true" + }, + "lower": { + "type": "float", + "index": "true" + }, + "mean": { + "type": "float", + "index": "true" + }, + "median": { + "type": "float", + "index": "true" + }, + "std": { + "type": "float", + "index": "true" + }, + "sum": { + "type": "float", + "index": "true" + }, + "mean_90": { + "type": "float", + "index": "true" + }, + "upper_90": { + "type": "float", + "index": "true" + }, + "sum_90": { + "type": "float", + "index": "true" + }, + "bin_100": { + "type": "integer", + "index": "true" + }, + "bin_500": { + "type": "integer", + "index": "true" + }, + "bin_1000": { + "type": "integer", + "index": "true" + }, + "bin_inf": { + "type": "integer", + "index": "true" + } + } + } +}'