diff --git a/setup/start/collectd/collectd.conf b/setup/start/collectd/collectd.conf index 4990bc5ce..fa531d23f 100644 --- a/setup/start/collectd/collectd.conf +++ b/setup/start/collectd/collectd.conf @@ -240,8 +240,12 @@ LoadPlugin write_graphite Interactive false Import "df" - # - # + + Import "du" + + Path boxdata "/home/yellowtent/boxdata" + Path platformdata "/home/yellowtent/platformdata" + diff --git a/setup/start/collectd/df.py b/setup/start/collectd/df.py index b0e4d45e5..23f3f7e98 100644 --- a/setup/start/collectd/df.py +++ b/setup/start/collectd/df.py @@ -21,6 +21,7 @@ def read(): except: continue + # type comes from https://github.com/collectd/collectd/blob/master/src/types.db val = collectd.Values(type='df_complex', plugin='df', plugin_instance=instance) free = st.f_bavail * st.f_frsize # bavail is for non-root user. bfree is total diff --git a/setup/start/collectd/du.py b/setup/start/collectd/du.py new file mode 100644 index 000000000..cebff1aef --- /dev/null +++ b/setup/start/collectd/du.py @@ -0,0 +1,42 @@ +import collectd,os,subprocess + +# https://www.programcreek.com/python/example/106897/collectd.register_read + +PATHS = [] +INTERVAL = 60 * 60 * 24 + +def du(path): + return subprocess.check_output(['du','-Dsb', path]).split()[0].decode('utf-8') + +def init(): + global PATHS + collectd.info('custom du plugin initialized with %s' % PATHS) + +# configure is called for each module block +def configure(config): + global PATHS + + for node in config.children: + key = node.key + + if key == 'Path': + PATHS.append({ 'name': node.values[0], 'path': node.values[1] }) + collectd.info('du plugin: monitoring %s' % node.values[1]) + else: + collectd.info('du plugin: Unknown config key "%s"' % key) + +def read(): + for p in PATHS: + path = p['path'] + collectd.info('computing size of %s' % path) + size = du(path) + collectd.info('du plugin: size of %s is %s' % (path, size)) + + # type comes from https://github.com/collectd/collectd/blob/master/src/types.db + val = collectd.Values(type='capacity', plugin='du', plugin_instance=p['name']) + + val.dispatch(values=[size], type_instance='usage') + +collectd.register_init(init) +collectd.register_config(configure) +collectd.register_read(read, INTERVAL) diff --git a/src/apptask.js b/src/apptask.js index cc9db4b5a..a8c82f9d5 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -205,7 +205,7 @@ function addCollectdProfile(app, callback) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof callback, 'function'); - var collectdConf = ejs.render(COLLECTD_CONFIG_EJS, { appId: app.id, containerId: app.containerId }); + var collectdConf = ejs.render(COLLECTD_CONFIG_EJS, { appId: app.id, containerId: app.containerId, appDataDir: apps.getDataDir(app, app.dataDir) }); fs.writeFile(path.join(paths.COLLECTD_APPCONFIG_DIR, app.id + '.conf'), collectdConf, function (error) { if (error) return callback(error); shell.sudo('addCollectdProfile', [ CONFIGURE_COLLECTD_CMD, 'add', app.id ], {}, callback); diff --git a/src/collectd.config.ejs b/src/collectd.config.ejs index a3ffc0b16..2d72edab0 100644 --- a/src/collectd.config.ejs +++ b/src/collectd.config.ejs @@ -30,3 +30,10 @@ LoadPlugin "table" + + + + Path "<%= appId %>" "<%= appDataDir %>" + + +