From 69faa523a1df0ea2c1fb70805f34e233fdda3c01 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Wed, 5 Feb 2014 23:51:49 +0100 Subject: [PATCH] Option --nocolor no longer implies --noupdate and --noheader This fixes #67 --- docs/dstat.1.txt | 51 +++++++++++++++++----- dstat | 84 ++++++++++++++++++------------------ plugins/dstat_snooze.py | 10 ++--- plugins/dstat_thermal.py | 26 +++++++++-- plugins/dstat_top_bio_adv.py | 2 +- plugins/dstat_top_cpu_adv.py | 2 +- plugins/dstat_top_io_adv.py | 2 +- 7 files changed, 114 insertions(+), 63 deletions(-) diff --git a/docs/dstat.1.txt b/docs/dstat.1.txt index ada8a24..a84cbf1 100644 --- a/docs/dstat.1.txt +++ b/docs/dstat.1.txt @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/dstat b/dstat index ffd2d1f..3c41863 100755 --- a/dstat +++ b/dstat @@ -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']: @@ -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 @@ -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', @@ -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', @@ -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 @@ -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 diff --git a/plugins/dstat_snooze.py b/plugins/dstat_snooze.py index 86607ee..e9331ee 100644 --- a/plugins/dstat_snooze.py +++ b/plugins/dstat_snooze.py @@ -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 diff --git a/plugins/dstat_thermal.py b/plugins/dstat_thermal.py index b470cbf..6119671 100644 --- a/plugins/dstat_thermal.py +++ b/plugins/dstat_thermal.py @@ -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'): @@ -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): diff --git a/plugins/dstat_top_bio_adv.py b/plugins/dstat_top_bio_adv.py index 2e4c6cb..c9647f7 100644 --- a/plugins/dstat_top_bio_adv.py +++ b/plugins/dstat_top_bio_adv.py @@ -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']) diff --git a/plugins/dstat_top_cpu_adv.py b/plugins/dstat_top_cpu_adv.py index 8cccace..900a6a0 100644 --- a/plugins/dstat_top_cpu_adv.py +++ b/plugins/dstat_top_cpu_adv.py @@ -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): diff --git a/plugins/dstat_top_io_adv.py b/plugins/dstat_top_io_adv.py index 9295828..fc78dbb 100644 --- a/plugins/dstat_top_io_adv.py +++ b/plugins/dstat_top_io_adv.py @@ -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'])