Monitoring servers with an USB lamp

For some time now I have been looking for a light that can be easily controlled from a desktop computer or server. The original intention was to have a red lamp in the office hallway and light it up when the unit tests break.

One solution to that idea is using a network-controllable power outlet strip and plug a normal lamp in there. Problem here is the price tag, which is above 100€.

Another solution would be to solder a lamp with an USB connector myself; there are numerous tutorials about that on the internet. Since I am inherently lazy, this was only my last resort when there was no other way out.

A Linux Journal article from 2004(!) told me about a dedicated USB lamp from Delcom which is basically what I want - a USB controllable light - but with a huge price tag of 88 US$ upwards.

Some days ago I came across the DreamCheeky Webmail notifier which actually is a USB lamp with differently colored LEDs inside that can be controlled via USB. After discovering that there is also a linux driver for it, I bought it at the local thinkgeek instance for 15€.

Yesterday it arrived by mail, 5 minutes later the controller program was installed - which supports passing in hex color codes, i.e. usblamp '#FF8000' for a nice orange - and an hour later I had a cron script running that sets the color of the mail notifier according to the load of one of our development servers. The serverload-munin code is part of daniel's git repository now.

The script expects that munin-node (version 1.x) is installed and running on the server, since fetching the load value is really easy using netcat on munin-node's plain text protocol on port 4949.

Photo of the USB lamp in action

Update 2010-12-22: Linux kernel drivers on the way

I just got a mail forwarded by Melchior Franz, noting that Greg Kroah-Hartman accepted Melchior's patch into his usb-next kernel tree ! This means that in the next merge window the patch will get into the linux mainline kernel. Wow! That was really fast.

The kernel already had a USBLED driver for Delcom's USB Visual Signal Indicator, exposing virtual files for red, green and blue in the /sys/ file system. Now that driver has been extended to support Dream Cheeky's DL100B Webmail Notifier - which also brings us support for connecting multiple usb lamps to the computer! This one was lacking in the usblamp tool on github and I already considered implementing it. You've gotta love Open Source for such moments.

Update 2010-12-23: Pimped USB Lamp

Melchior sent a link to photos of his pimped lamp - he removed the original cover and replaced it with one from a bicycle lamp.

Oh, and Conrad sells the lamp for 10€ now.

Update 2011-10-15: Kernel driver usage

Ubuntu 11.10 (Oneiric) ships Linux 3.0.0 which has the drivers included. Multiple lamps are supported!

When attached, the log shows the following:

$ dmesg|tail -n3
[72465.130847] usb 2-1.2: USB disconnect, device number 6
[72468.909763] usb 2-1.2: new low speed USB device number 7 using ehci_hcd
[72469.025013] usbled 2-1.2:1.0: USB LED device now attached

Finding the lamp devices

$ find /sys -name green

2 lamps are attached here.

Changing the color

You may use values from 0 to 255 in the files red, green and blue.

$ cd /sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1.2/2-1.2:1.0/
$ echo 255 > red
$ echo 255 > green
$ echo 255 > blue

For me, red 50 is the same as red 255.

udev rules

When the lamp gets plugged in, it is only usable for the root user. To fix this, an udev rule is needed.

Put the following line into /etc/udev/rules.d/99-usblamp.rules. It will run a shell script whenever an usb lamp is plugged in:

SUBSYSTEM=="usb", DRIVER=="usbled", RUN+="/etc/udev/"

Now create the shell script /etc/udev/ and make it executable:

chmod g+w $path/red $path/green $path/blue
chgrp lampe $path/red $path/green $path/blue

When booting the computer with the lamp attached, the rule does not get called. You may work around this problem by putting a

udevadm trigger --action=change

into your /etc/rc.local file.

If you know how to fix this properly without messing with rc.local, please tell me.

Update 2017-01: HID_LED drivers

Mid 2016 the kernel's USB-LED driver was converted into the HID_LED driver. Access to the color is a bit different now in Linux 4.9.

When plugging the device into the USB port, dmesg shows the following:

usb 2-3.3: new low-speed USB device number 5 using ehci-pci
usb 2-3.3: New USB device found, idVendor=1d34, idProduct=0004
usb 2-3.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 2-3.3: Product: DL100B Dream Cheeky Generic Controller
usb 2-3.3: Manufacturer: Dream Link
hid-led 0003:1D34:0004.0007: hidraw5: USB HID v1.10 Device [Dream Link DL100B Dream Cheeky Generic Controller] on usb-0000:00:13.2-3.3/input0
hid-led 0003:1D34:0004.0007: Dream Cheeky Webmail Notifier initialized

The LEDs are available as directories in /sys/class/leds and can be changed by modifying their brightness file:

$ ls /sys/class/leds/
dream_cheeky5:blue  dream_cheeky5:green  dream_cheeky5:red
$ echo 31 > /sys/class/leds/dream_cheeky5\:blue/brightness

There is a max_brightness file.

More documentation on the Linux LED subsystem can be found in leds-class.txt

Other people with the same idea

Laurence Sheed uses the eBuddy for server load and door entry monitoring .

Ian Dawson wrote lednotify, a tool to flash the lamp when mail or chat messages arrive.

Written by Christian Weiske.

Comments? Please send an e-mail.