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

Commit

Permalink
Option --nocolor no longer implies --noupdate and --noheader
Browse files Browse the repository at this point in the history
This fixes #67
  • Loading branch information
dagwieers committed Feb 5, 2014
1 parent 0a9f0fc commit 69faa52
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 63 deletions.
51 changes: 41 additions & 10 deletions docs/dstat.1.txt
Expand Up @@ -40,15 +40,16 @@ information.

== OPTIONS
-c, --cpu::
enable cpu stats (system, user, idle, wait, hardware interrupt, software
interrupt)
enable cpu stats (system, user, idle, wait), for more CPU related
stats also try *--cpu-adv*

-C 0,3,total::
include cpu0, cpu3 and total (when using -c/--cpu); use 'all' to show all
CPUs

-d, --disk::
enable disk stats (read, write)
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)
Expand All @@ -66,7 +67,8 @@ information.
enable load average stats (1 min, 5 mins, 15mins)

-m, --mem::
enable memory stats (used, buffers, cache, free)
enable memory stats (used, buffers, cache, free); for more memory
related stats also try *--mem-adv* and *--swap*

-n, --net::
enable network stats (receive, send)
Expand Down Expand Up @@ -98,6 +100,9 @@ information.
--aio::
enable aio stats (asynchronous I/O)

--cpu-adv::
enable advanced cpu stats

--fs, --filesystem::
enable filesystem stats (open files, inodes)

Expand All @@ -107,6 +112,9 @@ information.
--lock::
enable file lock stats (posix, flock, read, write)

--mem-adv::
enable advanced memory stats

--raw::
enable raw stats (raw sockets)

Expand Down Expand Up @@ -135,9 +143,9 @@ information.
enable (external) plugins by plugin name, see *PLUGINS* for options

Possible internal stats are::
aio, cpu, cpu24, disk, disk24, disk24old, epoch, fs, int, int24, io, ipc,
load, lock, mem, net, page, page24, proc, raw, socket, swap, swapold,
sys, tcp, time, udp, unix, vm
aio, cpu, cpu24, disk, disk24, disk24-old, epoch, fs, int, int24, io, ipc,
load, lock, mem, mem-adv, net, page, page24, proc, raw, socket, swap,
swap-old, sys, tcp, time, udp, unix, vm, vm-adv, zones

--list::
list the internal and external plugin names
Expand All @@ -164,7 +172,7 @@ Possible internal stats are::
change colors for white background terminal

--nocolor::
disable colors (implies *--noupdate*)
disable colors

--noheaders::
disable repetitive headers
Expand Down Expand Up @@ -466,8 +474,31 @@ Paths that may contain external dstat_*.py plugins:

== ENVIRONMENT VARIABLES

dstat will read additional command line arguments from the environment
variable *DSTAT_OPTS*.
Dstat will read additional command line arguments from the environment
variable *DSTAT_OPTS*. You can use this to configure Dstat's default
behavior, e.g. if you have a black-on-white terminal:

export DSTAT_OPTS="--bw --noupdate"

Other internal or external plugins have their own environment variables
to influence their behavior, e.g.


DSTAT_NTPSERVER

DSTAT_MYSQL
DSTAT_MYSQL_HOST
DSTAT_MYSQL_PORT
DSTAT_MYSQL_SOCKET
DSTAT_MYSQL_USER
DSTAT_MYSQL_PWD

DSTAT_SNMPSERVER
DSTAT_SNMPCOMMUNITY

DSTAT_SQUID_OPTS

DSTAT_TIMEFMT

== SEE ALSO

Expand Down
84 changes: 42 additions & 42 deletions dstat
Expand Up @@ -195,7 +195,6 @@ class Options:
sys.exit(0)
elif opt in ['--nocolor']:
self.color = False
self.update = False
elif opt in ['--noheaders']:
self.header = False
elif opt in ['--noupdate']:
Expand Down Expand Up @@ -319,7 +318,7 @@ Dstat options:
--bw, --blackonwhite change colors for white background terminal
--color force colors
--nocolor disable colors (implies --noupdate)
--nocolor disable colors
--noheaders disable repetitive headers
--noupdate disable intermediate updates
--output file write CSV output to file
Expand Down Expand Up @@ -1716,7 +1715,7 @@ class dstat_zones(dstat):

### END STATS DEFINITIONS ###

ansi = {
color = {
'black': '\033[0;30m',
'darkred': '\033[0;31m',
'darkgreen': '\033[0;32m',
Expand All @@ -1743,7 +1742,9 @@ ansi = {
'magentabg': '\033[45m',
'cyanbg': '\033[46m',
'whitebg': '\033[47m',
}

ansi = {
'reset': '\033[0;0m',
'bold': '\033[1m',
'reverse': '\033[2m',
Expand Down Expand Up @@ -1782,45 +1783,45 @@ def set_theme():
"Provide a set of colors to use"
if op.blackonwhite:
theme = {
'title': ansi['darkblue'],
'subtitle': ansi['darkcyan'] + ansi['underline'],
'frame': ansi['darkblue'],
'title': color['darkblue'],
'subtitle': color['darkcyan'] + ansi['underline'],
'frame': color['darkblue'],
'default': ansi['default'],
'error': ansi['white'] + ansi['redbg'],
'roundtrip': ansi['darkblue'],
'debug': ansi['darkred'],
'input': ansi['darkgray'],
'done_lo': ansi['black'],
'done_hi': ansi['darkgray'],
'text_lo': ansi['black'],
'text_hi': ansi['darkgray'],
'unit_lo': ansi['black'],
'unit_hi': ansi['darkgray'],
'colors_lo': (ansi['darkred'], ansi['darkmagenta'], ansi['darkgreen'], ansi['darkblue'],
ansi['darkcyan'], ansi['black'], ansi['red'], ansi['green']),
'colors_hi': (ansi['red'], ansi['magenta'], ansi['green'], ansi['blue'],
ansi['cyan'], ansi['darkgray'], ansi['darkred'], ansi['darkgreen']),
'error': color['white'] + color['redbg'],
'roundtrip': color['darkblue'],
'debug': color['darkred'],
'input': color['darkgray'],
'done_lo': color['black'],
'done_hi': color['darkgray'],
'text_lo': color['black'],
'text_hi': color['darkgray'],
'unit_lo': color['black'],
'unit_hi': color['darkgray'],
'colors_lo': (color['darkred'], color['darkmagenta'], color['darkgreen'], color['darkblue'],
color['darkcyan'], color['black'], color['red'], color['green']),
'colors_hi': (color['red'], color['magenta'], color['green'], color['blue'],
color['cyan'], color['darkgray'], color['darkred'], color['darkgreen']),
}
else:
theme = {
'title': ansi['darkblue'],
'subtitle': ansi['blue'] + ansi['underline'],
'frame': ansi['darkblue'],
'title': color['darkblue'],
'subtitle': color['blue'] + ansi['underline'],
'frame': color['darkblue'],
'default': ansi['default'],
'error': ansi['white'] + ansi['redbg'],
'roundtrip': ansi['darkblue'],
'debug': ansi['darkred'],
'input': ansi['darkgray'],
'done_lo': ansi['white'],
'done_hi': ansi['gray'],
'text_lo': ansi['gray'],
'text_hi': ansi['darkgray'],
'unit_lo': ansi['darkgray'],
'unit_hi': ansi['darkgray'],
'colors_lo': (ansi['red'], ansi['yellow'], ansi['green'], ansi['blue'],
ansi['cyan'], ansi['white'], ansi['darkred'], ansi['darkgreen']),
'colors_hi': (ansi['darkred'], ansi['darkyellow'], ansi['darkgreen'], ansi['darkblue'],
ansi['darkcyan'], ansi['gray'], ansi['red'], ansi['green']),
'error': color['white'] + color['redbg'],
'roundtrip': color['darkblue'],
'debug': color['darkred'],
'input': color['darkgray'],
'done_lo': color['white'],
'done_hi': color['gray'],
'text_lo': color['gray'],
'text_hi': color['darkgray'],
'unit_lo': color['darkgray'],
'unit_hi': color['darkgray'],
'colors_lo': (color['red'], color['yellow'], color['green'], color['blue'],
color['cyan'], color['white'], color['darkred'], color['darkgreen']),
'colors_hi': (color['darkred'], color['darkyellow'], color['darkgreen'], color['darkblue'],
color['darkcyan'], color['gray'], color['red'], color['green']),
}
return theme

Expand Down Expand Up @@ -2568,15 +2569,14 @@ def main():
op.pidfile = False

### Empty ansi and theme database if no colors are requested
if op.color != True:
op.update = False
for key in ansi.keys():
ansi[key] = ''
if not op.color:
for key in color.keys():
color[key] = ''
for key in theme.keys():
theme[key] = ''
theme['colors_hi'] = (ansi['default'],)
theme['colors_lo'] = (ansi['default'],)
# print ansi['blackbg']
# print color['blackbg']

if not op.update:
interval = op.delay
Expand Down
10 changes: 5 additions & 5 deletions plugins/dstat_snooze.py
Expand Up @@ -21,14 +21,14 @@ def show(self):
return ansi['default'] + ' -'

if op.blackonwhite:
color = 'black'
textcolor = 'black'
if step != op.delay:
color = 'darkgray'
textcolor = 'darkgray'
else:
color = 'white'
textcolor = 'white'
if step != op.delay:
color = 'gray'
textcolor = 'gray'

snoze, c = fchg(self.val['snooze'], 6, 1000)

return ansi[color] + snoze
return color[textcolor] + snoze
26 changes: 23 additions & 3 deletions plugins/dstat_thermal.py
Expand Up @@ -6,7 +6,14 @@ def __init__(self):
self.type = 'd'
self.width = 3
self.scale = 20
if os.path.exists('/proc/acpi/ibm/thermal'):

if os.path.exists('/sys/bus/acpi/devices/LNXTHERM:01/thermal_zone/'):
self.vars = os.listdir('/sys/bus/acpi/devices/LNXTHERM:01/thermal_zone/')
self.nick = []
for name in self.vars:
self.nick.append(name.lower())

elif os.path.exists('/proc/acpi/ibm/thermal'):
self.namelist = ['cpu', 'pci', 'hdd', 'cpu', 'ba0', 'unk', 'ba1', 'unk']
self.nick = []
for line in dopen('/proc/acpi/ibm/thermal'):
Expand All @@ -15,21 +22,34 @@ def __init__(self):
if int(l[i+1]) > 0:
self.nick.append(name)
self.vars = self.nick

elif os.path.exists('/proc/acpi/thermal_zone/'):
self.vars = os.listdir('/proc/acpi/thermal_zone/')
# self.nick = [name.lower() for name in self.vars]
self.nick = []
for name in self.vars:
self.nick.append(name.lower())

else:
raise Exception, 'Needs kernel ACPI or IBM-ACPI support'

def check(self):
if not os.path.exists('/proc/acpi/ibm/thermal') and not os.path.exists('/proc/acpi/thermal_zone/'):
if not os.path.exists('/proc/acpi/ibm/thermal') and \
not os.path.exists('/proc/acpi/thermal_zone/') and \
not os.path.exists('/sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/'):
raise Exception, 'Needs kernel ACPI or IBM-ACPI support'

def extract(self):
if os.path.exists('/proc/acpi/ibm/thermal'):
if os.path.exists('/sys/bus/acpi/devices/LNXTHERM:01/thermal_zone/'):
for zone in self.vars:
if os.path.isdir('/sys/bus/acpi/devices/LNXTHERM:01/thermal_zone/'+zone) == False:
for line in dopen('/sys/bus/acpi/devices/LNXTHERM:01/thermal_zone/'+zone).readlines():
l = line.split()
if l[0].isdigit() == True:
self.val[zone] = int(l[0])
else:
self.val[zone] = 0
elif os.path.exists('/proc/acpi/ibm/thermal'):
for line in dopen('/proc/acpi/ibm/thermal'):
l = line.split()
for i, name in enumerate(self.namelist):
Expand Down
2 changes: 1 addition & 1 deletion plugins/dstat_top_bio_adv.py
Expand Up @@ -69,7 +69,7 @@ def extract(self):
self.pidset1 = self.pidset2

if self.val['usage'] != 0.0:
self.output = '%-*s%s%-5s%s%s%s%s%%' % (self.width-14-len(pid), self.val['name'][0:self.width-14-len(pid)], ansi['darkblue'], self.val['pid'], cprint(self.val['read_usage'], 'd', 5, 1024), cprint(self.val['write_usage'], 'd', 5, 1024), cprint(self.val['cpu_usage'], 'f', 3, 34), ansi['darkgray'])
self.output = '%-*s%s%-5s%s%s%s%s%%' % (self.width-14-len(pid), self.val['name'][0:self.width-14-len(pid)], color['darkblue'], self.val['pid'], cprint(self.val['read_usage'], 'd', 5, 1024), cprint(self.val['write_usage'], 'd', 5, 1024), cprint(self.val['cpu_usage'], 'f', 3, 34), color['darkgray'])

def showcsv(self):
return 'Top: %s\t%s\t%s\t%s' % (self.val['name'][0:self.width-20], self.val['read_usage'], self.val['write_usage'], self.val['cpu_usage'])
2 changes: 1 addition & 1 deletion plugins/dstat_top_cpu_adv.py
Expand Up @@ -67,7 +67,7 @@ def extract(self):
self.pidset1 = self.pidset2

if self.val['cpu_usage'] != 0.0:
self.output = '%-*s%s%-5s%s%s%%%s%s' % (self.width-14-len(pid), self.val['name'][0:self.width-14-len(pid)], ansi['darkblue'], self.val['pid'], cprint(self.val['cpu_usage'], 'f', 3, 34), ansi['darkgray'],cprint(self.val['read_usage'], 'd', 5, 1024), cprint(self.val['write_usage'], 'd', 5, 1024))
self.output = '%-*s%s%-5s%s%s%%%s%s' % (self.width-14-len(pid), self.val['name'][0:self.width-14-len(pid)], color['darkblue'], self.val['pid'], cprint(self.val['cpu_usage'], 'f', 3, 34), color['darkgray'],cprint(self.val['read_usage'], 'd', 5, 1024), cprint(self.val['write_usage'], 'd', 5, 1024))


def showcsv(self):
Expand Down
2 changes: 1 addition & 1 deletion plugins/dstat_top_io_adv.py
Expand Up @@ -69,7 +69,7 @@ def extract(self):
self.pidset1 = self.pidset2

if self.val['usage'] != 0.0:
self.output = '%-*s%s%-5s%s%s%s%s%%' % (self.width-14-len(pid), self.val['name'][0:self.width-14-len(pid)], ansi['darkblue'], self.val['pid'], cprint(self.val['read_usage'], 'd', 5, 1024), cprint(self.val['write_usage'], 'd', 5, 1024), cprint(self.val['cpu_usage'], 'f', 3, 34), ansi['darkgray'])
self.output = '%-*s%s%-5s%s%s%s%s%%' % (self.width-14-len(pid), self.val['name'][0:self.width-14-len(pid)], color['darkblue'], self.val['pid'], cprint(self.val['read_usage'], 'd', 5, 1024), cprint(self.val['write_usage'], 'd', 5, 1024), cprint(self.val['cpu_usage'], 'f', 3, 34), color['darkgray'])

def showcsv(self):
return 'Top: %s\t%s\t%s\t%s' % (self.val['name'][0:self.width-20], self.val['read_usage'], self.val['write_usage'], self.val['cpu_usage'])

0 comments on commit 69faa52

Please sign in to comment.