Skip to content

Commit

Permalink
Retab
Browse files Browse the repository at this point in the history
  • Loading branch information
dagwieers committed May 12, 2007
1 parent c0c7cba commit 57b2b90
Show file tree
Hide file tree
Showing 29 changed files with 4,345 additions and 4,345 deletions.
3,568 changes: 1,784 additions & 1,784 deletions dstat

Large diffs are not rendered by default.

3,532 changes: 1,766 additions & 1,766 deletions dstat15

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/curstest
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import curses, sys
#curses.start_color()
#print "TERM is", curses.termname()
#if curses.has_colors():
# print "Has colors"#
# print "Has colors"#
#print curses.color_pair(curses.COLOR_RED), "Red"
#curses.endwin()

#curses.setupterm('xterm')
curses.setupterm()

if sys.stdout.isatty():
print "Is a TTY"
print "Is a TTY"

print "Size is %sx%s" % (curses.tigetnum('lines'), curses.tigetnum('cols'))

if curses.tigetnum('colors') > 0:
print "Has colors"
print curses.tigetnum('colors')
print "Has colors"
print curses.tigetnum('colors')
44 changes: 22 additions & 22 deletions examples/devtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
import dstat, time

devices = (
( 1, 0, 'ram0'),
( 1, 1, 'ram1'),
( 3, 1, 'hda1'),
( 33, 0, 'hde'),
( 7, 0, 'loop0'),
( 7, 1, 'loop1'),
( 8, 0, '/dev/sda'),
( 8, 1, '/dev/sda1'),
( 8, 18, '/dev/sdb2'),
( 8, 37, '/dev/sdc5'),
( 9, 0, 'md0'),
( 9, 1, 'md1'),
( 9, 2, 'md2'),
( 74, 16, '/dev/ida/c2d1'),
( 77, 241, '/dev/ida/c5d15p1'),
( 98, 0, 'ubd/disc0/disc'),
( 98, 16, 'ubd/disc1/disc'),
(104, 0, 'cciss/c0d0'),
(104, 2, 'cciss/c0d0p2'),
(253, 0, 'dm-0'),
(253, 1, 'dm-1'),
( 1, 0, 'ram0'),
( 1, 1, 'ram1'),
( 3, 1, 'hda1'),
( 33, 0, 'hde'),
( 7, 0, 'loop0'),
( 7, 1, 'loop1'),
( 8, 0, '/dev/sda'),
( 8, 1, '/dev/sda1'),
( 8, 18, '/dev/sdb2'),
( 8, 37, '/dev/sdc5'),
( 9, 0, 'md0'),
( 9, 1, 'md1'),
( 9, 2, 'md2'),
( 74, 16, '/dev/ida/c2d1'),
( 77, 241, '/dev/ida/c5d15p1'),
( 98, 0, 'ubd/disc0/disc'),
( 98, 16, 'ubd/disc1/disc'),
(104, 0, 'cciss/c0d0'),
(104, 2, 'cciss/c0d0p2'),
(253, 0, 'dm-0'),
(253, 1, 'dm-1'),
)

for maj, min, device in devices:
print device, '->', dstat.dev(maj, min)
print device, '->', dstat.dev(maj, min)
46 changes: 23 additions & 23 deletions examples/mmpipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@
import select, sys, os

def readpipe(file, tmout = 0.001):
"Read available data from pipe"
ret = ''
while not select.select([file.fileno()], [], [], tmout)[0]:
pass
while select.select([file.fileno()], [], [], tmout)[0]:
ret = ret + file.read(1)
return ret.split('\n')
"Read available data from pipe"
ret = ''
while not select.select([file.fileno()], [], [], tmout)[0]:
pass
while select.select([file.fileno()], [], [], tmout)[0]:
ret = ret + file.read(1)
return ret.split('\n')

def dpopen(cmd):
"Open a pipe for reuse, if already opened, return pipes"
global pipes
if 'pipes' not in globals().keys(): pipes = {}
if cmd not in pipes.keys():
pipes[cmd] = os.popen3(cmd, 't', 0)
return pipes[cmd]
"Open a pipe for reuse, if already opened, return pipes"
global pipes
if 'pipes' not in globals().keys(): pipes = {}
if cmd not in pipes.keys():
pipes[cmd] = os.popen3(cmd, 't', 0)
return pipes[cmd]

### Unbuffered sys.stdout
sys.stdout = os.fdopen(1, 'w', 0)

### Main entrance
if __name__ == '__main__':
try:
stdin, stdout, stderr = dpopen('/usr/lpp/mmfs/bin/mmpmon -p -s')
stdin.write('reset\n')
readpipe(stdout)
try:
stdin, stdout, stderr = dpopen('/usr/lpp/mmfs/bin/mmpmon -p -s')
stdin.write('reset\n')
readpipe(stdout)

while True:
stdin.write('io_s\n')
for line in readpipe(stdout):
print line
while True:
stdin.write('io_s\n')
for line in readpipe(stdout):
print line

except KeyboardInterrupt, e:
print
except KeyboardInterrupt, e:
print

# vim:ts=4:sw=4
24 changes: 12 additions & 12 deletions examples/mstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
### Load stats
stats = []
for o in (dstat.dstat_epoch(), dstat.dstat_cpu(), dstat.dstat_mem(), dstat.dstat_load(), dstat.dstat_disk(), dstat.dstat_sys()):
try: o.check()
except Exception, e: print e
else: stats.append(o)
try: o.check()
except Exception, e: print e
else: stats.append(o)

### Make time stats sub-second
stats[0].format = ('t', 14, 0)

### Print headers
title1 = title2 = ''
for o in stats:
title1 = title1 + ' ' + o.title1()
title2 = title2 + ' ' + o.title2()
title1 = title1 + ' ' + o.title1()
title2 = title2 + ' ' + o.title2()
print '\n' + title1 + '\n' + title2

### Print stats
for dstat.update in range(count):
line = ''
for o in stats:
o.extract()
line = line + ' ' + o.show()
print line + dstat.ansi['reset']
if dstat.update != count-1: time.sleep(delay)
dstat.tick = 1
line = ''
for o in stats:
o.extract()
line = line + ' ' + o.show()
print line + dstat.ansi['reset']
if dstat.update != count-1: time.sleep(delay)
dstat.tick = 1
print dstat.ansi['reset']
4 changes: 2 additions & 2 deletions examples/tdbtest
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ print db.keys()

key=db.firstkey()
while key:
print db.fetch(key)
key=db.nextkey(key)
print db.fetch(key)
key=db.nextkey(key)

db = tdb.tdb('/var/cache/samba/locking.tdb')
print db.keys
Expand Down
100 changes: 50 additions & 50 deletions plugins/dstat_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,62 @@
import string

class dstat_app(dstat):
def __init__(self):
self.name = 'most expensive'
self.format = ('s', 18, 0)
self.nick = ('process',)
self.vars = self.nick
self.pid = str(os.getpid())
self.cn1 = {}; self.cn2 = {}; self.val = {}
def __init__(self):
self.name = 'most expensive'
self.format = ('s', 18, 0)
self.nick = ('process',)
self.vars = self.nick
self.pid = str(os.getpid())
self.cn1 = {}; self.cn2 = {}; self.val = {}

def extract(self):
max = 0.0
for pid in os.listdir('/proc/'):
try: int(pid)
except: continue
if os.path.exists('/proc/%s/stat' % pid):
if pid == self.pid: continue
if not self.cn1.has_key(pid):
self.cn1[pid] = 0
def extract(self):
max = 0.0
for pid in os.listdir('/proc/'):
try: int(pid)
except: continue
if os.path.exists('/proc/%s/stat' % pid):
if pid == self.pid: continue
if not self.cn1.has_key(pid):
self.cn1[pid] = 0

### Using dopen() will cause too many open files
# l = string.split(dopen('/proc/%s/stat' % pid).read())
l = string.split(open('/proc/%s/stat' % pid).read())
if len(l) < 15: continue
self.cn2[pid] = int(l[13]) + int(l[14])
usage = (self.cn2[pid] - self.cn1[pid]) * 1.0 / tick
### Using dopen() will cause too many open files
# l = string.split(dopen('/proc/%s/stat' % pid).read())
l = string.split(open('/proc/%s/stat' % pid).read())
if len(l) < 15: continue
self.cn2[pid] = int(l[13]) + int(l[14])
usage = (self.cn2[pid] - self.cn1[pid]) * 1.0 / tick

### Get the process that spends the most jiffies
if usage > max:
max = usage
self.val['name'] = l[1][1:-1]
self.val['pid'] = pid
### Get the process that spends the most jiffies
if usage > max:
max = usage
self.val['name'] = l[1][1:-1]
self.val['pid'] = pid

if max == 0.0:
self.val['process'] = ''
else:
### If the name is a known interpreter, take the second argument from the cmdline
if self.val['name'] in ('bash', 'csh', 'ksh', 'perl', 'python', 'sh'):
### Using dopen() will cause too many open files
# l = string.split(dopen('/proc/%s/cmdline' % self.val['pid']).read(), '\0')
l = string.split(open('/proc/%s/cmdline' % self.val['pid']).read(), '\0')
if len(l) > 2:
self.val['name'] = os.path.basename(l[1])
if max == 0.0:
self.val['process'] = ''
else:
### If the name is a known interpreter, take the second argument from the cmdline
if self.val['name'] in ('bash', 'csh', 'ksh', 'perl', 'python', 'sh'):
### Using dopen() will cause too many open files
# l = string.split(dopen('/proc/%s/cmdline' % self.val['pid']).read(), '\0')
l = string.split(open('/proc/%s/cmdline' % self.val['pid']).read(), '\0')
if len(l) > 2:
self.val['name'] = os.path.basename(l[1])

# l = l.reverse()
# for x in l:
# print x
# if x[0] != '-':
# self.val['name'] = os.path.basename(x)
# break
# l = l.reverse()
# for x in l:
# print x
# if x[0] != '-':
# self.val['name'] = os.path.basename(x)
# break

### Show yellow usage
self.val['process'] = '%-*s%s%3d' % (self.format[1]-3, self.val['name'], ansi['yellow'], round(max))
### Show yellow usage
self.val['process'] = '%-*s%s%3d' % (self.format[1]-3, self.val['name'], ansi['yellow'], round(max))

### Debug (show PID)
# self.val['process'] = '%*s %-*s' % (5, self.val['pid'], self.format[1]-6, self.val['name'])
### Debug (show PID)
# self.val['process'] = '%*s %-*s' % (5, self.val['pid'], self.format[1]-6, self.val['name'])

if step == op.delay:
self.cn1.update(self.cn2)
if step == op.delay:
self.cn1.update(self.cn2)

# vim:ts=4:sw=4
# vim:ts=4:sw=4:et
68 changes: 34 additions & 34 deletions plugins/dstat_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@
import string

class dstat_battery(dstat):
def __init__(self):
self.name = 'battery'
self.format = ('f', 4, 34)
self.vars = []
for battery in os.listdir('/proc/acpi/battery/'):
for line in dopen('/proc/acpi/battery/'+battery+'/state').readlines():
l = string.split(line)
if len(l) < 2: continue
if l[0] == 'present:' and l[1] == 'yes':
self.vars.append(battery)
# self.nick = [string.lower(name) for name in self.vars]
self.nick = []
for name in self.vars:
self.nick.append(string.lower(name))
self.init(self.vars, 1)
def __init__(self):
self.name = 'battery'
self.format = ('f', 4, 34)
self.vars = []
for battery in os.listdir('/proc/acpi/battery/'):
for line in dopen('/proc/acpi/battery/'+battery+'/state').readlines():
l = string.split(line)
if len(l) < 2: continue
if l[0] == 'present:' and l[1] == 'yes':
self.vars.append(battery)
# self.nick = [string.lower(name) for name in self.vars]
self.nick = []
for name in self.vars:
self.nick.append(string.lower(name))
self.init(self.vars, 1)

def extract(self):
for battery in self.vars:
for line in dopen('/proc/acpi/battery/'+battery+'/info').readlines():
l = string.split(line)
if len(l) < 4: continue
if l[0] == 'last':
full = int(l[3])
break
for line in dopen('/proc/acpi/battery/'+battery+'/state').readlines():
l = string.split(line)
if len(l) < 3: continue
if l[0] == 'remaining':
current = int(l[2])
break
if current:
self.val[battery] = current * 100.0 / full
else:
self.val[battery] = -1
def extract(self):
for battery in self.vars:
for line in dopen('/proc/acpi/battery/'+battery+'/info').readlines():
l = string.split(line)
if len(l) < 4: continue
if l[0] == 'last':
full = int(l[3])
break
for line in dopen('/proc/acpi/battery/'+battery+'/state').readlines():
l = string.split(line)
if len(l) < 3: continue
if l[0] == 'remaining':
current = int(l[2])
break
if current:
self.val[battery] = current * 100.0 / full
else:
self.val[battery] = -1

# vim:ts=4:sw=4
# vim:ts=4:sw=4:et
Loading

0 comments on commit 57b2b90

Please sign in to comment.