From 17d5d06c3b74f895821e8f5b1858fe7dbc1fea9e Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Fri, 6 May 2005 22:48:44 +0000 Subject: [PATCH] Updates --- TODO | 1 + dstat | 45 ++++++++++++++++++++++-------------------- dstat.conf | 2 +- dstat15 | 28 ++++++++++++-------------- stats/dstat_cpufreq.py | 5 +++-- stats/dstat_dbus.py | 5 +++-- stats/dstat_utmp.py | 3 ++- 7 files changed, 47 insertions(+), 42 deletions(-) diff --git a/TODO b/TODO index 298a297..7cad953 100644 --- a/TODO +++ b/TODO @@ -17,6 +17,7 @@ + Look into interfacing with apps (bind, sendmail, postfix, squid, amavisd, laus, samba) + Look into interfacing with specific HW counters in /proc + Look at /proc/meminfo, /proc/mdstat, /proc/netstat, /proc/snmp, /proc/vmstat ++ Look at /proc/fs/cifs/stats + Allow for SNMP counters to be added ### Documentation (help welcome!) diff --git a/dstat b/dstat index 9955ca0..6cf5487 100755 --- a/dstat +++ b/dstat @@ -19,8 +19,9 @@ from __future__ import generators try: import sys, signal, os, re, time import types, curses, signal, resource - sys.path.insert(0, '.') - sys.path.insert(0, './stats/') + pwd = os.path.dirname(sys.argv[0]) + sys.path.insert(0, pwd) + sys.path.insert(0, pwd + '/stats/') sys.path.insert(0, '/usr/share/dstat/') except KeyboardInterrupt, e: pass @@ -362,10 +363,10 @@ class dstat: def check(self): "Check if stat is applicable" - if not self.vars: - return False if hasattr(self, 'fd') and not self.fd: return False + if not self.vars: + return False if self.discover() and self.width(): return True return False @@ -422,12 +423,13 @@ class dstat_cpu(dstat): def discover(self, *list): ret = [] - self.fd.seek(0) - for line in self.fd.readlines(): - l = line.split() - if len(l) < 8 or l[0][0:3] != 'cpu': continue - ret.append(l[0][3:]) - ret.sort() + if self.fd: + self.fd.seek(0) + for line in self.fd.readlines(): + l = line.split() + if len(l) < 8 or l[0][0:3] != 'cpu': continue + ret.append(l[0][3:]) + ret.sort() for item in list: ret.append(item) return ret @@ -535,13 +537,14 @@ class dstat_disk(dstat): def discover(self, *list): ret = [] - self.fd.seek(0) - for line in self.fd.readlines(): - l = line.split() - if len(l) < 13 or l[3] == '0': continue - name = l[2] - if not self.regexp.match(name): - ret.append(name) + if self.fd: + self.fd.seek(0) + for line in self.fd.readlines(): + l = line.split() + if len(l) < 13 or l[3] == '0': continue + name = l[2] + if not self.regexp.match(name): + ret.append(name) for item in list: ret.append(item) return ret @@ -591,14 +594,14 @@ class dstat_disk24(dstat): self.len = 5 self.open('/proc/partitions') self.nick = ('read', 'write') + self.regexp = re.compile('^(ram\d+|loop\d+|name)$') self.vars = self.vars() self.name = ['disk/'+name for name in self.vars] self.init(self.vars + ['total',], 2) - self.regexp = re.compile('^(ram\d+|loop\d+|name)$') def discover(self, *list): ret = [] - if not os.path.exists('/proc/diskstats'): + if self.fd and not os.path.exists('/proc/diskstats'): self.fd.seek(0) for line in self.fd.readlines(): l = line.split() @@ -606,7 +609,7 @@ class dstat_disk24(dstat): name = l[3] if not self.regexp.match(name): ret.append(name) - for item in list: ret.append(item) + for item in list: ret.append(item) return ret def vars(self): @@ -1533,7 +1536,7 @@ def main(): try: exec(compile('import dstat_%s\nobjs = ( dstat_%s.dstat_%s(), )' % (mod, mod, mod), '', 'exec')) except Exception, e: - info(1, 'Module \'dstat_%s\' does not exist or failed to load. (%s)' % (mod, e)) + info(1, 'Module \'dstat_%s\' failed to load. (%s)' % (mod, e)) continue ### Remove defect stat objects and calculate line length diff --git a/dstat.conf b/dstat.conf index e6c2cd6..5cdbd31 100644 --- a/dstat.conf +++ b/dstat.conf @@ -13,7 +13,7 @@ noupdate = true default-options = -cdns unit = k background = light -update-method = interval-average # snapshot total-average +update-method = interval-average # snapshot total-average last-n-average [colors] default = red yellow green blue magenta cyan white darkred darkgreen diff --git a/dstat15 b/dstat15 index 93ef845..29ef6c5 100755 --- a/dstat15 +++ b/dstat15 @@ -19,6 +19,8 @@ try: import sys, signal, os, re, time, string import types, curses, signal, resource + sys.path.insert(0, '.') + sys.path.insert(0, './stats/') sys.path.insert(0, '/usr/share/dstat/') except KeyboardInterrupt, e: pass @@ -28,20 +30,13 @@ except KeyboardInterrupt, e: ### Workaround for python < 2.3 (FIXME: check for sys.version_info existence) if not callable('enumerate'): - if sys.version_info < (2, 3) and sys.version_info >= (2, 2): - def enumerate(sequence): - index = 0 - for item in sequence: - yield index, item - index = index + 1 - elif sys.version_info < (2, 2): - def enumerate(sequence): - index = 0 - list = [] - for item in sequence: - list.append((index, item)) - index = index + 1 - return list + def enumerate(sequence): + index = 0 + list = [] + for item in sequence: + list.append((index, item)) + index = index + 1 + return list ### Workaround for python < 2.3 if not callable('sum'): @@ -65,6 +60,7 @@ class Options: self.args = args self.count = -1 self.cpulist = None + self.debug = False self.delay = 1 self.disklist = None self.full = False @@ -89,7 +85,7 @@ class Options: opts, args = getopt.getopt (args, 'acdfghilmno:pstvyC:D:I:M:N:V', ['all', 'cpu', 'disk', 'help', 'int', 'ipc', 'load', 'lock', 'mem', 'net', 'page', 'proc', 'raw', 'swap', 'sys', 'tcp', 'time', 'udp', 'unix', 'version', 'vmstat', - 'full', 'integer', 'mods', 'modules', 'nocolor', 'noheaders', 'noupdate', 'output=']) + 'debug', 'full', 'integer', 'mods', 'modules', 'nocolor', 'noheaders', 'noupdate', 'output=']) except getopt.error, exc: print 'dstat: %s, try dstat -h for a list of all the options' % str(exc) exit(1) @@ -105,6 +101,8 @@ class Options: self.modlist.append('disk') elif opt in ['-D']: self.disklist = string.split(arg, ',') + elif opt in ['--debug']: + self.debug = True elif opt in ['-g', '--page']: self.modlist.append('page') elif opt in ['-i', '--int']: diff --git a/stats/dstat_cpufreq.py b/stats/dstat_cpufreq.py index f7c396e..8f29dd0 100644 --- a/stats/dstat_cpufreq.py +++ b/stats/dstat_cpufreq.py @@ -7,12 +7,13 @@ def __init__(self): self.vars = os.listdir('/sys/devices/system/cpu/') self.nick = [string.lower(name) for name in self.vars] self.init(self.vars, 1) + self.check() def check(self): if self.vars: for cpu in self.vars: if not os.access('/sys/devices/system/cpu/'+cpu+'/cpufreq/cpuinfo_cur_freq', os.R_OK): - dstat.info(1, 'cpufreq: Cannot access acpi cpu frequency information.') + raise Exception, 'Module cannot access acpi cpu frequency information.' return False return True return false @@ -25,7 +26,7 @@ def extract(self): for line in dstat.dopen('/sys/devices/system/cpu/'+cpu+'/cpufreq/cpuinfo_cur_freq').readlines(): l = string.split(line) cur = int(l[0]) - ### Need to close becausee of bug in sysfs (?) + ### Need to close because of bug in sysfs (?) dstat.dclose('/sys/devices/system/cpu/'+cpu+'/cpufreq/cpuinfo_cur_freq') self.val[cpu] = cur * 100.0 / max diff --git a/stats/dstat_dbus.py b/stats/dstat_dbus.py index 142e8da..705e101 100644 --- a/stats/dstat_dbus.py +++ b/stats/dstat_dbus.py @@ -7,6 +7,7 @@ def __init__(self): self.nick = ('sys', 'ses') self.vars = ('system', 'session') self.init(self.vars, 1) + self.check() def check(self): # dstat.info(1, 'The dbus module is an EXPERIMENTAL module.') @@ -20,11 +21,11 @@ def check(self): except: self.sesbus = None except: - info(1, 'dbus: Unable to connect to dbus message bus.') + raise Exception, 'Module is unable to connect to dbus message bus.' return False return True except: - info(1, 'dbus: The dbus stat needs the python-dbus module.') + raise Exception, 'Module needs the python-dbus module.' return False def extract(self): diff --git a/stats/dstat_utmp.py b/stats/dstat_utmp.py index 0ff27fd..3326540 100644 --- a/stats/dstat_utmp.py +++ b/stats/dstat_utmp.py @@ -7,6 +7,7 @@ def __init__(self): self.nick = ('ses', 'usr', 'adm' ) self.vars = ('sessions', 'users', 'root') self.init(self.vars, 1) + self.check() def check(self): try: @@ -14,7 +15,7 @@ def check(self): import utmp return True except: - info(1, 'utmp: The utmp stat needs the python-utmp module.') + raise Exception, 'Module needs the python-utmp module.' return False def extract(self):