From fe795b33ee6b858ca62f94a86794667a96fe56d0 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 2 Sep 2014 11:05:57 -0300 Subject: [PATCH 1/7] monitor plugin: config --- config/config.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/config.js b/config/config.js index a639f2d..d317715 100644 --- a/config/config.js +++ b/config/config.js @@ -76,6 +76,7 @@ var bitcoindConf = { disableAgent: true }; +var enableMonitor = process.env.ENABLE_MONITOR === 'true'; var enableCleaner = process.env.ENABLE_CLEANER === 'true'; var enableMailbox = process.env.ENABLE_MAILBOX === 'true'; var enableRatelimiter = process.env.ENABLE_RATELIMITER === 'true'; @@ -93,6 +94,8 @@ if (!fs.existsSync(db)) { } module.exports = { + enableMonitor: enableMonitor, + cleaner: require('../plugins/config-monitor.js'), enableCleaner: enableCleaner, cleaner: require('../plugins/config-cleaner.js'), enableMailbox: enableMailbox, From 4c962d3a199bf39fdc51545718ea872b8febe7b9 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 2 Sep 2014 11:06:09 -0300 Subject: [PATCH 2/7] monitor plugin: add config file --- plugins/config-monitor.js | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 plugins/config-monitor.js diff --git a/plugins/config-monitor.js b/plugins/config-monitor.js new file mode 100644 index 0000000..9ee7de0 --- /dev/null +++ b/plugins/config-monitor.js @@ -0,0 +1,4 @@ +module.exports = { + + +}; From fa6fe8d03f42506ebb5ddb257cca65b6b2ccc000 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 2 Sep 2014 11:07:00 -0300 Subject: [PATCH 3/7] monitor plugin: add to main file --- config/config.js | 2 +- insight.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config/config.js b/config/config.js index d317715..dc95a24 100644 --- a/config/config.js +++ b/config/config.js @@ -95,7 +95,7 @@ if (!fs.existsSync(db)) { module.exports = { enableMonitor: enableMonitor, - cleaner: require('../plugins/config-monitor.js'), + monitor: require('../plugins/config-monitor.js'), enableCleaner: enableCleaner, cleaner: require('../plugins/config-cleaner.js'), enableMailbox: enableMailbox, diff --git a/insight.js b/insight.js index 2b810a1..4d4d9a0 100755 --- a/insight.js +++ b/insight.js @@ -139,6 +139,9 @@ if (config.enableCleaner) { require('./plugins/cleaner').init(config.cleaner); } +if (config.enableMonitor) { + require('./plugins/monitor').init(config.monitor); +} // express settings From 28da92be37cb7057aa6f80233b83c282595e15e0 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 2 Sep 2014 11:08:12 -0300 Subject: [PATCH 4/7] monitor plugin: add plugin main file --- plugins/monitor.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 plugins/monitor.js diff --git a/plugins/monitor.js b/plugins/monitor.js new file mode 100644 index 0000000..e0f0ab8 --- /dev/null +++ b/plugins/monitor.js @@ -0,0 +1,8 @@ +var mdb = require('../lib/MessageDb').default(); +var logger = require('../lib/logger').logger; +var preconditions = require('preconditions').singleton(); +var microtime = require('microtime'); + + +module.exports.init = function(config) { +}; From cd7f5035e418dced1657ad58f4425365a7a2aa37 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 2 Sep 2014 11:26:54 -0300 Subject: [PATCH 5/7] monitor plugin: init log --- plugins/monitor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/monitor.js b/plugins/monitor.js index e0f0ab8..9536a1e 100644 --- a/plugins/monitor.js +++ b/plugins/monitor.js @@ -5,4 +5,5 @@ var microtime = require('microtime'); module.exports.init = function(config) { + logger.info('Using monitor plugin'); }; From 3a057d5017271b7ce77b8134cdc70a9afda3a12f Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 2 Sep 2014 11:27:26 -0300 Subject: [PATCH 6/7] cleaner plugin: fix config --- plugins/config-cleaner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/config-cleaner.js b/plugins/config-cleaner.js index 0948f68..929198b 100644 --- a/plugins/config-cleaner.js +++ b/plugins/config-cleaner.js @@ -1,6 +1,6 @@ module.exports = { - cronTime: '* * * * *', + cronTime: '0 * * * *', // run each hour threshold: 2*24*60*60, // 2 days, in seconds }; From a01f70521bf5ad26829d9da4f0c78cc3bbb3cd43 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 2 Sep 2014 11:44:07 -0300 Subject: [PATCH 7/7] monitor plugin: first version --- plugins/config-monitor.js | 3 +-- plugins/monitor.js | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/plugins/config-monitor.js b/plugins/config-monitor.js index 9ee7de0..1958a96 100644 --- a/plugins/config-monitor.js +++ b/plugins/config-monitor.js @@ -1,4 +1,3 @@ module.exports = { - - + cronTime: '* * * * *', // run each minute }; diff --git a/plugins/monitor.js b/plugins/monitor.js index 9536a1e..e5d0ac3 100644 --- a/plugins/monitor.js +++ b/plugins/monitor.js @@ -2,8 +2,25 @@ var mdb = require('../lib/MessageDb').default(); var logger = require('../lib/logger').logger; var preconditions = require('preconditions').singleton(); var microtime = require('microtime'); +var cron = require('cron'); +var CronJob = cron.CronJob; module.exports.init = function(config) { - logger.info('Using monitor plugin'); + var cronTime = config.cronTime || '0 * * * *'; + logger.info('Using monitor plugin with cronTime ' + cronTime); + var onTick = function() { + mdb.getAll(function(err, messages) { + if (err) logger.error(err); + else { + logger.info('Message db size = ' + messages.length); + } + }); + }; + var job = new CronJob({ + cronTime: cronTime, + onTick: onTick + }); + onTick(); + job.start(); };