Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bahamas10/node-stats-page
Create a /stats page http-server for a server application
https://github.com/bahamas10/node-stats-page
Last synced: about 2 months ago
JSON representation
Create a /stats page http-server for a server application
- Host: GitHub
- URL: https://github.com/bahamas10/node-stats-page
- Owner: bahamas10
- Created: 2012-07-22T07:34:48.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-09-21T01:25:17.000Z (over 12 years ago)
- Last Synced: 2024-04-14T00:49:03.356Z (8 months ago)
- Language: JavaScript
- Size: 122 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Stats Server for Node Applications
==================================Create a /stats page http-server for a server application
Fire up an http server that you can query for stats on a running node process
Usage
-----``` js
var stats_page = require('stats-page');
stats_page.listen(port, [host], [callback]);
```Example
-------To create a stats server for your application use the following code
``` js
var stats_page = require('stats-page').listen(8745);
````require('stats-page')` returns an HTTP server object
This will fire up a stats server on port 8745 that you can query
$ curl -sS localhost:8745/ | json
``` json
[
"ping",
"process",
"stats"
]
```This returns the next route you can query
$ curl -sS localhost:8745/process | json
``` json
[
"arch",
"argv",
"cwd",
"env",
"execPath",
"features",
"getgid",
"getuid",
"memoryUsage",
"pid",
"platform",
"uptime",
"uvCounters",
"version",
"versions"
]
```Then drill in further to get some meaningful information
$ curl -sS localhost:8745/process/argv | json
``` json
[
"node",
"/Users/dave/dev/node-stats-page/examples/simple.js"
]
```$ curl -sS localhost:8745/process/memoryUsage | json
``` json
{
"rss": 14368768,
"heapTotal": 5343936,
"heapUsed": 2799240
}
```$ curl -sS localhost:8745/process/uptime | json
32
$ curl -sS localhost:8745/process/version | json
v0.6.15
$ curl -sS localhost:8745/ping | json
pong**NOTE:** stats-page will listen on `0.0.0.0` by default (as does `http.createServer`),
you can specify a second argument to the `listen` method of 'localhost' to restrict
access.Customization
-------------You will no doubt have information specific to your app that you would like to
expose. You can add your own routes using the `addRoute` function``` js
stats_page.router.addRoute('/custom', function(req, res) {
res.end('My Custom Route');
});
```then when you query
curl -sS localhost:8745/custom | json
My Custom Routeyou will get your data
The `addRoute` function is provided by the
[routes](https://github.com/aaronblohowiak/routes.js) moduleInstall
-------npm install stats-page
FAQ
---### Are there any other meaningful routes than /process ?
`process` had the easiest stats to expose. If you have any more stats that are generic
enough to expose fork and make a pull request.### Does this work with connect/middle-ware/express/some framework?
I don't know.
### Is this information safe to leave exposed?
Short answer: no. Process information like this can be a security concern, especially
having information like ENV variables visible. It's your job to make sure this host
is properly ACL'd if exposed externally, or to lock this down to localhost.License
-------MIT Licensed