Permalink
Browse files

[dist] First working model

  • Loading branch information...
1 parent 5a3ca7e commit 81b078f0f1a08e94bdfe46fa4849f50680487262 @alejandro alejandro committed Mar 19, 2012
Showing with 72 additions and 22 deletions.
  1. +5 −0 History.md
  2. +15 −2 README.md
  3. +0 −1 index.js
  4. +45 −16 lib/watcher.js
  5. +7 −3 package.json
View
@@ -0,0 +1,5 @@
+
+n.n.n / 2012-03-18
+==================
+
+ * [kronos] Initial Commit
View
@@ -1,8 +1,21 @@
-# watcher
+# Watcher by Nodester
+
+ Watcher is a simple module who will be watching a given process, due to maxmem use or disk space abuse, then It'll emit a SIGINT Sign then it'll send a notice to the master process. To restart the process.
+
+ The main purpose of this module is because we, at nodester, are needed to control the memory use by users apps. And disk space in use.
+
+
+#### Inspiration and some *cogh* (all) parts shameless copied from kiwf because read through [Kill it With Fire](https://github.com/Marak/node-kiwf/), was very handy.
- This is a **README**
## Contributors
+- [Alejandro Morales](http://github.com/alejandromg/)
- [Kronos](http://github.com/alejandromg/kronos 'npm install kronos')
+
+
+## Licence
+
+MIT
+Marak Squires & Alejandro Morales Gámez
View
@@ -9,4 +9,3 @@
module.exports = require('./lib/watcher');
-module.exports.run(8000);
View
@@ -1,24 +1,53 @@
#!/usr/bin/env node
/*
- * watcher
+ * watcher-kiwf
* @date:Sun Mar 18 2012 18:37:47 GMT-0600 (CST)
* @name: watcher.js
* @licence: MIT
*/
-
-
-var http = require('http');
-
-var app = http.createServer(function(req,res){
- res.end('I\'m watcher, and you');
-});
-
-
-function run(port) {
- port = port || 8000;
- app.listen(port, function() {
- console.log('running on port: '+port);
+var watcher = module['exports'] = function (options) {
+ var bolt = require('bolt');
+ var mesh = new bolt.Node({
+ delimiter:'::',
+ host: options.host || 'localhost',
+ port: options.port || 6379,
+ auth: options.auth || ''
+ });
+ mesh.start()
+ options = options || {};
+ options.maxMemory = options.maxMemory || -1;
+ process.maxMemory = options.maxMemory;
+ options.maxUptime = options.maxUptime || -1;
+ options.startTime = new Date().getTime();
+ process.maxUptime = options.maxUptime;
+ options.interval = options.interval || 200;
+ function checkConditions() {
+ if (options.maxMemory && options.maxMemory !== -1) {
+ var mem = process.memoryUsage().rss;
+ if (mem >= options.maxMemory) {
+ kill('maxMemory has been exceeded.');
+ }
+ }
+ if (options.maxUptime && options.maxUptime !== -1) {
+ var currentTime = new Date().getTime();
+ if (currentTime - options.startTime >= options.maxUptime) {
+ kill('maxUptime has been exceeded.');
+ }
+ }
+ }
+ function kill (code) {
+ console.log('We detect and abuse of memory in your app, process dieing')
+ console.log('process error: ' + code);
+ console.log('app emiting restart signal && dieing...')
+ mesh.emit('nodester::dieing',{PID:process.pid, execPath: process.cwd(), port: process.env['app_port']});
+ process.exit(0);
+ }
+ mesh.on('nodester::kill', function(data){
+ console.log('Receiving kill signal by nodester')
+ if (process.pid === data.pid){
+ kill('Kill by master');
+ }
});
-};
-module.exports.run = run;
+ setInterval(checkConditions, options.interval);
+}
View
@@ -1,7 +1,11 @@
{
"name" : "watcher",
"version" : "0.0.1",
- "author" : "Kronos",
- "dependencies": {} ,
- "engines": {">= 0.4.x <0.6.11"}
+ "description":"Watcher is a module who will be watching a given process, if he get the limits given before the process will die",
+ "author" : "Alejandro Morales",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/alejandromg/watcher.git"
+ },
+ "engines": "0.6.x"
}

0 comments on commit 81b078f

Please sign in to comment.