diff --git a/deploy/roles/collectd/templates/leds.py b/deploy/roles/collectd/templates/leds.py index b01909f..2c154bf 100644 --- a/deploy/roles/collectd/templates/leds.py +++ b/deploy/roles/collectd/templates/leds.py @@ -1,78 +1,78 @@ #!/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 = 255 fan_last = 0 TEMP_LOW = 20 TEMP_HIGH = 80 temp_last = 0 COLORS = [ - '0 X X ' # cyan - 'X 0 X ',# magenta - 'X X 0 ',# yellow + '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() 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_last, fan_last line = '' hosts.add(vl.host) index = list(hosts).index(vl.host) if vl.plugin == 'thermal': temp_last = max(temp_last, values[0]) 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 200 ' 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): 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);