Collect du information
This commit is contained in:
@@ -240,8 +240,12 @@ LoadPlugin write_graphite
|
||||
Interactive false
|
||||
|
||||
Import "df"
|
||||
# <Module df>
|
||||
# </Module>
|
||||
|
||||
Import "du"
|
||||
<Module du>
|
||||
Path boxdata "/home/yellowtent/boxdata"
|
||||
Path platformdata "/home/yellowtent/platformdata"
|
||||
</Module>
|
||||
</Plugin>
|
||||
|
||||
<Plugin write_graphite>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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