-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed return structure and added support for first global metrics.
- Loading branch information
1 parent
919386e
commit d329ee7
Showing
8 changed files
with
116 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Basic example | ||
|
||
This will demonstrate the basic usage of the RestService to check health and metrics. | ||
|
||
Execute `npm run basic` from the root directory and open `http://localhost:8000` for the "webpage" and `http://localhost:8001/healthcheck` or `http://localhost:8001/metrics` for data from the RestServie. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"apps": [ | ||
{ | ||
"name": "status", | ||
"script": "examples/metrics/status.js", | ||
"instances": 1 | ||
}, | ||
{ | ||
"name": "server", | ||
"script": "examples/metrics/server.js", | ||
"instances": 1 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var http = require('http'); | ||
var MessageBus = require('../..').MessageBus; | ||
var bus = new MessageBus(); | ||
|
||
var server = this._server = http.createServer(function (req, res) { | ||
(function delayRequest(start) { | ||
setTimeout(function () { | ||
bus.publish('total_requests'); | ||
bus.publish('average_request_time', new Date() - start); | ||
res.writeHead(200); | ||
res.end('Ok'); | ||
}, Math.random() * 20 + 100); | ||
})(new Date()); | ||
}); | ||
|
||
server.listen(8000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var RestService = require('../..').RestService; | ||
var Counter = require('../..').Metrics.Counter; | ||
var Average = require('../..').Metrics.Average; | ||
var instance = new RestService({ | ||
monitor_apps: ['server'] | ||
}); | ||
|
||
instance.registerMetric('total_requests', new Counter()); | ||
instance.registerMetric('average_request_time', new Average()); | ||
|
||
instance.connect().then(function () { | ||
instance.listen(8001); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
'use strict' | ||
|
||
//exports.Starter = require('./lib/starter').default; | ||
exports.RestService = require('./lib/rest').default; | ||
exports.RestService = require('./lib/rest').default; | ||
exports.MessageBus = require('./lib/bus').default; | ||
exports.Metrics = { | ||
Counter: require('./lib/metrics/counter').default, | ||
Average: require('./lib/metrics/average').default | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const pm2 = require('pm2'); | ||
|
||
export default class MessageBus { | ||
constructor () { | ||
process.on('message', this.onMessage.bind(this)); | ||
} | ||
|
||
onMessage(message) { | ||
console.log(message); | ||
} | ||
|
||
publish(event, payload) { | ||
process.send({ | ||
type: 'process:msg', | ||
data: { | ||
event, | ||
payload | ||
} | ||
}) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters