Permalink
Browse files

Added user stat

  • Loading branch information...
dagwieers committed Jan 5, 2005
1 parent 9308c99 commit 3dacd7f8a1bbb141ce4e7522f305c1c7399ed662
Showing with 44 additions and 5 deletions.
  1. +2 −0 ChangeLog
  2. +39 −4 dstat
  3. +2 −0 dstat.1
  4. +1 −1 dstat.spec
View
@@ -3,6 +3,8 @@
- Fixed another crash caused by /proc instability
- Added --csv option to output Comma-Seperated-Value output
- If output is not a tty, don't care about line-width
+- Added user stats using python-utmp
+- Bail out if all requested stats fail
* 0.5.6
- Made sys and int stats unit-aware (so 10000 int/sec -> 10.0k) (Anton Blanchard)
View
43 dstat
@@ -43,9 +43,9 @@ class Options:
self.header = True
try:
- opts, args = getopt.getopt (args, 'acdfghilmnpstvyC:D:I:M:N:',
- ['all', 'cpu', 'disk', 'help', 'int', 'load', 'mem', 'net', 'page',
- 'proc', 'swap', 'sys', 'tcp', 'time', 'udp', 'version', 'vmstat',
+ opts, args = getopt.getopt (args, 'acdfghilmnpstuvyC:D:I:M:N:',
+ ['all', 'cpu', 'disk', 'help', 'int', 'load', 'mem', 'net', 'page', 'proc',
+ 'swap', 'sys', 'tcp', 'time', 'udp', 'user', 'version', 'vmstat',
'csv', 'full', 'integer', 'mods', 'modules', 'nocolor', 'noheader', 'noupdate'])
except getopt.error, exc:
print 'dstat: %s, try dstat -h for a list of all the options' % str(exc)
@@ -86,6 +86,8 @@ class Options:
self.modlist.append('tcp')
elif opt in ['-t', '--time']:
self.modlist.append('time')
+ elif opt in ['-u', '--user']:
+ self.modlist.append('user')
elif opt in ['--udp']:
self.modlist.append('udp')
elif opt in ['-y', '--sys']:
@@ -914,7 +916,7 @@ class dstat_proc(dstat):
self.val['processes'] = 0
self.cn2[name] = long(l[1])
elif name == 'procs_running':
- self.cn2[name] = self.cn2[name] + long(l[1]) - 2
+ self.cn2[name] = self.cn2[name] + long(l[1]) - 1
elif name == 'procs_blocked':
self.cn2[name] = self.cn2[name] + long(l[1])
if update:
@@ -1038,6 +1040,35 @@ class dstat_udp(dstat):
l = line.split()
if l[3] == '07': self.val['connections'] = self.val['connections'] + 1
+class dstat_user(dstat):
+ def __init__(self):
+ self.name = 'users'
+ self.format = '%is'
+ self.len = 3
+ self.nick = ('usr', 'adm' )
+ self.vars = ('users', 'root')
+ self.init()
+
+ def check(self):
+ try:
+ import utmp
+ return True
+ except:
+ print 'The user stat needs the python-utmp module.'
+ return False
+
+ def stats(self):
+ import utmp
+ u = utmp.UtmpRecord()
+ self.val['users'] = 0
+ self.val['root'] = 0
+ for i in u:
+ if i.ut_type == utmp.USER_PROCESS:
+ self.val['users'] = self.val['users'] + 1
+ if i.ut_user == 'root':
+ self.val['root'] = self.val['root'] + 1
+
+
ansi = {
'black': '\033[0;30m',
'darkred': '\033[0;31m',
@@ -1246,6 +1277,7 @@ def main():
elif mod == 'tcp': olist.append(dstat_tcp())
elif mod == 'time': olist.append(dstat_time())
elif mod == 'udp': olist.append(dstat_udp())
+ elif mod == 'user': olist.append(dstat_user())
else:
info(1, 'Module \'%s\' does not exist or failed to load.' % mod)
@@ -1276,6 +1308,9 @@ def main():
else:
olist.remove(o)
+ if not olist:
+ die(8, 'None of the stats you selected are available.')
+
if not op.nolimit:
if linewidth > cols:
print 'Screen width too small, trimming output.'
View
@@ -7,6 +7,8 @@ dstat [-afv] [-cdgilmnpsty] [-D..] [-I..] [-N..] [delay [count]]
.SH DESCRIPTION
Dstat is a versatile replacement for vmstat, iostat and ifstat. Dstat overcomes some of the limitations and adds some extra features.
+For Debian users of Sleuthkit, /usr/bin/dstat has been renamed to /usr/bin/datastat to avoid a name conflict. See bug #283709 for more information.
+
Dstat allows you to view all of your system resources instantly, you can eg. compare disk usage in combination with interrupts from your IDE controller, or compare the network bandwidth numbers directly with the disk throughput (in the same interval).
.TP
\fB\-c\fR, \fB\-\-cpu\fR
View
@@ -72,7 +72,7 @@ interprete real-time data as easy as possible.
%{_bindir}/dstat
%changelog
-* Tue Dec 21 2004 Dag Wieers <dag@wieers.com> - 0.5.7-1
+* Fri Dec 31 2004 Dag Wieers <dag@wieers.com> - 0.5.7-1
- Updated to release 0.5.7.
* Mon Dec 20 2004 Dag Wieers <dag@wieers.com> - 0.5.6-1

0 comments on commit 3dacd7f

Please sign in to comment.