diff --git a/deploy/roles/collectd/templates/leds.py b/deploy/roles/collectd/templates/leds.py index d4f2f56..4694059 100644 --- a/deploy/roles/collectd/templates/leds.py +++ b/deploy/roles/collectd/templates/leds.py @@ -1,77 +1,77 @@ #!/usr/bin/env python2 import collectd import serial import subprocess from math import floor, ceil DEBUG = 1 PORT = '/dev/ttyS1' SPEED = 9600 CORES = int(subprocess.check_output('nproc')) LEDS_NUMBER = 8 # number of leds in a column LEDS_MAX = 100 LEDS_NOCOL = '0 0 0 ' FAN_MAX = 200 -TEMP_LOW = 20 +TEMP_LOW = 40 TEMP_HIGH = 80 COLORS = [ '0 X X ', # cyan 'X 0 X ', # magenta 'X X 0 ', # yellow 'X 0 0 ', # red '0 X 0 ', # green '0 0 X ', # blue ] hosts = set() temp = {} def debug(msg): if DEBUG: f = open('/tmp/debug', 'a+') f.write(str(msg) + "\n") f.close() def color(value, index): return COLORS[index].replace('X', str(int(value))) def write(vl, data=None): global hosts, temp line = '' hosts.add(vl.host) index = list(hosts).index(vl.host) if vl.type == 'temperature' and vl.plugin_instance == 'thermal_zone0': temp[vl.host] = float(vl.values[0]) temp_last = max(temp.values()) if temp_last > TEMP_LOW and temp_last < TEMP_HIGH: line += 'f %d ' % (temp_last * 2 / 3 - 20) elif temp_last > TEMP_HIGH: line += 'f %d ' % FAN_MAX else: line += 'f 0 ' if vl.type == 'load': load1 = vl.values[0] load1 = load1 if load1 <= CORES else CORES leds_on = int(floor(LEDS_NUMBER / CORES * load1)) line += 'l%d ' % index for i in xrange(LEDS_NUMBER - 1, -1, -1): if i < leds_on: line += color(LEDS_MAX, index) else: line += LEDS_NOCOL if line != '': debug(line.strip()) ser = serial.Serial(PORT, SPEED) ser.write(line) ser.close() collectd.register_write(write);