1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Changing metric logging to take a primative rather than an object

This commit is contained in:
hbeeken 2015-02-03 13:51:05 +00:00 committed by Nick O'Leary
parent b052324d36
commit 7d6ce1ec12
2 changed files with 11 additions and 10 deletions

View File

@ -99,7 +99,7 @@ Node.prototype.send = function(msg) {
if (!msg._messageUuid) { if (!msg._messageUuid) {
msg._messageUuid = constructUniqueIdentifier(); msg._messageUuid = constructUniqueIdentifier();
} }
this.metric(msg,"Node.prototype.send"); this.metric("Node.prototype.send", msg);
node = flows.get(this._wire); node = flows.get(this._wire);
if (node) { if (node) {
node.receive(msg); node.receive(msg);
@ -137,14 +137,14 @@ Node.prototype.send = function(msg) {
// overwriting any previously written uuid because a cloned // overwriting any previously written uuid because a cloned
// message is a different one // message is a different one
clonedmsg._messageUuid = constructUniqueIdentifier(); clonedmsg._messageUuid = constructUniqueIdentifier();
this.metric(clonedmsg,"Node.prototype.send",{parentuuid:msgs[k]._messageUuid}); this.metric("Node.prototype.send",clonedmsg,msgs[k]._messageUuid);
sendEvents.push({n:node,m:clonedmsg}); sendEvents.push({n:node,m:clonedmsg});
} else { } else {
// first msg sent so don't clone // first msg sent so don't clone
if (msgs[k]._messageUuid === null) { if (!msgs[k]._messageUuid) {
msgs[k]._messageUuid = constructUniqueIdentifier(); msgs[k]._messageUuid = constructUniqueIdentifier();
} }
this.metric(msgs[k],"Node.prototype.send"); this.metric("Node.prototype.send", msgs[k]);
sendEvents.push({n:node,m:msgs[k]}); sendEvents.push({n:node,m:msgs[k]});
msgSent = true; msgSent = true;
} }
@ -168,7 +168,7 @@ Node.prototype.receive = function(msg) {
if (!msg._messageUuid) { if (!msg._messageUuid) {
msg._messageUuid = constructUniqueIdentifier(); msg._messageUuid = constructUniqueIdentifier();
} }
this.metric(msg,"Node.prototype.receive"); this.metric("Node.prototype.receive",msg);
this.emit("input", msg); this.emit("input", msg);
}; };
@ -197,12 +197,13 @@ Node.prototype.error = function(msg) {
log_helper(this, 'error', msg); log_helper(this, 'error', msg);
}; };
Node.prototype.metric = function(msg, eventname, metrics) { Node.prototype.metric = function(eventname, msg, metricValue) {
metrics = metrics || {}; var metrics = {};
metrics.level = "metric"; metrics.level = "metric";
metrics.nodeid = this.id; metrics.nodeid = this.id;
metrics.event = eventname; metrics.event = eventname;
metrics.msguuid = msg._messageUuid; metrics.msguuid = msg._messageUuid;
metrics.metric = metricValue;
Log.log(metrics); Log.log(metrics);
} }

View File

@ -379,9 +379,9 @@ describe('Node', function() {
loginfo = msg; loginfo = msg;
}); });
var msg = {payload:"foo", _messageUuid:"987654321"}; var msg = {payload:"foo", _messageUuid:"987654321"};
n.metric(msg,"test.metric",{size:"15mb"}); n.metric("test.metric",msg,"15mb");
should.deepEqual({size:"15mb", level:"metric", nodeid:n.id, should.deepEqual({level:"metric", nodeid:n.id,
event:"test.metric",msguuid:"987654321"}, loginfo); event:"test.metric",msguuid:"987654321", metric:"15mb"}, loginfo);
Log.log.restore(); Log.log.restore();
done(); done();
}); });