summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolargo@nicolargo-boulot.(none)>2012-03-30 17:34:48 +0200
committernicolargo <nicolargo@nicolargo-boulot.(none)>2012-03-30 17:34:48 +0200
commit05cad032134894e3506470ae60fe19cc789535bb (patch)
tree457ac936171ea8a9d7bdeb374c1b682c5cdf16f2
parentcfcb49054fff0262461e55bf283bb72c7b52ad5f (diff)
Code checked with PEP8 checker
-rw-r--r--NEWS1
-rw-r--r--[l---------]README.md261
-rwxr-xr-xglances/glances.py3318
3 files changed, 2027 insertions, 1553 deletions
diff --git a/NEWS b/NEWS
index fe8c5ec3..72bf4139 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Version 1.4
* Sort by Process name ('p' key)
* Only major stats (CPU, Load and memory) use background colors
* Improve operating system name
+ * Code is now checked with pep8
Version 1.3.7
=============
diff --git a/README.md b/README.md
index 100b9382..e8a7556d 120000..100644
--- a/README.md
+++ b/README.md
@@ -1 +1,260 @@
-README \ No newline at end of file
+[![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 PPA (Ubuntu/Mint)
+
+Thanks to Arnaud Hartmann, a PPA is available for the stable branch.
+
+To install it on your Ubuntu system:
+
+ $ sudo add-apt-repository ppa:arnaud-hartmann/glances-stable
+ $ sudo apt-get update
+ $ sudo apt-get install glances
+
+The PPA is available for Ubuntu version 9.10 to 12.04.
+
+### From source
+
+Get the latest version:
+
+ $ 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.7.tar.gz
+ $ cd glances-1.3.7
+ $ ./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
+* '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
+
+### 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.
+
+### 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)
+
+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
diff --git a/glances/glances.py b/glances/glances.py
index bb72da3f..7ba2da6c 100755
--- a/glances/glances.py
+++ b/glances/glances.py
@@ -5,16 +5,16 @@
# Pre-requisites: Python 2.6+ and PsUtil 0.4.0+ (for full functions)
#
# Copyright (C) Nicolargo 2012 <nicolas@nicolargo.com>
-#
+#
# under the terms of the GNU Lesser General Public License as published
# 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
# 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.
-#
+#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.";
#
@@ -23,7 +23,7 @@ from __future__ import generators
__appname__ = 'glances'
__version__ = "1.4b16"
-__author__ = "Nicolas Hennion <nicolas@nicolargo.com>"
+__author__ = "Nicolas Hennion <nicolas@nicolargo.com>"
__licence__ = "LGPL"
# Libraries
@@ -32,30 +32,30 @@ __licence__ = "LGPL"
import sys
try:
- import os
- import platform
- import getopt
- import signal
- import time
- import datetime
- import multiprocessing
- import gettext
+ import os
+ import platform
+ import getopt
+ import signal
+ import time
+ import datetime
+ import multiprocessing
+ import gettext
except ImportError:
- print("Error during Python libraries import: "+str(sys.exc_info()[1]))
- sys.exit(1)
+ print("Error during Python libraries import: " + str(sys.exc_info()[1]))
+ sys.exit(1)
# International
#==============
-
+
gettext.install(__appname__)
# Test methods
#=============
try:
- import curses
- import curses.panel
+ import curses
+ import curses.panel
except ImportError:
print _('Textmode GUI initialization failed, Glances cannot start.')
print _('Use Python 2.6 or higher')
@@ -63,1603 +63,1817 @@ except ImportError:
sys.exit(1)
try:
- import psutil
+ import psutil
except ImportError:
- print _('PsUtil library initialization failed, Glances cannot start.')
- print _('On Debian/Ubuntu, you can try (as root):')
- print _('# apt-get install python-dev python-pip')
- print _('# pip install psutil')
- print
- sys.exit(1)
-
+ print _('PsUtil library initialization failed, Glances cannot start.')
+ print _('On Debian/Ubuntu, you can try (as root):')
+ print _('# apt-get install python-dev python-pip')
+ print _('# pip install psutil')
+ print
+ sys.exit(1)
+
try:
- # get_cpu_percent method only available with PsUtil 0.2.0 or +
- psutil.Process(os.getpid()).get_cpu_percent(interval=0)
+ # get_cpu_percent method only available with PsUtil 0.2.0 or +
+ psutil.Process(os.getpid()).get_cpu_percent(interval=0)
except:
- psutil_get_cpu_percent_tag = False
+ psutil_get_cpu_percent_tag = False
else:
- psutil_get_cpu_percent_tag = True
+ psutil_get_cpu_percent_tag = True
try:
- # (phy|virt)mem_usage methods only available with PsUtil 0.3.0 or +
- psutil.phymem_usage()
- psutil.virtmem_usage()
+ # (phy|virt)mem_usage methods only available with PsUtil 0.3.0 or +
+ psutil.phymem_usage()
+ psutil.virtmem_usage()
except:
- psutil_mem_usage_tag = False
+ psutil_mem_usage_tag = False
else:
- psutil_mem_usage_tag = True
-
+ psutil_mem_usage_tag = True
+
try:
- # disk_(partitions|usage) methods only available with PsUtil 0.3.0 or +
- psutil.disk_partitions()
- psutil.disk_usage('/')
+ # disk_(partitions|usage) methods only available with PsUtil 0.3.0 or +
+ psutil.disk_partitions()
+ psutil.disk_usage('/')
except:
- psutil_fs_usage_tag = False
+ psutil_fs_usage_tag = False
else:
- psutil_fs_usage_tag = True
+ psutil_fs_usage_tag = True
try:
- # disk_io_counters method only available with PsUtil 0.4.0 or +
- psutil.disk_io_counters()
+ # disk_io_counters method only available with PsUtil 0.4.0 or +
+ psutil.disk_io_counters()
except:
- psutil_disk_io_tag = False
+ psutil_disk_io_tag = False
else:
- psutil_disk_io_tag = True
+ psutil_disk_io_tag = True
try:
- # network_io_counters method only available with PsUtil 0.4.0 or +
- psutil.network_io_counters()
+ # network_io_counters method only available with PsUtil 0.4.0 or +
+ psutil.network_io_counters()
except:
- psutil_network_io_tag = False
+ psutil_network_io_tag = False
else:
- psutil_network_io_tag = True
+ psutil_network_io_tag = True
try:
- # HTML output
- import jinja2
+ # HTML output
+ import jinja2
except ImportError:
- jinja_tag = False
+ jinja_tag = False
else:
- jinja_tag = True
+ jinja_tag = True
try:
- # CSV output
- import csv
+ # CSV output
+ import csv
except ImportError:
- csv_tag = False
+ csvlib_tag = False
else:
- csv_tag = True
+ csvlib_tag = True
# Classes
#========
class Timer():
- """
- The timer class
- """
-
- def __init__(self, duration):
- self.started(duration)
-
- def started(self, duration):
- self.target = time.time() + duration
-
- def finished(self):
- return time.time() > self.target
+ """
+ The timer class
+ """
+
+ 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 __init__(self, careful = 50, warning = 70, critical = 90):
- self.__limits_list['STD'] = [careful, warning, critical]
-
- 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
-
+ """
+ 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 ]
+
+ #_______________________________CAREFUL WARNING CRITICAL
+ __limits_list = {
+ 'STD': [50, 70, 90],
+ 'LOAD': [0.7, 1.0, 5.0]
+ }
+
+ def __init__(self, careful=50, warning=70, critical=90):
+ self.__limits_list['STD'] = [careful, warning, critical]
+
+ 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()
+ """
+ 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
- """
-
- def __init__(self):
- """
- Init FS stats
- """
-
- # Ignore the following FS
- self.ignore_fsname = ('', 'none', 'gvfs-fuse-daemon', 'fusectl', 'cgroup')
- self.ignore_fstype = ('binfmt_misc', 'devpts', 'iso9660', 'none', 'proc', 'sysfs', 'usbfs', 'rootfs', 'autofs')
-
-
- def __update__(self):
- """
- Update the stats
- """
-
- # Reset the list
- self.fs_list = []
-
- # Open the current mounted FS
- fs_stat = psutil.disk_partitions(True)
- for fs in range(len(fs_stat)):
- fs_current = {}
- fs_current['device_name'] = fs_stat[fs].device
- if fs_current['device_name'] in self.ignore_fsname: continue
- fs_current['fs_type'] = fs_stat[fs].fstype
- if fs_current['fs_type'] in self.ignore_fstype: continue
- fs_current['mnt_point'] = fs_stat[fs].mountpoint
- try:
- fs_usage = psutil.disk_usage(fs_current['mnt_point'])
- except:
- continue
- fs_current['size'] = fs_usage.total
- fs_current['used'] = fs_usage.used
- fs_current['avail'] = fs_usage.free
- self.fs_list.append(fs_current)
-
-
- def get(self):
- self.__update__()
- return self.fs_list
+ """
+ Get FS stats
+ """
+
+ def __init__(self):
+ """
+ Init FS stats
+ """
+
+ # Ignore the following FS name
+ self.ignore_fsname = ('', 'none', 'gvfs-fuse-daemon', 'fusectl', \
+ 'cgroup')
+
+ # Ignore the following FS type
+ self.ignore_fstype = ('binfmt_misc', 'devpts', 'iso9660', 'none', \
+ 'proc', 'sysfs', 'usbfs', 'rootfs', 'autofs')
+
+ def __update__(self):
+ """
+ Update the stats
+ """
+
+ # Reset the list
+ self.fs_list = []
+
+ # Open the current mounted FS
+ fs_stat = psutil.disk_partitions(True)
+ for fs in range(len(fs_stat)):
+ fs_current = {}
+ fs_current['device_name'] = fs_stat[fs].device
+ if fs_current['device_name'] in self.ignore_fsname:
+ continue
+ fs_current['fs_type'] = fs_stat[fs].fstype
+ if fs_current['fs_type'] in self.ignore_fstype:
+ continue
+ fs_current['mnt_point'] = fs_stat[fs].mountpoint
+ try:
+ fs_usage = psutil.disk_usage(fs_current['mnt_point'])
+ except:
+ continue
+ fs_current['size'] = fs_usage.total
+ fs_current['used'] = fs_usage.used
+ fs_current['avail'] = fs_usage.free
+ self.fs_list.append(fs_current)
+
+ def get(self):
+ self.__update__()
+ return self.fs_list
class glancesStats():
- """
- This class store, update and give stats
- """
-
- def __init__(self):
- """
- Init the stats
- """
-
- # Init the fs stats
- try:
- self.glancesgrabfs = glancesGrabFs()
- except:
- self.glancesgrabfs = {}
-
- # Process list refresh
- self.process_list_refresh = True
-
-
- def __update__(self):
- """
- Update the stats
- """
-
- # Host and OS informations
- self.host = {}
- self.host['hostname'] = platform.node()
- self.host['platform'] = platform.architecture()[0]
- self.host['processor'] = platform.processor()
- self.host['os_name'] = platform.system()
- try:
- if (self.host['os_name'] == "Linux" or self.host['os_name'] == "FreeBSD"):
- os_version = platform.linux_distribution()
- self.host['os_version'] = os_version[0]+" "+os_version[2]+" "+os_version[1]
- elif (self.host['os_name'] == "Windows"):
- os_version = platform.win32_ver()
- self.host['os_version'] = os_version[0]+" "+os_version[2]
- elif (self.host['os_name'] == "Darwin"):
- os_version = platform.mac_ver()
- self.host['os_version'] = os_version[0]
- else:
- self.host['os_version'] = ""
- except:
- self.host['os_version'] = ""
-
- # CPU
- percent = 0
- try:
- self.cputime_old
- except:
- self.cputime_old = psutil.cpu_times()
- self.cputime_total_old = self.cputime_old.user+self.cputime_old.system+self.cputime_old.idle
- # Only available on some OS
- try:
- self.cputime_total_old += self.cputime_old.nice
- except:
- pass
- try:
- self.cputime_total_old += self.cputime_old.iowait
- except:
- pass
- try:
- self.cputime_total_old += self.cputime_old.irq
- except:
- pass
- try:
- self.cputime_total_old += self.cputime_old.softirq
- except:
- pass
- self.cpu = {}
- else:
- try:
- self.cputime_new = psutil.cpu_times()
- self.cputime_total_new = self.cputime_new.user+self.cputime_new.system+self.cputime_new.idle
- # Only available on some OS
- try:
- self.cputime_total_new += self.cputime_new.nice
- except:
- pass
- try:
- self.cputime_total_new += self.cputime_new.iowait
- except:
- pass
- try:
- self.cputime_total_new += self.cputime_new.irq
- except:
- pass
- try:
- self.cputime_total_new += self.cputime_new.softirq
- except:
- pass
- percent = 100/(self.cputime_total_new-self.cputime_total_old)
- self.cpu = { 'kernel': (self.cputime_new.system-self.cputime_old.system)*percent,
- 'user': (self.cputime_new.user-self.cputime_old.user)*percent,
- 'idle': (self.cputime_new.idle-self.cputime_old.idle)*percent,
- 'nice': (self.cputime_new.nice-self.cputime_old.nice)*percent }
- self.cputime_old = self.cputime_new
- self.cputime_total_old = self.cputime_total_new
- except:
- self.cpu = {}
-
- # LOAD
- try:
- getload = os.getloadavg()
- self.load = { 'min1': getload[0],
- 'min5': getload[1],
- 'min15': getload[2] }
- except:
- self.load = {}
-
- # MEM
- try:
- # Only for Linux
- cachemem = psutil.cached_phymem()+psutil.phymem_buffers()
- except:
- cachemem = 0
- try:
- phymem = psutil.phymem_usage()
- self.mem = { 'cache': cachemem,
- 'total': phymem.total,
- 'free': phymem.free,
- 'used': phymem.used }
- except:
- self.mem = {}
- try:
- virtmem = psutil.virtmem_usage()
- self.memswap = { 'total': virtmem.total,
- 'free': virtmem.free,
- 'used': virtmem.used }
- except:
- self.memswap = {}
-
- # NET
- self.network = []
- try:
- self.network_old
- except:
- if (psutil_network_io_tag):
- self.network_old = psutil.network_io_counters(True)
- else:
- try:
- self.network_new = psutil.network_io_counters(True)
- except:
- pass
- else:
- for net in self.network_new:
- try:
- netstat = {}
- netstat['interface_name'] = net
- netstat['rx'] = self.network_new[net].bytes_recv - self.network_old[net].bytes_recv
- netstat['tx'] = self.network_new[net].bytes_sent - self.network_old[net].bytes_sent
- except:
- continue
- else:
- self.network.append(netstat)
- self.network_old = self.network_new
-
- # DISK IO
- self.diskio = []
- try:
- self.diskio_old
- except:
- if (psutil_disk_io_tag):
- self.diskio_old = psutil.disk_io_counters(True)
- else:
- try:
- self.diskio_new = psutil.disk_io_counters(True)
- except:
- pass
- else:
- for disk in self.diskio_new:
- try:
- diskstat = {}
- diskstat['disk_name'] = disk
- diskstat['read_bytes'] = self.diskio_new[disk].read_bytes - self.diskio_old[disk].read_bytes
- diskstat['write_bytes'] = self.diskio_new[disk].write_bytes - self.diskio_old[disk].write_bytes
- except:
- continue
- else:
- self.diskio.append(diskstat)
- self.diskio_old = self.diskio_new
-
- # FILE SYSTEM
- try:
- self.fs = self.glancesgrabfs.get()
- except:
- self.fs = {}
-
- # PROCESS
- # Initialiation of the running processes list
- # Data are refreshed every two cycle (refresh_time * 2)
- if (self.process_list_refresh):
- self.process_first_grab = False
- try:
- self.process_all
- except:
- self.process_all = [proc for proc in psutil.process_iter()]
- self.process_first_grab = True
- self.process = []
- self.processcount = { 'total': 0 , 'running': 0, 'sleeping': 0 }
- # Manage new processes
- process_new = [proc.pid for proc in self.process_all]
- for proc in psutil.process_iter():
- if proc.pid not in process_new:
- self.proces