[prev in list] [next in list] [prev in thread] [next in thread] 

List:       collectd
Subject:    [collectd] Smartctl python plugin
From:       Florian_Schüller <florian.schueller () gmail ! com>
Date:       2015-04-29 21:06:50
Message-ID: CAHdOBFqRjuL1EqYb_A=EfVCsjB76m+LFtv+Ma80fx79LU9GQvw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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

[Attachment #5 (text/html)]

<div dir="ltr">Hi!<div><br></div><div>As I&#39;m interrested when my disks will die I \
wrote this plugin</div><div>(It&#39;s far from complete and was just my first \
test)</div><div><br></div><div>Do you think this is useful?</div><div>Is there a \
place for python plugins where I/you can add this?</div><div>Did I miss that there \
already is a plugin to read <a \
href="https://en.wikipedia.org/wiki/S.M.A.R.T">https://en.wikipedia.org/wiki/S.M.A.R.T</a>. \
status?</div><div><br></div><div>btw. nice work \
guys!</div><div>Regards</div><div>Florian</div><div><br></div></div>

--001a1135d732d3ae830514e35cea--


["smart.py" (text/x-python)]

#!/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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic