Collect du information
This commit is contained in:
42
setup/start/collectd/du.py
Normal file
42
setup/start/collectd/du.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user