Skip to content

Commit

Permalink
Add limits to the quicklook plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed Feb 3, 2015
1 parent c66a7a8 commit 596d93a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
11 changes: 11 additions & 0 deletions conf/glances-test.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
[quicklook]
cpu_careful=50
cpu_warning=70
cpu_critical=90
mem_careful=50
mem_warning=70
mem_critical=90
swap_careful=50
swap_warning=70
swap_critical=90

[cpu]
# Default values if not defined: 50/70/90
user_careful=50
Expand Down
11 changes: 11 additions & 0 deletions conf/glances.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
[quicklook]
cpu_careful=50
cpu_warning=70
cpu_critical=90
mem_careful=50
mem_warning=70
mem_critical=90
swap_careful=50
swap_warning=70
swap_critical=90

[cpu]
# Default values if not defined: 50/70/90
user_careful=50
Expand Down
31 changes: 18 additions & 13 deletions glances/plugins/glances_quicklook.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def update_views(self):
# Call the father's method
GlancesPlugin.update_views(self)

# Add specifics informations
# Alert only
for key in ['cpu', 'mem', 'swap']:
if key in self.stats:
self.views[key]['decoration'] = self.get_alert(self.stats[key], header=key)

def msg_curse(self, args=None, max_width=10):
"""Return the list to display in the UI"""
# Init the return message
Expand All @@ -84,20 +90,19 @@ def msg_curse(self, args=None, max_width=10):
if self.stats == {} or args.disable_quicklook:
return ret

# Build the string message
# Define the bar
bar = Bar(max_width, pre_char='|', post_char='|', empty_char=' ')
bar.set_percent(self.stats['cpu'])
msg = '{0:>4} {1}'.format(_("CPU"), bar)
ret.append(self.curse_add_line(msg))
ret.append(self.curse_new_line())
bar.set_percent(self.stats['mem'])
msg = '{0:>4} {1}'.format(_("MEM"), bar)
ret.append(self.curse_add_line(msg))
ret.append(self.curse_new_line())
bar.set_percent(self.stats['swap'])
msg = '{0:>4} {1}'.format(_("SWAP"), bar)
ret.append(self.curse_add_line(msg))
ret.append(self.curse_new_line())

# Build the string message
for key in ['cpu', 'mem', 'swap']:
bar.set_percent(self.stats[key])
msg = '{0:>4} '.format(key.upper())
ret.append(self.curse_add_line(msg))
msg = '{0}'.format(bar)
ret.append(self.curse_add_line(msg,
self.get_views(key=key,
option='decoration')))
ret.append(self.curse_new_line())

# Return the message with decoration
return ret

0 comments on commit 596d93a

Please sign in to comment.