Permalink
Browse files

- Added external dstat_qmail plugin to show the length of qmail queu…

…es (Tom Van Looy)

+- Added external dstat_dstat plugin to show Dstat's own cputime and latency values
+- Added --profile option to get profiling statistics when you exit dstat
  • Loading branch information...
1 parent 8206f60 commit e882b3a2b7ac8257b44d45d78b1c3755f4ab730f @dagwieers committed Dec 2, 2009
Showing with 106 additions and 7 deletions.
  1. +2 −0 ChangeLog
  2. +6 −0 docs/dstat.1.txt
  3. +25 −6 dstat
  4. +0 −1 plugins/dstat_dbus.py
  5. +30 −0 plugins/dstat_dstat.py
  6. +24 −0 plugins/dstat_qmail.py
  7. +19 −0 plugins/dstat_test.py
View
@@ -3,6 +3,8 @@
- Documentation improvements
- Implement linecache for top-plugins (caching for statistics)
- Added external dstat_qmail plugin to show the length of qmail queues (Tom Van Looy)
+- Added external dstat_dstat plugin to show Dstat's own cputime and latency values
+- Added --profile option to get profiling statistics when you exit dstat
* 0.7.0 - Tokyo - release 25/11/2009
- Fixed dstat_disk plugin for total calculation on 2.6.25+ kernels (Noel J. Bergman)
View
@@ -165,6 +165,9 @@ Possible internal stats are::
--output file::
write CSV output to file
+--profile::
+ show profiling statistics when exiting dstat
+
== PLUGINS
While anyone can create their own dstat plugins (and contribute them) dstat
@@ -261,6 +264,9 @@ Here is an overview of the plugins dstat ships with:
--proc-count::
show total number of processes
+--qmail::
+ show qmail queue sizes (needs qmail)
+
--rpc::
show RPC client calls stats
View
31 dstat
@@ -89,6 +89,7 @@ class Options:
self.header = True
self.output = False
self.pidfile = False
+ self.profile = False
### List of available plugins
allplugins = listplugins()
@@ -115,7 +116,7 @@ class Options:
['all', 'all-plugins', 'bw', 'blackonwhite', 'debug',
'filesystem', 'float', 'full', 'gonuts', 'help', 'integer',
'list', 'mods', 'modules', 'nocolor', 'noheaders', 'noupdate',
- 'output=', 'pidfile=', 'version', 'vmstat'] + allplugins)
+ 'output=', 'pidfile=', 'profile', 'version', 'vmstat'] + allplugins)
except getopt.error, exc:
print 'dstat: %s, try dstat -h for a list of all the options' % str(exc)
sys.exit(1)
@@ -170,15 +171,15 @@ class Options:
elif opt in ['-f', '--full']:
self.full = True
- elif opt in ['--bw', '--black-on-white']:
- self.blackonwhite = True
- elif opt in ['--debug']:
- self.debug = self.debug + 1
elif opt in ['--all-plugins']:
### Make list unique in a fancy fast way
plugins = {}.fromkeys(allplugins).keys()
plugins.sort()
self.plugins += plugins
+ elif opt in ['--bw', '--black-on-white']:
+ self.blackonwhite = True
+ elif opt in ['--debug']:
+ self.debug = self.debug + 1
elif opt in ['--float']:
self.float = True
elif opt in ['--integer']:
@@ -197,6 +198,8 @@ class Options:
self.output = arg
elif opt in ['--pidfile']:
self.pidfile = arg
+ elif opt in ['--profile']:
+ self.profile = True
elif opt in ['-h', '--help']:
self.usage()
self.help()
@@ -215,6 +218,7 @@ class Options:
sys.exit(1)
if not self.plugins:
+ print 'You did not select any stats, using -cdngy by default.'
self.plugins = [ 'cpu', 'disk', 'net', 'page', 'sys' ]
try:
@@ -2431,7 +2435,11 @@ if __name__ == '__main__':
initterm()
op = Options(sys.argv[1:])
theme = set_theme()
- main()
+ if op.profile:
+ import profile
+ profile.run('main()', 'dstat_profile.log')
+ else:
+ main()
except KeyboardInterrupt, e:
if op.update:
sys.stdout.write('\n')
@@ -2440,6 +2448,17 @@ if __name__ == '__main__':
if op.pidfile and os.path.exists(op.pidfile):
os.remove(op.pidfile)
+ if op.profile:
+ rows, cols = gettermsize()
+ import pstats
+ p = pstats.Stats('dstat_profile.log')
+# p.sort_stats('name')
+# p.print_stats()
+ p.sort_stats('cumulative').print_stats(rows - 12)
+# p.sort_stats('time').print_stats(rows - 12)
+# p.sort_stats('file').print_stats('__init__')
+# p.sort_stats('time', 'cum').print_stats(.5, 'init')
+# p.print_callees()
exit(0)
else:
op = Options('')
View
@@ -4,7 +4,6 @@ class dstat_plugin(dstat):
"""
Number of active dbus sessions.
"""
-
def __init__(self):
self.name = 'dbus'
self.nick = ('sys', 'ses')
View
@@ -0,0 +1,30 @@
+### Author: Dag Wieers <dag$wieers,com>
+
+class dstat_plugin(dstat):
+ """
+ Provide more information related to the dstat process
+ """
+ def __init__(self):
+ self.name = 'dstat'
+ self.nick = ('time', 'latency')
+ self.vars = ('cputime', 'latency')
+ self.type = 'd'
+ self.width = 4
+ self.scale = 100
+ self.pid = str(os.getpid())
+
+ def extract(self):
+ ### Extract counters
+ l = dopen('/proc/%s/schedstat' % self.pid).read().split()
+# l = linecache.getline('/proc/%s/schedstat' % self.pid, 1).split()
+
+ self.set2['cputime'] = long(l[0])
+ self.set2['latency'] = long(l[1])
+
+ for name in self.vars:
+ self.val[name] = (self.set2[name] - self.set1[name]) * 1.0 / elapsed
+
+ if step == op.delay:
+ self.set1.update(self.set2)
+
+# vim:ts=4:sw=4:et
View
@@ -0,0 +1,24 @@
+### Author: Tom Van Looy <tom$ctors,net>
+
+class dstat_plugin(dstat):
+ """
+ port of qmail_qstat to dstat
+ """
+ def __init__(self):
+ self.name = 'qmail'
+ self.nick = ('in_queue', 'not_prep')
+ self.vars = ('mess', 'todo')
+ self.type = 'd'
+ self.width = 4
+ self.scale = 100
+
+ def check(self):
+ for item in self.vars:
+ if not os.access('/var/qmail/queue/'+item, os.R_OK):
+ raise Exception, 'Cannot access qmail queues'
+
+ def extract(self):
+ for item in self.vars:
+ self.val[item] = len(glob.glob('/var/qmail/queue/'+item+'/*/*'))
+
+# vim:ts=4:sw=4:et
View
@@ -0,0 +1,19 @@
+### Author: Dag Wieers <dag@wieers.com>
+
+class dstat_plugin(dstat):
+ def __init__(self):
+ self.name = 'test'
+ self.nick = ( 'f1', 'f2' )
+ self.vars = ( 'f1', 'f2' )
+# self.type = 'd'
+# self.width = 4
+# self.scale = 20
+ self.type = 's'
+ self.width = 4
+ self.scale = 0
+
+ def extract(self):
+# Self.val = { 'f1': -1, 'f2': -1 }
+ self.val = { 'f1': 'test', 'f2': 'test' }
+
+# vim:ts=4:sw=4:et

0 comments on commit e882b3a

Please sign in to comment.