Commit 98287c99a6cd73409a7e6cc537debba0612a49a2

Authored by John Snowdon
1 parent 8f45534e91
Exists in master

change the colour of the lcd screen based on the load of the cpu, for an easy to…

… see visual indication: green - orange - yellow - red
Showing 2 changed files with 21 additions and 2 deletions   Show diff stats
output.py
... ... @@ -79,8 +79,16 @@ class Output():
79 79 else:
80 80 self.errors = False
81 81  
  82 + # If CPU load is above a trigger level,
82 83 # If no errors, screen defaults back to green
83   - self.matrix.matrixRGB(0,255,0)
  84 + if data.cpu_percent_avg >= settings.CPU_HIGH['level']:
  85 + self.matrix.matrixRGB(settings.CPU_HIGH['r'],settings.CPU_HIGH['g'],settings.CPU_HIGH['b'])
  86 + elif data.cpu_percent_avg >= settings.CPU_MED['level']:
  87 + self.matrix.matrixRGB(settings.CPU_MED['r'],settings.CPU_MED['g'],settings.CPU_MED['b'])
  88 + elif data.cpu_percent_avg >= settings.CPU_LOW['level']:
  89 + self.matrix.matrixRGB(settings.CPU_LOW['r'],settings.CPU_LOW['g'],settings.CPU_LOW['b'])
  90 + else:
  91 + self.matrix.matrixRGB(settings.CPU_IDLE['r'],settings.CPU_IDLE['g'],settings.CPU_IDLE['b'])
84 92  
85 93 # Are we showing alternate screen 1?
86 94 # Show CPU
... ... @@ -119,6 +127,7 @@ class Output():
119 127 t = "RAM %s of %s used, %s buffers." % (self.sizeof_fmt(num = data.ram_avail), self.sizeof_fmt(num = data.ram_total), (self.sizeof_fmt(num = data.ram_buffer)))
120 128 t = ' '.join(t.split())
121 129 for i in range (0, len(t)):
  130 + data.update()
122 131 self.matrix.matrixClear()
123 132 self.matrix.matrixWrite("CPU %2d%% %sMHz" % (data.cpu_percent_avg, data.cpu_mhz))
124 133 display_text = t[i:(i+settings.DISPLAY_WIDTH)]
... ... @@ -261,6 +270,7 @@ class Output():
261 270 # unless we had errors last time, so
262 271 # check for errors again.
263 272 if self.errors:
  273 + d.zap()
264 274 d.update(services = True)
265 275 else:
266 276 d.update()
... ...
settings.py
... ... @@ -65,4 +65,13 @@ ERR_SERVICE_NOVAb = "Nova client error or unable to contact controller."
65 65 ERR_SERVICE_CINDER = "Cinder error or service not running."
66 66 ERR_SERVICE_GLANCE = "Glance error or service not running."
67 67 ERR_SERVICE_NEUTRONa = "Neutron error or service not running."
68   -ERR_SERVICE_NEUTRONb = "Neutron client error or unable to contact controller."
69 68 \ No newline at end of file
  69 +ERR_SERVICE_NEUTRONb = "Neutron client error or unable to contact controller."
  70 +
  71 +# Trigger levels for various metrics
  72 +# and the colour to change the backlight of the lcd module
  73 +# when that mode is active
  74 +CPU_HIGH = { 'level' : 50, 'r': 255, 'g': 0, 'b': 0 }
  75 +CPU_MED = { 'level' : 25, 'r': 255, 'g': 255, 'b': 0 }
  76 +CPU_LOW = { 'level' : 10, 'r': 255, 'g': 165, 'b': 0 }
  77 +CPU_IDLE = { 'level' : 0, 'r': 0, 'g': 255, 'b': 0 }
  78 +
... ...