提交 311ba7ce 编写于 作者: N Nicolas Hennion

Add FS and DiskIO plugins

上级 30826905
......@@ -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
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Glances - An eye on your system
#
# Copyright (C) 2014 Nicolargo <nicolas@nicolargo.com>
#
# 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 <http://www.gnu.org/licenses/>.
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']))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Glances - An eye on your system
#
# Copyright (C) 2014 Nicolargo <nicolas@nicolargo.com>
#
# 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 <http://www.gnu.org/licenses/>.
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
......@@ -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'):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册