Skip to content

Commit

Permalink
Add an option for --diskset for #35 (#42)
Browse files Browse the repository at this point in the history
* Add an option for --diskset for #35

* Documentation for `--diskset`

* Add a plugin for Linux bonding devices (#10)

* Add plugin for Linux bonding devices

* Cover up the "^C" that gets printed when you CTRL + C

---------

Co-authored-by: minghungchen <[email protected]>
  • Loading branch information
scottchiefbaker and minghungchen committed Jun 19, 2023
1 parent bc9aede commit b05092e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
9 changes: 7 additions & 2 deletions docs/dool.1
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ enable disk stats (read, write), for more disk related stats look into the other
plugins
.RE
.PP
\-D total,hda
\-D total,sda
.RS 4
include total and hda (when using \-d/\-\-disk)
include total and sda (when using \-\-disk)
.RE
.PP
\-\-diskset diskset_name:dev1,dev2,dev3,etc\&...
.RS 4
group several disks together and report aggregate stats (when using \-\-disk)
.RE
.PP
\-g, \-\-page
Expand Down
7 changes: 5 additions & 2 deletions docs/dool.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ imported and used by OpenOffice, Gnumeric or Excel to create graphs.
enable disk stats (read, write), for more disk related stats look
into the other *--disk* plugins

-D total,hda::
include total and hda (when using -d/--disk)
-D total,sda::
include total and sda (when using --disk)

--diskset diskset_name:dev1,dev2,dev3,etc...::
group several disks together and report aggregate stats (when using --disk)

-g, --page::
enable page stats (page in, page out)
Expand Down
14 changes: 11 additions & 3 deletions docs/dool.1.html
Original file line number Diff line number Diff line change
Expand Up @@ -803,11 +803,19 @@ <h2 id="_options">OPTIONS</h2>
</p>
</dd>
<dt class="hdlist1">
-D total,hda
-D total,sda
</dt>
<dd>
<p>
include total and hda (when using -d/--disk)
include total and sda (when using --disk)
</p>
</dd>
<dt class="hdlist1">
--diskset diskset_name:dev1,dev2,dev3,etc&#8230;
</dt>
<dd>
<p>
group several disks together and report aggregate stats (when using --disk)
</p>
</dd>
<dt class="hdlist1">
Expand Down Expand Up @@ -2091,7 +2099,7 @@ <h2 id="_author">AUTHOR</h2>
<div id="footer-text">
Version 1.1.0<br />
Last updated
2023-06-05 12:54:51 PDT
2023-06-05 14:47:19 PDT
</div>
</div>
</body>
Expand Down
35 changes: 26 additions & 9 deletions dool
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class Options:
self.cpulist = None
self.debug = 0
self.delay = 1
self.disklist = None
self.disklist = []
self.diskset = {}
self.full = False
self.float = False
self.integer = False
Expand All @@ -87,19 +88,12 @@ class Options:
self.header = False
self.update = False

### Temporary hardcoded for my own project
self.diskset = {
'local': ('sda', 'hd[a-d]'),
'lores': ('sd[b-k]', 'sd[v-z]', 'sda[a-e]'),
'hires': ('sd[l-u]', 'sda[f-o]'),
}

try:
opts, args = getopt.getopt(args, 'acdfghilmno:prstTvyC:D:I:M:N:S:V',
['all', 'all-plugins', 'bits', 'bw', 'bytes', 'black-on-white', 'color',
'defaults', 'debug', 'filesystem', 'float', 'full', 'help', 'integer',
'list', 'mods', 'modules', 'more', 'nocolor', 'noheaders', 'noupdate',
'output=', 'pidfile=', 'profile', 'version', 'vmstat', 'ascii', 'display'] + allplugins)
'output=', 'pidfile=', 'profile', 'version', 'vmstat', 'ascii', 'display', 'diskset='] + allplugins)
except getopt.error as exc:
print('dool: %s, try dool -h for a list of all the options' % exc)
sys.exit(1)
Expand All @@ -125,6 +119,18 @@ class Options:
self.plugins.append('disk')
elif opt in ['-D']:
self.disklist = arg.split(',')
elif opt in ['--diskset']:
parts = arg.split(":", 1)
name = list_item_default(parts, 0, "Unknown")
members = list_item_default(parts, 1, "").split(", ")

if (len(parts) < 2 or len(members) < 1):
print("Error parsing diskset...\n")
print("Format : diskset_name:dev1,dev2,dev3,etc...")
print("Example: --diskset os_drives:sda,sdb")

self.diskset[name] = members
self.disklist.append(name)
elif opt in ['--filesystem']:
self.plugins.append('fs')
elif opt in ['-g']:
Expand Down Expand Up @@ -223,6 +229,9 @@ class Options:
print('dool: option %s unknown to getopt, try dool -h for a list of all the options' % opt)
sys.exit(1)

#k(self.diskset)
#k(self.disklist)

# If --display is before --output we have to reset it here
if '--display' in opt_keys:
self.display = True
Expand Down Expand Up @@ -295,6 +304,7 @@ Dool options:
-C 0,3,total include cpu0, cpu3 and total
-d, --disk enable disk stats
-D total,hda include hda and total
--diskset name:sda,sdb group disks together for aggregate stats
-g, --page enable page stats
-i, --int enable interrupt stats
-I 5,eth2 include int5 and interrupt used by eth2
Expand Down Expand Up @@ -2630,6 +2640,13 @@ def perform(update):
if not op.update:
sys.stdout.write('\n')

# Get an item from a list, or a default value if the array isn't big enough
def list_item_default(mylist, num, default):
if num > len(mylist) - 1:
return default
else:
return mylist[num]

# Borrowed from: https://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python
def stripcolor(self, mystr):
ansi_escape = re.compile(r'\x1B[@-_][0-?]*[ -/]*[@-~]')
Expand Down

0 comments on commit b05092e

Please sign in to comment.