Monitoring The Cluster Using the LCD Panel

I thought it would be nice to have a display on pi1 (the primary node) so found an LCD kit that hopefully I could write a little script to hack around to display the status of each data node.

So I purchased the Adafruit Char 16×2 LCD Plate from:

https://www.modmypi.com/raspberry-pi-expansion-boards/raspberry-pi-blue-and-white-16×2-LCD-kit

Then set about soldering it all up

20130715_135813_Macaulay Ave

tada!

20130715_143836_Macaulay Ave

I followed the guide here:

http://learn.adafruit.com/adafruit-16×2-character-lcd-plus-keypad-for-raspberry-pi/assembly

Once the kit was all soldered up you have to enable the linux kernel to recognise it

I followed the guide here

http://learn.adafruit.com/adafruit-16×2-character-lcd-plus-keypad-for-raspberry-pi/usage

I then modified the sample code to get the output from the cluster node status. The code I used is below

#!/usr/bin/python
from time import sleep
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
from subprocess import *
from time import sleep, strftime
from datetime import datetime

# Initialize the LCD plate. Should auto-detect correct I2C bus. If not,
# pass '0' for early 256 MB Model B boards or '1' for all later versions
lcd = Adafruit_CharLCDPlate()
# Clear display and show greeting, pause 1 sec
lcd.clear()
lcd.message("MySQL Cluster\n Running On Pi")
sleep(1)
cmd = "ndb_mgm -e show |grep ^id=[3,4]|awk {'print $1 $2 $3}'|sed s/=//g|sed 's/[(]/ /g'"

def run_cmd(cmd):
 p = Popen(cmd, shell=True, stdout=PIPE)
 output = p.communicate()[0]
 return output
while 1:
 lcd.clear()
 clusterstatus = run_cmd(cmd)
 lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n'))
sleep(2)
 lcd.clear()
 lcd.message(( clusterstatus ))
 sleep(2)

# Poll buttons, display message & set backlight accordingly
btn = ((lcd.LEFT , 'left'),
 (lcd.UP , 'up'),
 (lcd.DOWN , 'down'),
 (lcd.RIGHT , 'right'),
 (lcd.SELECT, ''))
prev = -1
while True:
 for b in btn:
 if lcd.buttonPressed(b[0]):
 if b is not prev:
 lcd.clear()
 lcd.message(b[1])
 prev = b
 break

The final result

About these ads

One thought on “Monitoring The Cluster Using the LCD Panel

  1. Pingback: Monitorando o MySQL Cluster por um mini LCD! Isso é Nerd! | Mathias Brem

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s