
var counters = function (key, value, ts, bucket) {
    var listKeys = key.split('.');
    var act = listKeys.slice(4, listKeys.length).join('.');
    bucket.push({
		"ns": listKeys[0] || '',
		"grp":listKeys[1] || '',
		"tgt":listKeys[2] || '',
		"tnt": listKeys[3] || '',    
		"act":act || '',
		"val":value,
		"@timestamp": ts
	});
	return 1;
}

var timers = function (key, series, ts, bucket) {
    var listKeys = key.split('.');
    var act = listKeys.slice(4, listKeys.length).join('.');
    for (keyTimer in series) {
      bucket.push({
		"ns": listKeys[0] || '',
		"grp":listKeys[1] || '',
		"tgt":listKeys[2] || '',
		"tnt": listKeys[3] || '',            
		"act":act || '',
		"val":series[keyTimer],
		"@timestamp": ts
	 });
    }
	return series.length;
}


var timer_data = function (key, value, ts, bucket) {
    var listKeys = key.split('.');
    var act = listKeys.slice(4, listKeys.length).join('.');
    value["@timestamp"] = ts;
    value["ns"]  = listKeys[0] || '';
    value["grp"] = listKeys[1] || '';
    value["tgt"] = listKeys[2] || '';
    value["tnt"]  = listKeys[3] || '';    
    value["act"] = act || '';
    if (value['histogram']) {
      for (var keyH in value['histogram']) {
        value[keyH] = value['histogram'][keyH];
      }
      delete value['histogram'];
    }
    bucket.push(value);
}

exports.counters   = counters;
exports.timers     = timers;
exports.timer_data = timer_data;
exports.gauges     = counters;

@@ -153,34 +153,35 @@
 ucket.push(%7B%0A%09%09%22
-ns
+tnt
 %22: listKeys%5B0%5D %7C
@@ -181,33 +181,41 @@
 ys%5B0%5D %7C%7C '',
+        
 %0A%09%09%22
-grp
+ns
 %22:
+ 
 listKeys%5B1%5D 
@@ -216,35 +216,35 @@
 ys%5B1%5D %7C%7C '',%0A%09%09%22
-tgt
+grp
 %22:listKeys%5B2%5D %7C%7C
@@ -244,37 +244,36 @@
 s%5B2%5D %7C%7C '',%0A%09%09%22t
-n
+g
 t%22:
- 
 listKeys%5B3%5D %7C%7C '
@@ -274,20 +274,16 @@
 %5D %7C%7C '',
-    
 %0A%09%09%22act%22
@@ -542,26 +542,27 @@
 t.push(%7B%0A%09%09%22
-ns
+tnt
 %22: listKeys%5B
@@ -566,33 +566,53 @@
 ys%5B0%5D %7C%7C '',
+                    
 %0A%09%09%22
-grp
+ns
 %22:
+ 
 listKeys%5B1%5D 
@@ -613,35 +613,35 @@
 ys%5B1%5D %7C%7C '',%0A%09%09%22
-tgt
+grp
 %22:listKeys%5B2%5D %7C%7C
@@ -645,29 +645,28 @@
  %7C%7C '',%0A%09%09%22t
-n
+g
 t%22:
- 
 listKeys%5B3%5D 
@@ -671,28 +671,16 @@
 %5D %7C%7C '',
-            
 %0A%09%09%22act%22
@@ -964,18 +964,19 @@
  value%5B%22
-ns
+tnt
 %22%5D  = li
@@ -983,32 +983,40 @@
 stKeys%5B0%5D %7C%7C '';
+        
 %0A    value%5B%22grp%22
@@ -1015,13 +1015,13 @@
 ue%5B%22
-grp
+ns
 %22%5D
+ 
  = l
@@ -1049,19 +1049,19 @@
  value%5B%22
-tgt
+grp
 %22%5D = lis
@@ -1080,37 +1080,36 @@
 '';%0A    value%5B%22t
-n
+g
 t%22%5D
- 
  = listKeys%5B3%5D %7C
@@ -1113,20 +1113,16 @@
 %5D %7C%7C '';
-    
 %0A    val

update statsd format order