Browse files

Updates

  • Loading branch information...
1 parent b959e95 commit 17d5d06c3b74f895821e8f5b1858fe7dbc1fea9e @dagwieers committed May 6, 2005
Showing with 47 additions and 42 deletions.
  1. +1 −0 TODO
  2. +24 −21 dstat
  3. +1 −1 dstat.conf
  4. +13 −15 dstat15
  5. +3 −2 stats/dstat_cpufreq.py
  6. +3 −2 stats/dstat_dbus.py
  7. +2 −1 stats/dstat_utmp.py
View
1 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!)
View
45 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,22 +594,22 @@ 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()
if len(l) < 15 or l[0] == 'major' or int(l[1]) % 16 != 0: continue
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), '<string>', '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
View
2 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
View
28 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']:
View
5 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
View
5 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):
View
3 stats/dstat_utmp.py
@@ -7,14 +7,15 @@ def __init__(self):
self.nick = ('ses', 'usr', 'adm' )
self.vars = ('sessions', 'users', 'root')
self.init(self.vars, 1)
+ self.check()
def check(self):
try:
global utmp
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):

0 comments on commit 17d5d06

Please sign in to comment.