diff options
author | nicolargo <nicolargo@nicolargo-fujitsu.(none)> | 2012-01-31 14:37:56 +0100 |
---|---|---|
committer | nicolargo <nicolargo@nicolargo-fujitsu.(none)> | 2012-01-31 14:37:56 +0100 |
commit | 1c2094998c30468deaab6700cac7b4866a02d7dc (patch) | |
tree | 5af1e6cccac45a8e1ad4dd81eec33581d551fc94 | |
parent | 1a2626ed278415baebfa23781ab7bfd60554b87e (diff) |
version 1.3.7v1.3.7
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | README | 23 | ||||
-rw-r--r-- | README-fr | 27 | ||||
l---------[-rw-r--r--] | README.md | 232 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | buildout.cfg | 2 | ||||
-rw-r--r-- | doc/logs.png | bin | 0 -> 11975 bytes | |||
-rw-r--r-- | man/glances.1 | 4 | ||||
-rw-r--r-- | screenshot.png | bin | 97775 -> 102609 bytes | |||
-rw-r--r-- | setup.py | 4 | ||||
-rwxr-xr-x | src/glances.py | 447 |
11 files changed, 391 insertions, 352 deletions
@@ -1,6 +1,8 @@ Version 1.3.7 ============= + * Display (if terminal space is available) an alerts history (logs) + * Add a limits classe to manage stats limits * Manage black and white console (issue #31) Version 1.3.6 @@ -23,12 +23,12 @@ Packages exist for Arch, Fedora, Redhat ... Get the latest version: - $ wget https://github.com/downloads/nicolargo/glances/glances-1.3.6.tar.gz + $ wget https://github.com/downloads/nicolargo/glances/glances-1.3.7.tar.gz Glances use a standard GNU style installer: - $ tar zxvf glances-1.3.6.tar.gz - $ cd glances-1.3.6 + $ tar zxvf glances-1.3.7.tar.gz + $ cd glances-1.3.7 $ ./configure $ make $ sudo make install @@ -85,6 +85,7 @@ When Glances is running, you can press: * 'c' to sort the processes list by CPU consumption * 'd' Disable or enable the disk IO stats * 'f' Disable or enable the file system stats +* 'l' Disable or enable the logs * 'm' to sort the processes list by process size * 'n' Disable or enable the network interfaces stats * 'q' Exit @@ -208,6 +209,22 @@ sorted by CPU of memory consumption. The number of processes in the list is adapted to the screen size. +### Logs + +![screenshot](https://github.com/nicolargo/glances/raw/master/doc/logs.png) + +A logs list is displayed in the bottom of the screen if (an only if): + +* at least one WARNING or CRITICAL alert was occured. +* space is available in the bottom of the console/terminal + +There is one line per alert with the following information: + +* start date +* end date +* alert name +* (min/avg/max) values + ### Footer ![screenshot](https://github.com/nicolargo/glances/raw/master/doc/footer.png) @@ -27,14 +27,14 @@ Le projet Glances est hébergé sur GitHUB: https://github.com/nicolargo/glances Pour l'installer, il suffit de suivre les instructions suivantes depuis un terminal. -Récupération de la dernière version (1.3.6): +Récupération de la dernière version (1.3.7): - $ wget https://github.com/downloads/nicolargo/glances/glances-1.3.6.tar.gz + $ wget https://github.com/downloads/nicolargo/glances/glances-1.3.7.tar.gz Procédez ensuite à l'installation: - $ tar zxvf glances-1.3.6.tar.gz - $ cd glances-1.3.6 + $ tar zxvf glances-1.3.7.tar.gz + $ cd glances-1.3.7 $ ./configure $ make $ sudo make install @@ -104,6 +104,7 @@ Quand Glances est lancé, il est possible d'utiliser les touches suivantes: * 'c' pour forcer le tri par consommation CPU * 'd' pour desactiver ou activer l'affichage des entrées/sorties disques * 'f' pour desactiver ou activer l'affichage de l'occupation des FS +* 'l' pour desactiver ou activer l'affichage des logs * 'm' pour forcer le tri par consommation MEMOIRE * 'n' pour desactiver ou activer l'affichage des interfaces réseau * 'q' sortir de Glances (il est également possible d'utiliser CTRL-C) @@ -229,6 +230,22 @@ détaillée. Le nombre des processus affichés est adapté à la taille de la fenêtre. +### Logs + +![screenshot](https://github.com/nicolargo/glances/raw/master/doc/logs.png) + +Une liste des dernières alertes relevées par Glances est affichée si: + +* au moins une alerte de type WARNING ou CRITICAL est arrivée +* la console/fenêtre dispose de la place nécessaire + +Glances affiche une ligne par alerte: + +* date de début +* date de fin +* description de l'alerte +* valeur (min/moyenne/max) lors de l'alerte + ### Pied de page ![screenshot](https://github.com/nicolargo/glances/raw/master/doc/footer.png) @@ -254,6 +271,4 @@ Notamment: * Packaging pour Debian, Ubuntu, BSD et toutes autres distributions * Controle de la présence des librairie dans le fichier configure.ac -* Inclure les stats de FS directement dans python-statgrab -* Ajout d'une fenêtre d'aide * Optimisation du code diff --git a/README.md b/README.md index c2afdc1e..100b9382 100644..120000 --- a/README.md +++ b/README.md @@ -1,231 +1 @@ -[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=nicolargo&url=https://github.com/nicolargo/glances&title=Glances&language=&tags=github&category=software) - -============================= -Glances -- Eye on your system -============================= - -## Description - -Glances is a CLI curses based monitoring tool for GNU/Linux or BSD OS. - -Glances uses the libstatgrab library to get information from your system. -It is developed in Python and uses the python-statgrab lib. - -![screenshot](https://github.com/nicolargo/glances/raw/master/screenshot.png) - -## Installation - -### From package manager - -Packages exist for Arch, Fedora, Redhat ... - -### From source - -Get the latest version: - - $ wget https://github.com/downloads/nicolargo/glances/glances-1.3.6.tar.gz - -Glances use a standard GNU style installer: - - $ tar zxvf glances-1.3.6.tar.gz - $ cd glances-1.3.6 - $ ./configure - $ make - $ sudo make install - -Pre-requisites: - -* Python 2.6+ (not tested with Python 3+) -* python-statgrab 0.5+ (did NOT work with python-statgrab 0.4) - -Notes: For Debian. -The Debian Squeeze repos only include the python-statgrab 0.4. -You had to install the version 0.5 using the following commands: - - $ sudo apt-get install libstatgrab-dev pkg-config python-dev make - $ wget http://ftp.uk.i-scream.org/sites/ftp.i-scream.org/pub/i-scream/pystatgrab/pystatgrab-0.5.tar.gz - $ tar zxvf pystatgrab-0.5.tar.gz - $ cd pystatgrab-0.5/ - $ ./setup.py build - $ sudo ./setup.py install - -Notes: For Ubuntu 10.04 and 10.10. -The instruction to install the version 0.5 are here: -https://github.com/nicolargo/glances/issues/5#issuecomment-3033194 - -## Running - -Easy: - - $ glances.py - -## User guide - -By default, stats are refreshed every second, to change this setting, you can -use the -t option. For exemple to set the refrech rate to 5 seconds: - - $ glances.py -t 5 - -Importants stats are colored: - -* GREEN: stat counter is "OK" -* BLUE: stat counter is "CAREFUL" -* MAGENTA: stat counter is "WARNING" -* RED: stat counter is "CRITICAL" - -When Glances is running, you can press: - -* 'h' to display an help message whith the keys you can press -* 'a' to set the automatic mode. The processes are sorted automatically - - If CPU > 70%, sort by process "CPU consumption" - - If MEM > 70%, sort by process "memory size" - -* 'c' to sort the processes list by CPU consumption -* 'd' Disable or enable the disk IO stats -* 'f' Disable or enable the file system stats -* 'm' to sort the processes list by process size -* 'n' Disable or enable the network interfaces stats -* 'q' Exit - -### Header - -![screenshot](https://github.com/nicolargo/glances/raw/master/doc/header.png) - -The header shows the Glances version, the host name and the operating -system name, version and architecture. - -### CPU - -![screenshot](https://github.com/nicolargo/glances/raw/master/doc/cpu.png) - -The CPU states are shown as a percentage and for the configured refresh -time. - -If user|kernel|nice CPU is < 50%, then status is set to "OK". - -If user|kernel|nice CPU is > 50%, then status is set to "CAREFUL". - -If user|kernel|nice CPU is > 70%, then status is set to "WARNING". - -If user|kernel|nice CPU is > 90%, then status is set to "CRITICAL". - -### Load - -![screenshot](https://github.com/nicolargo/glances/raw/master/doc/load.png) - -On the Nosheep blog, Zach defines the average load: "In short it is the -average sum of the number of processes waiting in the run-queue plus the -number currently executing over 1, 5, and 15 minute time periods." - -Glances gets the number of CPU cores to adapt the alerts. With Glances, -alerts on average load are only set on 5 and 15 mins. - -If average load is < O.7*Core, then status is set to "OK". - -If average load is > O.7*Core, then status is set to "CAREFUL". - -If average load is > 1*Core, then status is set to "WARNING". - -If average load is > 5*Core, then status is set to "CRITICAL". - -### Memory - -![screenshot](https://github.com/nicolargo/glances/raw/master/doc/mem.png) - -Glances uses tree columns: memory (RAM), swap and "real". - -Real used memory is: used - cache. - -Real free memory is: free + cache. - -With Glances, alerts are only set for on used swap and real memory. - -If memory is < 50%, then status is set to "OK". - -If memory is > 50%, then status is set to "CAREFUL". - -If memory is > 70%, then status is set to "WARNING". - -If memory is > 90%, then status is set to "CRITICAL". - -### Network bit rate - -![screenshot](https://github.com/nicolargo/glances/raw/master/doc/network.png) - -Glances display the network interface bit rate. The unit is adapted -dynamicaly (bits per second, Kbits per second, Mbits per second...). - -Alerts are set only if the network interface maximum speed is available. - -If bitrate is < 50%, then status is set to "OK". - -If bitrate is > 50%, then status is set to "CAREFUL". - -If bitrate is > 70%, then status is set to "WARNING". - -If bitrate is > 90%, then status is set to "CRITICAL". - -For exemple, on a 100 Mbps Ethernet interface, the warning status is set -if the bit rate is higher than 70 Mbps. - -### Disk I/O - -![screenshot](https://github.com/nicolargo/glances/raw/master/doc/diskio.png) - -Glances display the disk I/O throughput. The unit is adapted dynamicaly -(bytes per second, Kbytes per second, Mbytes per second...). - -There is no alert on this information. - -### Filesystem - -![screenshot](https://github.com/nicolargo/glances/raw/master/doc/fs.png) - -Glances display the total and used filesytem disk space. The unit is -adapted dynamicaly (bytes per second, Kbytes per second, Mbytes per -second...). - -Alerts are set for used disk space: - -If disk used is < 50%, then status is set to "OK". - -If disk used is > 50%, then status is set to "CAREFUL". - -If disk used is > 70%, then status is set to "WARNING". - -If disk used is > 90%, then status is set to "CRITICAL". - -### Processes - -![screenshot](https://github.com/nicolargo/glances/raw/master/doc/processlist.png) - -Glances displays a summary and a list of processes. - -By default (or if you hit the 'a' key) the process list is automaticaly -sorted by CPU of memory consumption. - -The number of processes in the list is adapted to the screen size. - -### Footer - -![screenshot](https://github.com/nicolargo/glances/raw/master/doc/footer.png) - -Glances displays a caption and the current time/date. - -## Localisation - -To generate french locale execute as root or sudo : -i18n_francais_generate.sh - -To generate spanish locale execute as root or sudo : -i18n_espanol_generate.sh - -## Todo - -You are welcome to contribute to this software. - -* Packaging for Debian, Ubuntu, BSD... -* Check the needed Python library in the configure.ac -* Add file system stats when the python-statgrab is corrected +README
\ No newline at end of file @@ -1,4 +1,4 @@ - Packaging for .deb (Debian|Ubuntu|Mint) Linux distributions (contributors needed) - Test/coding for xBSD - Add control to check the libstatgrab version in the script -- Add thermal information for CPU (issue #26) +- Add a limit class to manage the OK ,CAREFUL,WARNING,CRITICAL limits diff --git a/buildout.cfg b/buildout.cfg index d87898f5..dfdf6b0f 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -30,7 +30,7 @@ include-site-packages = false allowed-eggs-from-site-packages = false [config] -glances_version = 1.3.6 +glances_version = 1.3.7 pystatgrab_version = 0.5 pystatgrab_download_url = http://ftp.uk.i-scream.org/sites/ftp.i-scream.org/pub/i-scream/pystatgrab diff --git a/doc/logs.png b/doc/logs.png Binary files differnew file mode 100644 index 00000000..d51f2be8 --- /dev/null +++ b/doc/logs.png diff --git a/man/glances.1 b/man/glances.1 index 70229719..5fd60e39 100644 --- a/man/glances.1 +++ b/man/glances.1 @@ -1,4 +1,4 @@ -.TH glances 1 "January, 2012" "version 1.3.6" "USER COMMANDS" +.TH glances 1 "January, 2012" "version 1.3.7" "USER COMMANDS" .SH NAME glances \- CLI curses based monitoring tool .SH SYNOPSIS @@ -23,6 +23,8 @@ You can use the following keys to sort the processesi list: .PP 'h' Hide or show the help message .PP + 'l' Hide or show the logs +.PP 'm' the processes list is sorted by process size .PP 'n' Disable or enable the network interfaces stats diff --git a/screenshot.png b/screenshot.png Binary files differindex 04d5faf3..a9efb2b5 100644 --- a/screenshot.png +++ b/screenshot.png @@ -11,8 +11,8 @@ def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() setup( name='Glances', - version='1.3.6', - download_url='https://github.com/downloads/nicolargo/glances/glances-1.3.6.tar.gz', + version='1.3.7', + download_url='https://github.com/downloads/nicolargo/glances/glances-1.3.7.tar.gz', url='https://github.com/nicolargo/glances', description='CLI curses-based monitoring tool', author='Nicolas Hennion', diff --git a/src/glances.py b/src/glances.py index 52f52783..8ff0b818 100755 --- a/src/glances.py +++ b/src/glances.py @@ -10,7 +10,7 @@ # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # -# glances is distributed in the hope that it will be useful, but +# Glances is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU Lesser General Public License for more details. @@ -19,26 +19,33 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>."; # -import os -import getopt -import sys -import signal -import time -import datetime -import multiprocessing -import gettext +from __future__ import generators -#i18n -#==== +try: + import os + import getopt + import sys + import signal + import time + import datetime + import multiprocessing + import gettext +except KeyboardInterrupt: + pass + + +# i18n +#===== application = 'glances' +__version__ = "1.3.7" gettext.install(application) try: import statgrab except: - print 'Statgrab initialization failed, Glances cannot start.' - print '' + print _('Statgrab initialization failed, Glances cannot start.') + print sys.exit(1) try: @@ -49,14 +56,9 @@ except: print sys.exit(1) -# Globals variables -#================== - -# The glances version id -__version__ = "1.3.6" -# Class -#====== +# Classes +#======== class Timer(): """ @@ -64,12 +66,147 @@ class Timer(): """ def __init__(self, duration): + self.started(duration) + + def started(self, duration): self.target = time.time() + duration def finished(self): return time.time() > self.target +class glancesLimits(): + """ + Manage the limit OK,CAREFUL,WARNING,CRITICAL for each stats + """ + + # The limit list is stored in an hash table: + # limits_list[STAT] = [ CAREFUL , WARNING , CRITICAL ] + # Exemple: + # limits_list['STD'] = [ 50, 70 , 90 ] + + __limits_list = { # CAREFUL WARNING CRITICAL + 'STD': [50, 70, 90], + 'LOAD': [0.7, 1.0, 5.0] + } + + def getSTDCareful(self): + return self.__limits_list['STD'][0] + + def getSTDWarning(self): + return self.__limits_list['STD'][1] + + def getSTDCritical(self): + return self.__limits_list['STD'][2] + + def getLOADCareful(self, core = 1): + return self.__limits_list['LOAD'][0] * core + + def getLOADWarning(self, core = 1): + return self.__limits_list['LOAD'][1] * core + + def getLOADCritical(self, core = 1): + return self.__limits_list['LOAD'][2] * core + + +class glancesLogs(): + """ + The main class to manage logs inside the Glances software + Logs is a list of list: + [["begin", "end", "WARNING|CRITICAL", "CPU|LOAD|MEM", MAX, AVG, MIN, SUM, COUNT],...] + """ + + def __init__(self): + """ + Init the logs classe + """ + # Maximum size of the logs list + self.logs_max = 10 + + # Init the logs list + self.logs_list = [] + + def get(self): + """ + Return the logs list (RAW) + """ + return self.logs_list + + def len(self): + """ + Return the number of item in the log list + """ + return self.logs_list.__len__() + + def __itemexist__(self, item_type): + """ + An item exist in the list if: + * end is < 0 + * item_type is matching + """ + for i in range(self.len()): + if ((self.logs_list[i][1] < 0) and + (self.logs_list[i][3] == item_type)): + return i + return -1 + + def add(self, item_state, item_type, item_value): + """ + item_state = "OK|CAREFUL|WARNING|CRITICAL" + item_type = "CPU|LOAD|MEM" + item_value = value + Item is defined by: + ["begin", "end", "WARNING|CRITICAL", "CPU|LOAD|MEM", MAX, AVG, MIN, SUM, COUNT] + If item is a 'new one': + Add the new item at the beginning of the logs list + Else: + Update the existing item + """ + item_index = self.__itemexist__(item_type) + if (item_index < 0): + # Item did not exist, add if WARNING or CRITICAL + if ((item_state == "WARNING") or + (item_state == "CRITICAL")): + # Time is stored in Epoch format + # Epoch -> DMYHMS = datetime.datetime.fromtimestamp(epoch) + item = [] + item.append(time.mktime(datetime.datetime.now().timetuple())) + item.append(-1) + item.append(item_state) # STATE: WARNING|CRITICAL + item.append(item_type) # TYPE: CPU, LOAD, MEM... + item.append(item_value) # MAX + item.append(item_value) # AVG + item.append(item_value) # MIN + item.append(item_value) # SUM + item.append(1) # COUNT + self.logs_list.insert(0, item) + if (self.len() > self.logs_max): + self.logs_list.pop() + else: + # Item exist, update + if ((item_state == "OK") or + (item_state == "CAREFUL")): + # Close the item + self.logs_list[item_index][1] = time.mktime(datetime.datetime.now().timetuple()) + else: + # Update the item + # State + if (item_state == "CRITICAL"): + self.logs_list[item_index][2] = item_state + # Value + if (item_value > self.logs_list[item_index][4]): + # MAX + self.logs_list[item_index][4] = item_value + elif (item_value < self.logs_list[item_index][6]): + # MIN + self.logs_list[item_index][6] = item_value + # AVG + self.logs_list[item_index][7] += item_value + self.logs_list[item_index][8] += 1 + self.logs_list[item_index][5] = self.logs_list[item_index][7] / self.logs_list[item_index][8] + return self.len() + + class glancesGrabFs(): """ Get FS stats: idem as structure http://www.i-scream.org/libstatgrab/docs/sg_get_fs_stats.3.html @@ -281,7 +418,7 @@ class glancesStats(): # Else sort by cpu comsoption sortedby = 'cpu_percent' if ( self.mem['total'] != 0): - if ( ( (self.mem['used'] - self.mem['cache']) * 100 / self.mem['total']) > 70): + if ( ( (self.mem['used'] - self.mem['cache']) * 100 / self.mem['total']) > limits.getSTDWarning()): sortedby = 'proc_size' return sorted(self.process, key=lambda process: process[sortedby], reverse=True) @@ -296,8 +433,8 @@ class glancesScreen(): """ # By default the process list is automaticaly sorted - # If global CPU > 75% => Sorted by process Cpu consomption - # If global used MEM > 75% => Sorted by process size + # If global CPU > WANRING => Sorted by process Cpu consomption + # If global used MEM > WARINING => Sorted by process size __process_sortedby = 'auto' def __init__(self, refresh_time = 1): @@ -315,6 +452,7 @@ class glancesScreen(): self.diskio_x = 0 ; self.diskio_y = -1 self.fs_x = 0 ; self.fs_y = -1 self.process_x = 30; self.process_y = 9 + self.log_x = 0 ; self.log_y = -1 self.help_x = 30; self.help_y = 12 self.now_x = 79; self.now_y = 3 self.caption_x = 0 ; self.caption_y = 3 @@ -355,29 +493,45 @@ class glancesScreen(): # Colors text styles self.no_color = curses.color_pair(1) self.default_color = curses.color_pair(3)|curses.A_BOLD - self.if50pc_color = curses.color_pair(4)|curses.A_BOLD - self.if70pc_color = curses.color_pair(5)|curses.A_BOLD - self.if90pc_color = curses.color_pair(2)|curses.A_BOLD + self.ifCAREFUL_color = curses.color_pair(4)|curses.A_BOLD + self.ifWARNING_color = curses.color_pair(5)|curses.A_BOLD + self.ifCRITICAL_color = curses.color_pair(2)|curses.A_BOLD else: # B&W text styles self.no_color = curses.A_NORMAL self.default_color = curses.A_NORMAL - self.if50pc_color = curses.A_UNDERLINE - self.if70pc_color = curses.A_BOLD - self.if90pc_color = curses.A_REVERSE + self.ifCAREFUL_color = curses.A_UNDERLINE + self.ifWARNING_color = curses.A_BOLD + self.ifCRITICAL_color = curses.A_REVERSE + + # Define the colors list (hash table) + self.__colors_list = { + # CAREFUL WARNING CRITICAL + 'DEFAULT': self.no_color, + 'OK': self.default_color, + 'CAREFUL': self.ifCAREFUL_color, + 'WARNING': self.ifWARNING_color, + 'CRITICAL': self.ifCRITICAL_color + } # By default all the stats are displayed self.network_tag = True self.diskio_tag = True self.fs_tag = True + self.log_tag = True # Init main window self.term_window = self.screen.subwin(0, 0) # Init help panel - term_help = self.screen.subwin(self.term_h-self.help_y-2, self.term_w-self.help_x, self.help_y, self.help_x) - self.panel_help = curses.panel.new_panel(term_help) - self.hideHelp() + # TODO: pb when size of the screen < 22 lines + screen_x = self.screen.getmaxyx()[1] + screen_y = self.screen.getmaxyx()[0] + if (screen_x > (self.term_w-self.help_x) and + (screen_y > (self.term_h-self.help_y-2))): + term_help = self.screen.subwin(self.term_h-self.help_y-2, self.term_w-self.help_x, self.help_y, self.help_x) + self.panel_help = curses.panel.new_panel(term_help) + self.hideHelp() # Init refresh time self.__refresh_time = refresh_time @@ -413,69 +567,76 @@ class glancesScreen(): else: return str(int(val)) - def __getColor(self, current = 0, max = 100): - # If current > 50% of max then color = self.if50pc_color / A_DIM - # If current > 70% of max then color = self.if70pc_color / A_BOLD - # If current > 90% of max then color = self.if90pc_color / A_REVERSE - # By default: color = self.default_color / 0 + def __getAlert(self, current = 0, max = 100): + # If current < CAREFUL of max then alert = OK + # If current > CAREFUL of max then alert = CAREFUL + # If current > WARNING of max then alert = WARNING + # If current > CRITICAL of max then alert = CRITICAL try: (current * 100) / max except ZeroDivisionError: - return 0 + return 'DEFAULT' variable = (current * 100) / max - if variable > 90: - if self.hascolors: - return self.if90pc_color - else: - return curses.A_REVERSE - elif variable > 70: - if self.hascolors: - return self.if70pc_color - else: - return curses.A_BOLD - elif variable > 50: - if self.hascolors: - return self.if50pc_color - else: - return curses.A_DIM - else: - if self.hascolors: - return self.default_color - else: - return 0 + if variable > limits.getSTDCritical(): + return 'CRITICAL' + elif variable > limits.getSTDWarning(): + return 'WARNING' + elif variable > limits.getSTDCareful(): + return 'CAREFUL' + + return 'OK' + + + def __getColor(self, current = 0, max = 100): + return self.__colors_list[self.__getAlert(current, max)] + + + def __getCpuAlert(self, current = 0, max = 100): + return self.__getAlert(current, max) + + + def __getCpuColor(self, current = 0, max = 100): + return self.__getColor(current, max) + + + def __getLoadAlert(self, current = 0, core = 1): + # If current < CAREFUL*core of max then alert = OK + # If current > CAREFUL*core of max then alert = CAREFUL + # If current > WARNING*core of max then alert = WARNING + # If current > CRITICAL*core of max then alert = CRITICAL + + if current > limits.getLOADCritical(core): + return 'CRITICAL' + elif current > limits.getLOADWarning(core): + return 'WARNING' + elif current > limits.getLOADCareful(core): + return 'CAREFUL' + + return 'OK' def __getLoadColor(self, current = 0, core = 1): - # core is the number of CPU core - # If current > 0.7*core then color = self.if50pc_color / A_DIM - # If current > 1.0*core then color = self.if70pc_color / A_BOLD - # If current > 5.0*core then color = self.if90pc_color / A_REVERSE - # By default: color = self.default_color / 0 - - if current > (5.0 * core): - if self.hascolors: - return self.if90pc_color - else: - return curses.A_REVERSE - elif current > (1.0 * core): - if self.hascolors: - return self.if70pc_color - else: - return curses.A_BOLD - elif current > (0.7 * core): - if self.hascolors: - return self.if50pc_color - else: - return curses.A_DIM - else: - if self.hascolors: - return self.default_color - else: - return 0 + return self.__colors_list[self.__getLoadAlert(current, core)] + def __getMemAlert(self, current = 0, max = 100): + return self.__getAlert(current, max) + + + def __getMemColor(self, current = 0, max = 100): + return self.__getColor(current, max) + + + def __getNetColor(self, current = 0, max = 100): + return self.__getColor(current, max) + + + def __getFsColor(self, current = 0, max = 100): + return self.__getColor(current, max) + + def __catchKey(self): # Get key self.pressedkey = self.term_window.getch(); @@ -504,6 +665,9 @@ class glancesScreen(): self.showHelp() else: self.hideHelp() + elif (self.pressedkey == 108): + # 'l' > Enable/Disable logs list + self.log_tag = not self.log_tag elif (self.pressedkey == 109): # 'm' > Sort process list by Mem usage self.setProcessSortedBy('proc_size') @@ -530,8 +694,9 @@ class glancesScreen(): self.displayMem(stats.getMem(), stats.getMemSwap()) network_count = self.displayNetwork(stats.getNetwork(), stats.getNetworkInterface()) diskio_count = self.displayDiskIO(stats.getDiskIO(), self.network_y + network_count) - self.displayFs(stats.getFs(), self.network_y + network_count + diskio_count) - self.displayProcess(stats.getProcessCount(), stats.getProcessList(screen.getProcessSortedBy())) + fs_count = self.displayFs(stats.getFs(), self.network_y + network_count + diskio_count) + log_count = self.displayLog(self.network_y + network_count + diskio_count + fs_count) + self.displayProcess(stats.getProcessCount(), stats.getProcessList(screen.getProcessSortedBy()), log_count) self.displayCaption() self.displayNow(stats.getNow()) @@ -580,11 +745,11 @@ class glancesScreen(): helpWindow.resize(self.term_h-self.help_y-2, self.term_w-self.help_x) helpWindow.clear() msg = _("Glances help (press 'h' to hide)") - helpWindow.addnstr(1, 2,_("'h'\tto display|hide this help message"), self.term_w-self.help_x-4, self.help_color if self.hascolors else 0) - helpWindow.addnstr(2, 2,_("'a'\tto sort processes automatically"), self.term_w-self.help_x-4, self.help_color if self.hascolors else 0) - helpWindow.addnstr(3, 2, _("'c'\tto sort processes by CPU consumption"), self.term_w-self.help_x-4, self.help_color if self.hascolors else 0) - helpWindow.addnstr(4, 2, _("'d'\tto disable|enable the disk IO stats"), self.term_w-self.help_x-4, self.help_color if self.hascolors else 0) - helpWindow.addnstr(5, 2, _("'f'\tto disable|enable the file system stats"), self.term_w-self.help_x-4, self.help_color if self.hascolors else 0) + helpWindow.addnstr(1, 2, _("'a'\tto sort processes automatically"), self.term_w-self.help_x-4, self.help_color if self.hascolors else 0) + helpWindow.addnstr(2, 2, _("'c'\tto sort processes by CPU consumption"), self.term_w-self.help_x-4, self.help_colo |