Skip to content

Commit

Permalink
Merge pull request #2 from antonmatsiuk/feature/add-ns-format
Browse files Browse the repository at this point in the history
add ns grp tgt act format
lorenzoaiello authored Feb 1, 2022
2 parents 9784e73 + 1d48c0a commit 694969f
Showing 2 changed files with 162 additions and 0 deletions.
64 changes: 64 additions & 0 deletions lib/ns_format.js
Original file line number Diff line number Diff line change
@@ -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;
98 changes: 98 additions & 0 deletions scipts/es-index-ns-template.sh
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}'

0 comments on commit 694969f

Please sign in to comment.