Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Improvements to swap
Browse files Browse the repository at this point in the history
  • Loading branch information
dagwieers committed Jun 15, 2006
1 parent 1932737 commit d946cac
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -7,6 +7,7 @@
- Exclude md-devices from total
- Improved debug output somewhat
- Moved documentation to asciidoc at last
- Added individual swap monitoring (-s with -S)

* 0.6.2 - Cumbernauld - released 08/03/2006
- Fixed situation where no TERM environment variable was set (William Webber)
Expand Down
63 changes: 62 additions & 1 deletion dstat
Expand Up @@ -81,6 +81,7 @@ class Options:
self.integer = False
self.intlist = None
self.netlist = None
self.swaplist = None
self.nolimit = False
self.color = True
self.update = True
Expand All @@ -96,7 +97,7 @@ class Options:

try:
import getopt
opts, args = getopt.getopt (args, 'acdfghilmno:pstvyC:D:I:M:N:V',
opts, args = getopt.getopt (args, 'acdfghilmno:pstvyC:D:I:M:N:S:V',
['all', 'cpu', 'disk', 'help', 'int', 'ipc', 'load', 'lock', 'mem', 'net', 'page',
'proc', 'raw', 'swap', 'sys', 'tcp', 'time', 'udp', 'unix', 'version', 'vmstat',
'debug', 'full', 'integer', 'mods', 'modules', 'nocolor', 'noheaders', 'noupdate', 'output='])
Expand Down Expand Up @@ -143,6 +144,8 @@ class Options:
self.modlist.append('raw')
elif opt in ['-s', '--swap']:
self.modlist.append('swap')
elif opt in ['-S']:
self.swaplist = arg.split(',')
elif opt in ['--tcp']:
self.modlist.append('tcp')
elif opt in ['-t', '--time']:
Expand Down Expand Up @@ -1114,6 +1117,55 @@ class dstat_raw(dstat):
self.val['sockets'] = len(self.fd.readlines()) - 1

class dstat_swap(dstat):
def __init__(self):
self.name = 'swap'
self.format = ('f', 5, 1024)
self.open('/proc/swaps')
self.nick = ('used', 'free')
self.vars = self.vars()
self.name = ['swp/'+improve(name) for name in self.vars]
self.init(self.vars + ['total',], 2)

def discover(self, *list):
ret = []
self.fd.seek(0)
for line in self.fd.readlines():
l = line.split()
if len(l) < 5: continue
if l[0] == 'Filename': continue
ret.append(improve(l[0]))
ret.sort()
for item in list: ret.append(item)
return ret

def vars(self):
ret = []
if op.swaplist:
list = op.swaplist
elif not op.full:
list = ('total', )
else:
list = self.discover()
# if len(list) > 2: list = list[0:2]
list.sort()
for name in list:
if name in self.discover('total',):
ret.append(name)
return ret

def extract(self):
self.val['total'] = [0, 0]
self.fd.seek(0)
for line in self.fd.readlines():
l = line.split()
if len(l) < 5: continue
if l[0] == 'Filename': continue
name = improve(l[0])
if name in self.vars :
self.val[name] = ( long(l[3]) * 1024.0, (long(l[2]) - long(l[3])) * 1024.0 )
self.val['total'] = ( self.val['total'][0] + long(l[3]) * 1024.0, self.val['total'][1] + (long(l[2]) - long(l[3])) * 1024.0)

class dstat_swapold(dstat):
def __init__(self):
self.name = 'swap'
self.format = ('f', 5, 1024)
Expand Down Expand Up @@ -1303,6 +1355,14 @@ def ticks():
if l[0] == 'btime':
return time.time() - long(l[1])

def improve(str):
"Improve a device name"
if str.startswith('/dev/mapper/'):
str = str.split('/')[3]
elif str.startswith('/dev/'):
str = str.split('/')[2]
return str

def dopen(file):
"Open a file for reuse, if already opened, return file descriptor"
global fds
Expand Down Expand Up @@ -1649,6 +1709,7 @@ def main():
elif module == 'disk': mods = ( 'disk', 'disk24', 'disk24old' )
elif module == 'int': mods = ( 'int', 'int24' )
elif module == 'page': mods = ( 'page', 'page24' )
elif module == 'swap': mods = ( 'swap', 'swapold' )
else: mods = ( module, )

for mod in mods:
Expand Down

0 comments on commit d946cac

Please sign in to comment.