diff --git a/glances/core/glances_core.py b/glances/core/glances_core.py index c0334bb656d0c16aefab6d492490a8201ed2bcc5..455e68b5f5e45c68a6cf553e7e2ab7f33635e68b 100644 --- a/glances/core/glances_core.py +++ b/glances/core/glances_core.py @@ -56,13 +56,6 @@ if psutil_version < (0, 5, 0): print('PsUtil 0.5.1 or higher is needed. Glances cannot start.') sys.exit(1) -if not is_Mac: - psutil_get_io_counter_tag = True -else: - # get_io_counters() not available on OS X - psutil_get_io_counter_tag = False - - class GlancesCore(object): """ Main class to manage Glances instance diff --git a/glances/plugins/glances_diskio.py b/glances/plugins/glances_diskio.py new file mode 100644 index 0000000000000000000000000000000000000000..f22e70b2e20cebae22705b2bb5f2872b4504f018 --- /dev/null +++ b/glances/plugins/glances_diskio.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Glances - An eye on your system +# +# Copyright (C) 2014 Nicolargo +# +# Glances is free software; you can redistribute it and/or modify +# it 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 . + +from psutil import disk_io_counters + +from glances.core.glances_globals import is_Mac +from glances_plugin import GlancesPlugin, getTimeSinceLastUpdate + +class Plugin(GlancesPlugin): + """ + Glances's disks IO Plugin + + stats is a list + """ + + def __init__(self): + GlancesPlugin.__init__(self) + + + def update(self): + """ + Update disk IO stats + """ + + self.diskio = [] + + # Disk IO stat not available on Mac OS + if is_Mac: + self.stats = self.diskio + return self.stats + + # By storing time data we enable Rx/s and Tx/s calculations in the + # XML/RPC API, which would otherwise be overly difficult work + # for users of the API + time_since_update = getTimeSinceLastUpdate('disk') + + if not hasattr(self, 'diskio_old'): + try: + self.diskio_old = disk_io_counters(perdisk=True) + except IOError: + self.diskio_error_tag = True + else: + self.diskio_new = disk_io_counters(perdisk=True) + for disk in self.diskio_new: + try: + # Try necessary to manage dynamic disk creation/del + diskstat = {} + diskstat['time_since_update'] = time_since_update + 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 Exception: + continue + else: + self.diskio.append(diskstat) + self.diskio_old = self.diskio_new + + self.stats = self.diskio + + + def get_stats(self): + # Return the stats object for the RPC API + # Sort it by disk name + # Convert it to string + return str(sorted(self.stats, key=lambda network: network['disk_name'])) diff --git a/glances/plugins/glances_fs.py b/glances/plugins/glances_fs.py new file mode 100644 index 0000000000000000000000000000000000000000..15349eac912718744a863b47459ba5cb1d95d8b4 --- /dev/null +++ b/glances/plugins/glances_fs.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Glances - An eye on your system +# +# Copyright (C) 2014 Nicolargo +# +# Glances is free software; you can redistribute it and/or modify +# it 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 . + +from psutil import disk_partitions, disk_usage +from glances_plugin import GlancesPlugin, getTimeSinceLastUpdate + + +class Plugin(GlancesPlugin): + """ + Glances's File System (fs) Plugin + + stats is a list + """ + + def __init__(self): + GlancesPlugin.__init__(self) + + # Init the FS class + self.glancesgrabfs = glancesGrabFs() + + + def update(self): + """ + Update stats + """ + + self.stats = self.glancesgrabfs.get() + + + def get_stats(self): + # Return the stats object for the RPC API + # Sort it by mount name + # Convert it to string + return str(sorted(self.stats, key=lambda network: network['mnt_point'])) + + +class glancesGrabFs: + """ + Get FS stats + """ + + def __init__(self): + """ + Init FS stats + """ + # Ignore the following FS name + self.ignore_fsname = ('', 'cgroup', 'fusectl', 'gvfs-fuse-daemon', + 'gvfsd-fuse', 'none') + + # Ignore the following FS type + self.ignore_fstype = ('autofs', 'binfmt_misc', 'configfs', 'debugfs', + 'devfs', 'devpts', 'devtmpfs', 'hugetlbfs', + 'iso9660', 'linprocfs', 'mqueue', 'none', + 'proc', 'procfs', 'pstore', 'rootfs', + 'securityfs', 'sysfs', 'usbfs') + + # ignore FS by mount point + self.ignore_mntpoint = ('', '/dev/shm', '/lib/init/rw', '/sys/fs/cgroup') + + def __update__(self): + """ + Update the stats + """ + # Reset the list + self.fs_list = [] + + # Open the current mounted FS + fs_stat = disk_partitions(all=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 + if fs_current['mnt_point'] in self.ignore_mntpoint: + continue + try: + fs_usage = disk_usage(fs_current['mnt_point']) + except Exception: + 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 diff --git a/glances/plugins/glances_network.py b/glances/plugins/glances_network.py index 5d3dbe3505c9e91da6437578bc854ca7a61316f3..0e9d7af7dca64a3a645c216efb13d1081c87c079 100644 --- a/glances/plugins/glances_network.py +++ b/glances/plugins/glances_network.py @@ -48,10 +48,7 @@ class Plugin(GlancesPlugin): Update network stats """ - # By storing time data we enable Rx/s and Tx/s calculations in the - # XML/RPC API, which would otherwise be overly difficult work - # for users of the API - time_since_update = getTimeSinceLastUpdate('net') + network = [] # psutil >= 1.0.0 try: @@ -63,7 +60,10 @@ class Plugin(GlancesPlugin): except IOError: pass - network = [] + # By storing time data we enable Rx/s and Tx/s calculations in the + # XML/RPC API, which would otherwise be overly difficult work + # for users of the API + time_since_update = getTimeSinceLastUpdate('net') # Previous network interface stats are stored in the network_old variable if not hasattr(self, 'network_old'):