-
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.
- Loading branch information
Showing
4 changed files
with
159 additions
and
94 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
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,43 @@ | ||
var express = require( 'express' ), | ||
request = require( 'request' ), | ||
sPlugin = require( 'monitor-plugin-os' ), | ||
pPlugin = require( 'monitor-plugin-process' ), | ||
createMonitor = require( './../lib' ); | ||
|
||
// Define a port: | ||
var PORT = 7331; | ||
|
||
// Create a new monitor: | ||
var monitor = createMonitor( sPlugin, pPlugin ); | ||
|
||
// Create a new application: | ||
var app = express(); | ||
|
||
// Bind a route using the monitor middleware: | ||
app.get( '/', [ monitor, sendJSON ] ); | ||
|
||
// Spin up a new server: | ||
var server = app.listen( PORT, onListen ); | ||
|
||
|
||
function onListen() { | ||
request({ | ||
'method': 'GET', | ||
'uri': 'http://127.0.0.1:' + PORT | ||
}, onResponse ); | ||
} | ||
|
||
function onResponse( error, response, body ) { | ||
if ( error ) { | ||
throw new Error( error ); | ||
} | ||
console.log( body ); | ||
server.close(); | ||
process.exit( -1 ); | ||
} | ||
|
||
function sendJSON( request, response, next ) { | ||
response | ||
.status( 200 ) | ||
.send( JSON.stringify( request.locals.monitor ) ); | ||
} |
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