-#!/usr/bin/env node
+#!/usr/bin/env bash
+':' //; exec "$(command -v nodejs || command -v node || command -v js || echo "ERROR node.js IS NOT AVAILABLE IN THIS SYSTEM")" "$0" "$@"
+
+// shebang hack from:
+// http://unix.stackexchange.com/questions/65235/universal-node-js-shebang
+
+// Initially this is run as a shell script (#!/bin/sh).
+// Then, the second line, finds nodejs or node or js in the system path
+// and executes it with the shell parameters.
+
+// --------------------------------------------------------------------------------------------------------------------
'use strict';
var NETDATA_CONFIG_DIR = process.env.NETDATA_CONFIG_DIR || '/etc/netdata';
var NETDATA_UPDATE_EVERY = process.env.NETDATA_UPDATE_EVERY || 1;
var NODE_D_DIR = NETDATA_PLUGINS_DIR + '/../node.d';
-NETDATA_UPDATE_EVERY = NETDATA_UPDATE_EVERY * 1000;
// make sure the modules are found
process.mainModule.paths.unshift(NODE_D_DIR + '/node_modules');
function pluginConfig(filename) {
var f = path.basename(filename);
+ // node.d.plugin configuration
var m = f.match('.plugin' + '$');
- if(m === null) m = f.match('.node.js' + '$');
if(m !== null)
return netdata.options.paths.config + '/' + f.substring(0, m.index) + '.conf';
- return netdata.options.paths.config + '/' + f + '.conf';
+ // node.d modules configuration
+ m = f.match('.node.js' + '$');
+ if(m !== null)
+ return netdata.options.paths.config + '/node.d/' + f.substring(0, m.index) + '.conf';
+
+ return netdata.options.paths.config + '/node.d/' + f + '.conf';
}
// internal defaults
// --------------------------------------------------------------------------------------------------------------------
// get command line arguments
+{
+ var found_myself = false;
+ var found_number = false;
+ var found_modules = false;
+ process.argv.forEach(function (val, index, array) {
+ netdata.debug('PARAM: ' + val);
+
+ if(!found_myself) {
+ if(val === __filename)
+ found_myself = true;
+ }
+ else {
+ switch(val) {
+ case 'debug':
+ netdata.options.DEBUG = true;
+ netdata.debug('DEBUG enabled');
+ break;
+
+ default:
+ if(found_number === true) {
+ if(found_modules === false) {
+ for(var i in netdata.options.modules)
+ netdata.options.modules[i].enabled = false;
+ }
-var found_myself = false;
-process.argv.forEach(function (val, index, array) {
- netdata.debug('PARAM: ' + val);
+ if(typeof netdata.options.modules[val] === 'undefined')
+ netdata.options.modules[val] = {};
- if(!found_myself) {
- if(val === __filename)
- found_myself = true;
- }
- else {
- switch(val) {
- case 'debug':
- netdata.options.DEBUG = true;
- netdata.debug('DEBUG enabled');
- break;
-
- default:
- try {
- var x = parseInt(val);
- if(x > 0) {
- netdata.options.update_every = x * 1000;
- if(netdata.options.update_every < NETDATA_UPDATE_EVERY) {
- netdata.options.update_every = NETDATA_UPDATE_EVERY;
- netdata.debug('Update frequency ' + x + 's is too low');
+ netdata.options.modules[val].enabled = true;
+ netdata.options.modules_enable_all = false;
+ netdata.debug('enabled module ' + val);
+ }
+ else {
+ try {
+ var x = parseInt(val);
+ if(x > 0) {
+ netdata.options.update_every = x;
+ if(netdata.options.update_every < NETDATA_UPDATE_EVERY) {
+ netdata.options.update_every = NETDATA_UPDATE_EVERY;
+ netdata.debug('Update frequency ' + x + 's is too low');
+ }
+
+ found_number = true;
+ netdata.debug('Update frequency set to ' + netdata.options.update_every + ' seconds');
+ }
+ else netdata.error('Ignoring parameter: ' + val);
+ }
+ catch(e) {
+ netdata.error('Cannot get value of parameter: ' + val);
+ dumpError(e);
}
-
- netdata.debug('Update frequency set to ' + netdata.options.update_every + ' ms');
}
- else netdata.error('Ignoring parameter: ' + val);
- }
- catch(e) {
- netdata.error('Cannot get value of parameter: ' + val);
- dumpError(e);
- }
+ break;
+ }
}
- }
-});
+ });
+}
-if(netdata.options.update_every < 1000) {
+if(netdata.options.update_every < 1) {
netdata.debug('Adjusting update frequency to 1 second');
- netdata.options.update_every = 1000;
+ netdata.options.update_every = 1;
}
// --------------------------------------------------------------------------------------------------------------------
var n = files[len].substring(0, m.index);
if(typeof(netdata.options.modules[n]) === 'undefined')
- netdata.options.modules[n] = { enabled: netdata.options.modules_enable_all };
+ netdata.options.modules[n] = { name: n, enabled: netdata.options.modules_enable_all };
if(netdata.options.modules[n].enabled === true) {
netdata.options.modules[n].name = n;
// load its configuration
var c = {
enable_autodetect: netdata.options.modules_enable_autodetect,
- update_every: Math.round(netdata.options.update_every / 1000)
+ update_every: netdata.options.update_every
};
try {
netdata.debug('loading module\'s ' + netdata.options.modules[n].name + ' config ' + netdata.options.modules[n].config_filename);
}
}
+ // netdata.debug(netdata.options.modules);
return found;
}