Question

The following code is written in a node server, using a monitoring module that meters properties of a function. My problem is I want to extract one of the properties out of a JSON output then pass it to a socket.

meter is a function:

stats.meter('reqPerSec').mark;

Print out in JSON format every second:

setInterval(function() {
    console.log(stats.toJSON());
}, 1000);

The output:

{
   reqPerSec:
   { mean: 0,
     count: 0,
     currentRate: 0,
     '1MinuteRate': 0,
     '5MinuteRate': 0,
     '15MinuteRate': 0
   }
}

For example I want the value of mean and put it in a socket.emit.

socket.emit('monitoring', /*value of mean*/);

Debug of socket should be like "args":[0] is the value of mean which is 0:

{"name":"monitoring", "args":[0] }

I am not sure how to extract, it should be something like

function extractData(data) {
    data.reqPerSec.mean;    
}
Was it helpful?

Solution

Based on this example, you can get mean value like this -

var tmp = collection.toJSON();
console.log("mean = "+tmp.http.requestsPerSecond.mean);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top