Collect du information

This commit is contained in:
Girish Ramakrishnan
2019-08-17 03:37:22 -07:00
parent 8195e439f3
commit 0d7a3f43c4
5 changed files with 57 additions and 3 deletions
+6 -2
View File
@@ -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>
+1
View File
@@ -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
+42
View 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)