Skip to content

Commit

Permalink
Added metricsPrev to onLag event
Browse files Browse the repository at this point in the history
  • Loading branch information
nachooya committed Apr 14, 2017
1 parent c11f2c5 commit 852ed24
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 0.6.1
* Added metricsPrev paramater to `onLag` event. Thanks @nachooya

### 0.6.0
* Added metrics `metrics(name, value)`. Thanks @nachooya

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ toobusy.metric ('bar', 100);
// Get current maxLag or interval setting by calling without parameters.
var currentMaxLag = toobusy.maxLag(), interval = toobusy.interval();

toobusy.onLag(function(currentLag, metrics) {
toobusy.onLag(function(currentLag, metrics, metricsPrev) {
console.log("Event loop lag detected! Latency: " + currentLag + "ms");
console.log("Metrics during interval: ", metrics);
console.log("Metrics previous interval: ", metricsPrev);
});
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "toobusy-why",
"description": "Don't fall over when your Node.JS server is too busy. Now without native dependencies and metrics support!",
"homepage": "https://github.com/nachooya/node-toobusy",
"version": "0.6.0",
"version": "0.6.1",
"dependencies": {},
"devDependencies": {
"mocha": "1.7.0",
Expand Down
4 changes: 3 additions & 1 deletion toobusy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var checkInterval;
var lagEventThreshold = -1;
var eventEmitter = new events.EventEmitter();
var metrics = {};
var metricsPrev = {};

/**
* Main export function.
Expand Down Expand Up @@ -163,9 +164,10 @@ function start() {
lastTime = now;

if (lagEventThreshold !== -1 && currentLag > lagEventThreshold) {
eventEmitter.emit(LAG_EVENT, currentLag, metrics);
eventEmitter.emit(LAG_EVENT, currentLag, metrics, metricsPrev);
}

metricsPrev = metrics;
metrics = {};

}, interval);
Expand Down

0 comments on commit 852ed24

Please sign in to comment.