From 5b4d8af75780310916af952060a21267dd193c0a Mon Sep 17 00:00:00 2001 From: n0ts Date: Thu, 23 Oct 2014 20:14:39 +0900 Subject: [PATCH] Add USBRH module (USBRH is thermometer module) --- usbrh/README.mkdn | 14 +++++ usbrh/conf.d/usbrh.pyconf | 22 ++++++++ usbrh/python_modules/usbrh.py | 99 +++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 usbrh/README.mkdn create mode 100644 usbrh/conf.d/usbrh.pyconf create mode 100644 usbrh/python_modules/usbrh.py diff --git a/usbrh/README.mkdn b/usbrh/README.mkdn new file mode 100644 index 00000000..013ecbff --- /dev/null +++ b/usbrh/README.mkdn @@ -0,0 +1,14 @@ +USBRH +=============== +python module for ganglia 3.1. + +This module parse output /proc/usbrh/X/temperature. +This module required installation USBRH driver fo Linux(*1). + + +(*1) USBRH driver for Linux + + +## AUTHOR + +NAOYA Nakazawa diff --git a/usbrh/conf.d/usbrh.pyconf b/usbrh/conf.d/usbrh.pyconf new file mode 100644 index 00000000..5c8ae37d --- /dev/null +++ b/usbrh/conf.d/usbrh.pyconf @@ -0,0 +1,22 @@ +modules { + module { + name = "usbrh" + language = "python" + } +} + +collection_group { + collect_every = 60 + time_threshold = 90 + + metric { + name = "usbrh_temperature_0" + title = "Temperature 0" + value_threshold = 0 + } + metric { + name = "usbrh_temperature_1" + title = "Temperature 1" + value_threshold = 0 + } +} diff --git a/usbrh/python_modules/usbrh.py b/usbrh/python_modules/usbrh.py new file mode 100644 index 00000000..4d2347c6 --- /dev/null +++ b/usbrh/python_modules/usbrh.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys + +descriptors = list() +Desc_Skel = {} +Debug = False + +def dprint(f, *v): + if Debug: + print >>sys.stderr, "DEBUG: "+f % v + +def metric_of(name): + dprint("%s", name) + try: + type, device_num = name.split("usbrh_")[1].split("_") + f = open("/proc/usbrh/%(device_num)s/%(type)s" % locals(), 'r') + + except IOError: + return 0 + + for l in f: + line = l.rstrip() + if type == "temperature": + line = float(line) + + return line + +def metric_init(params): + global descriptors, Desc_Skel, Debug + + print '[usbrh] initialize' + print params + + # initialize skeleton of descriptors + Desc_Skel = { + 'name' : 'usbrh', + 'call_back' : metric_of, + 'time_max' : 60, + 'value_type' : 'float', + 'format' : '%f', + 'units' : 'Celsius', + 'slope' : 'both', + 'description' : 'usbrh temperature', + 'groups' : 'usbrh', + } + + if "debug" in params: + Debug = params["debug"] + dprint("%s", "Debug mode on") + + # IP:HOSTNAME + if "spoof_host" in params: + Desc_Skel["spoof_host"] = params["spoof_host"] + + descriptors.append(create_desc(Desc_Skel, { + "name" : "usbrh_temperature_0", + "value_type" : "float", + "format" : "%f", + "units" : "Celsius", + "description": "usbrh temperature 0", + })) + + descriptors.append(create_desc(Desc_Skel, { + "name" : "usbrh_temperature_1", + "value_type" : "float", + "format" : "%f", + "units" : "Celsius", + "description": "usbrh temperature 1", + })) + + return descriptors + +def create_desc(skel, prop): + d = skel.copy() + for k,v in prop.iteritems(): + d[k] = v + return d + +def metric_cleanup(): + pass + +if __name__ == '__main__': + params = { + "debug" : True, + } + metric_init(params) + + # for d in descriptors: + # print ''' metric { + # name = "%s" + # title = "%s" + # value_threshold = 0 + # }''' % (d["name"], d["description"]) + + for d in descriptors: + v = d['call_back'](d['name']) + print ('value for %s is '+d['format']) % (d['name'], v)