forked from Unitech/pm2
-
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
Unitech
committed
Feb 8, 2015
1 parent
74ed479
commit 3d4d46f
Showing
14 changed files
with
509 additions
and
64 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
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,79 @@ | ||
|
||
# Modules system | ||
|
||
A module can be a probe using pmx, an application or any process. | ||
Once a module is installed, it will always stay online. | ||
|
||
## Basics | ||
|
||
```bash | ||
$ pm2 install module-probe | ||
$ pm2 uninstall module-probe | ||
``` | ||
|
||
## Writing a module | ||
|
||
A module is a classic NPM module that contains at least these files: | ||
- **package.json** with all dependencies needed to run this module and the app to be run | ||
- **conf.js** containing user and internals configuration variables | ||
- **index.js** a script that init the module and do whatever you need | ||
|
||
Publishing a module consist of doing: | ||
|
||
```bash | ||
$ npm publish | ||
``` | ||
|
||
## Pre flight checks | ||
|
||
- in the package.json this must be present in order to launch the app: | ||
|
||
```json | ||
[...] | ||
"apps" : [{ | ||
"script" : "probe.js" | ||
}] | ||
[...] | ||
``` | ||
|
||
- the conf.js MUST be present, it's a requirement | ||
|
||
```javascript | ||
var pmx = require('pmx'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
module.exports = { | ||
internals : { | ||
comment : 'This module monitors PM2', | ||
errors : false, | ||
latency : false, | ||
versioning : false, | ||
show_module_meta : true, | ||
pid : pmx.getPID(path.join(process.env.HOME, '.pm2', 'pm2.pid')) | ||
}, | ||
|
||
my_conf_var1 : 1000, | ||
my_conf_var2 : true | ||
}; | ||
``` | ||
|
||
**internals.pid** allows you to monitor a specific PID instead of the PID of the current process. | ||
|
||
**internals.errors|latency|versioning|show_module_meta** allows you to show or hide panel in the keymetrics dashboard. | ||
|
||
**internals.name|comment** allows you to display some metadata in keymetrics | ||
|
||
## Internals | ||
|
||
### Start | ||
|
||
1- When a plugin is installed, it does an npm install and move it to .pm2/node_modules/module-name | ||
1- Then the package.json is started with watch option, forced name (= name folder) and started as module | ||
|
||
-> pm2_env.pmx_module flag is set to true. Allows to differenciate it from other classic processes | ||
|
||
### loadConfig() | ||
|
||
1- send conf.internals to PM2 with msg type axm:option:configuration | ||
1- Attach this data to pm2_env.axm_options |
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,24 +1,31 @@ | ||
var axm = require('pmx'); | ||
var pmx = require('pmx'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
fs.readFile(path.join(process.env.HOME, '.pm2', 'pm2.pid'), function(err, data) { | ||
|
||
var pid = data.toString(); | ||
// conf.js | ||
var conf = { | ||
|
||
axm.configureModule({ | ||
name : 'PM2', | ||
version : '0.12.1', | ||
pid : pid, | ||
keymetrics : { | ||
errors : false, | ||
latency : false, | ||
versioning : false, | ||
show_module_meta : true, | ||
author : 'Alexandre Strzelewicz', | ||
comment : 'This module monitors PM2' | ||
}); | ||
module_type : 'database' | ||
}, | ||
|
||
}); | ||
pid : pmx.getPID(path.join(process.env.HOME, '.pm2', 'pm2.pid')), | ||
pool_time : 1000, | ||
active_pro : true | ||
|
||
}; | ||
|
||
// + merge package.json data | ||
|
||
var conf = pmx.initModule(); | ||
|
||
setInterval(function() { | ||
}, 1000); | ||
// Do something at configurable interval | ||
}, conf.pool_time); | ||
|
||
var Probe = pmx.probe(); |
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
Oops, something went wrong.