Hi!

As I'm interrested when my disks will die I wrote this plugin
(It's far from complete and was just my first test)

Do you think this is useful?
Is there a place for python plugins where I/you can add this?
Did I miss that there already is a plugin to read
https://en.wikipedia.org/wiki/S.M.A.R.T. status?

btw. nice work guys!
Regards
Florian
#!/usr/bin/python
#plugin for collectd-python
# configuration expects disks to query with smartctl
# (so smartctl needs to be installed)
#
# sample configuration for collectd.conf
# (just the section for python plugin and "LoadPlugin python" has to be enabled)
#
#<Plugin python>
#        ModulePath "/PATH/WHERE/THIS/SCRIPT/IS"
#        Import "smart"
#
#        <Module smart>
#                disk "/dev/sda"
#                disk "/dev/sdb"
#        </Module>
#</Plugin>


testMode=False
import sys
import subprocess
import re

myName = "smart"
disks = []
smartHeadLine = re.compile("^ID# +ATTRIBUTE_NAME +.*RAW_VALUE$")
smartDataLine = re.compile("^ *(?P<id>[0-9]+) +(?P<name>[^ ]+) .* (?P<value>[0-9]+)( \(.+\))?$")
try:
	import collectd
except:
	print "Collectd not found - running in test mode"
	testMode=True

def myconfig_callback(myConfig):
	global myName
	global disks
        if myConfig is None:
                collectd.warning("%s: impossible to read config" % myName)
		return
	for child in myConfig.children:
		val = child.values[0]
		if child.key.lower() == 'disk':
			if val not in disks:
				disks.append(val)
	collectd.warning("%s: will query disks: %s" %(myName, ", ".join(disks)))
def read(data=None):
	global myName
	global disks
	global smartHeadLine
	global smartDataLine
	for disk in disks:
		smartctl = subprocess.Popen(["smartctl", "-A", disk], stdout = subprocess.PIPE)
		stdout_var = smartctl.stdout.readlines()
		headLine = False
		niceDiskName = disk.replace('/', '_')[1:] if disk[0] == '/' else disk.replace("/","_")
		for line in stdout_var:
			if not headLine:
				if smartHeadLine.match(line) is not None:
					headLine=True
			if not headLine:
				continue
			m = smartDataLine.match(line)
			if m is not None:
				valueName = "%s-%s" %(niceDiskName, m.group("name"))
				vl = collectd.Values(type='gauge', type_instance=valueName)
				vl.plugin='python.smart'
				vl.dispatch(values=[int(m.group("value"))])

def smart_init():
	collectd.register_read(read)

if testMode:
	print "No test mode currently"
else:
	collectd.register_config(myconfig_callback)
	collectd.register_init(smart_init)

_______________________________________________
collectd mailing list
collectd@verplant.org
http://mailman.verplant.org/listinfo/collectd

Reply via email to