Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dagwieers committed May 6, 2005
1 parent b959e95 commit 17d5d06
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 42 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand Down
45 changes: 24 additions & 21 deletions dstat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dstat.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 13 additions & 15 deletions dstat15
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'):
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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']:
Expand Down
5 changes: 3 additions & 2 deletions stats/dstat_cpufreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions stats/dstat_dbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion stats/dstat_utmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 17d5d06

Please sign in to comment.