[modules/zpool] quotes

This commit is contained in:
tobi-wan-kenobi 2020-04-25 10:27:27 +02:00
parent 2048ac8706
commit dcc06307d9

View file

@ -2,13 +2,13 @@
Parameters: Parameters:
* zpool.list: Comma-separated list of zpools to display info for. If empty, info for all zpools * zpool.list: Comma-separated list of zpools to display info for. If empty, info for all zpools
is displayed. (Default: "") is displayed. (Default: '')
* zpool.format: Format string, tags {name}, {used}, {left}, {size}, {percentfree}, {percentuse}, * zpool.format: Format string, tags {name}, {used}, {left}, {size}, {percentfree}, {percentuse},
{status}, {shortstatus}, {fragpercent}, {deduppercent} are supported. {status}, {shortstatus}, {fragpercent}, {deduppercent} are supported.
(Default: "{name} {used}/{size} ({percentfree}%)") (Default: '{name} {used}/{size} ({percentfree}%)')
* zpool.showio: Show also widgets detailing current read and write I/O (Default: true) * zpool.showio: Show also widgets detailing current read and write I/O (Default: true)
* zpool.ioformat: Format string for I/O widget, tags {ops} (operations per seconds) and {band} * zpool.ioformat: Format string for I/O widget, tags {ops} (operations per seconds) and {band}
(bandwidth) are supported. (Default: "{band}") (bandwidth) are supported. (Default: '{band}')
* zpool.warnfree: Warn if free space is below this percentage (Default: 10) * zpool.warnfree: Warn if free space is below this percentage (Default: 10)
* zpool.sudo: Use sudo when calling the `zpool` binary. (Default: false) * zpool.sudo: Use sudo when calling the `zpool` binary. (Default: false)
@ -38,13 +38,13 @@ class Module(bumblebee.engine.Module):
super(Module, self).__init__(engine, config, widgets) super(Module, self).__init__(engine, config, widgets)
self._includelist = set(filter(lambda x: len(x) > 0, self._includelist = set(filter(lambda x: len(x) > 0,
self.parameter("list", default="").split(','))) self.parameter('list', default='').split(',')))
self._format = self.parameter("format", default="{name} {shortstatus} {used}/{size} " + self._format = self.parameter('format', default='{name} {shortstatus} {used}/{size} ' +
"({percentfree}%)") '({percentfree}%)')
self._usesudo = asbool(self.parameter("sudo", default=False)) self._usesudo = asbool(self.parameter('sudo', default=False))
self._showio = asbool(self.parameter("showio", default=True)) self._showio = asbool(self.parameter('showio', default=True))
self._ioformat = self.parameter("ioformat", default="{band}") self._ioformat = self.parameter('ioformat', default='{band}')
self._warnfree = int(self.parameter("warnfree", default=10)) self._warnfree = int(self.parameter('warnfree', default=10))
self._update_widgets(widgets) self._update_widgets(widgets)
@ -52,39 +52,39 @@ class Module(bumblebee.engine.Module):
self._update_widgets(widgets) self._update_widgets(widgets)
def state(self, widget): def state(self, widget):
if widget.name.endswith("__read"): if widget.name.endswith('__read'):
return "poolread" return 'poolread'
elif widget.name.endswith("__write"): elif widget.name.endswith('__write'):
return "poolwrite" return 'poolwrite'
state = widget.get("state") state = widget.get('state')
if state == "FAULTED": if state == 'FAULTED':
return [state, "critical"] return [state, 'critical']
elif state == "DEGRADED" or widget.get("percentfree") < self._warnfree: elif state == 'DEGRADED' or widget.get('percentfree') < self._warnfree:
return [state, "warning"] return [state, 'warning']
return state return state
def _update_widgets(self, widgets): def _update_widgets(self, widgets):
zfs_version_path = "/sys/module/zfs/version" zfs_version_path = '/sys/module/zfs/version'
# zpool list -H: List all zpools, use script mode (no headers and tabs as separators). # zpool list -H: List all zpools, use script mode (no headers and tabs as separators).
try: try:
with open(zfs_version_path, 'r') as zfs_mod_version: with open(zfs_version_path, 'r') as zfs_mod_version:
zfs_version = zfs_mod_version.readline().rstrip().split('-')[0] zfs_version = zfs_mod_version.readline().rstrip().split('-')[0]
except IOError: except IOError:
# ZFS isn't installed or the module isn't loaded, stub the version # ZFS isn't installed or the module isn't loaded, stub the version
zfs_version = "0.0.0" zfs_version = '0.0.0'
logging.error("ZFS version information not found at {}, check the module is loaded.".format(zfs_version_path)) logging.error('ZFS version information not found at {}, check the module is loaded.'.format(zfs_version_path))
raw_zpools = execute(('sudo ' if self._usesudo else '') + 'zpool list -H').split('\n') raw_zpools = execute(('sudo ' if self._usesudo else '') + 'zpool list -H').split('\n')
for widget in widgets: for widget in widgets:
widget.set("visited", False) widget.set('visited', False)
for raw_zpool in raw_zpools: for raw_zpool in raw_zpools:
try: try:
# Ignored fields (assigned to _) are "expandsz" and "altroot", also "ckpoint" in ZFS 0.8.0+ # Ignored fields (assigned to _) are 'expandsz' and 'altroot', also 'ckpoint' in ZFS 0.8.0+
if parse_version(zfs_version) < parse_version("0.8.0"): if parse_version(zfs_version) < parse_version('0.8.0'):
name, size, alloc, free, _, frag, cap, dedup, health, _ = raw_zpool.split('\t') name, size, alloc, free, _, frag, cap, dedup, health, _ = raw_zpool.split('\t')
else: else:
name, size, alloc, free, _, _, frag, cap, dedup, health, _ = raw_zpool.split('\t') name, size, alloc, free, _, _, frag, cap, dedup, health, _ = raw_zpool.split('\t')
@ -98,7 +98,7 @@ class Module(bumblebee.engine.Module):
# (and timestamp) during each widget update, and during the next widget update we # (and timestamp) during each widget update, and during the next widget update we
# use them to compute delta of transferred bytes, and using the last and current # use them to compute delta of transferred bytes, and using the last and current
# timestamp the rate at which they have been transferred. # timestamp the rate at which they have been transferred.
with open("/proc/spl/kstat/zfs/{}/io".format(name), "r") as f: with open('/proc/spl/kstat/zfs/{}/io'.format(name), 'r') as f:
# Third row provides data we need, we are interested in the first 4 values. # Third row provides data we need, we are interested in the first 4 values.
# More info about this file can be found here: # More info about this file can be found here:
# https://github.com/zfsonlinux/zfs/blob/master/lib/libspl/include/sys/kstat.h#L580 # https://github.com/zfsonlinux/zfs/blob/master/lib/libspl/include/sys/kstat.h#L580
@ -115,12 +115,12 @@ class Module(bumblebee.engine.Module):
widget = self.widget(name) widget = self.widget(name)
if not widget: if not widget:
widget = bumblebee.output.Widget(name=name) widget = bumblebee.output.Widget(name=name)
widget.set("last_iostat", [0, 0, 0, 0]) widget.set('last_iostat', [0, 0, 0, 0])
widget.set("last_timestamp", 0) widget.set('last_timestamp', 0)
widgets.append(widget) widgets.append(widget)
delta_iostat = [b - a for a, b in zip(iostat, widget.get("last_iostat"))] delta_iostat = [b - a for a, b in zip(iostat, widget.get('last_iostat'))]
widget.set("last_iostat", iostat) widget.set('last_iostat', iostat)
# From docs: # From docs:
# > Note that even though the time is always returned as a floating point number, not # > Note that even though the time is always returned as a floating point number, not
@ -129,8 +129,8 @@ class Module(bumblebee.engine.Module):
# Also, during one update cycle the reported I/O may be garbage if the system time # Also, during one update cycle the reported I/O may be garbage if the system time
# was changed. # was changed.
timestamp = time.time() timestamp = time.time()
delta_timestamp = widget.get("last_timestamp") - timestamp delta_timestamp = widget.get('last_timestamp') - timestamp
widget.set("last_timestamp", time.time()) widget.set('last_timestamp', time.time())
# abs is there because sometimes the result is -0 # abs is there because sometimes the result is -0
rate_iostat = [abs(x / delta_timestamp) for x in delta_iostat] rate_iostat = [abs(x / delta_timestamp) for x in delta_iostat]
@ -143,12 +143,12 @@ class Module(bumblebee.engine.Module):
status=health, status=health,
shortstatus=self._shortstatus(health), shortstatus=self._shortstatus(health),
fragpercent=frag, deduppercent=dedup)) fragpercent=frag, deduppercent=dedup))
widget.set("state", health) widget.set('state', health)
widget.set("percentfree", percentfree) widget.set('percentfree', percentfree)
widget.set("visited", True) widget.set('visited', True)
if self._showio: if self._showio:
wname, rname = [name + x for x in ["__write", "__read"]] wname, rname = [name + x for x in ['__write', '__read']]
widget_w = self.widget(wname) widget_w = self.widget(wname)
widget_r = self.widget(rname) widget_r = self.widget(rname)
if not widget_w or not widget_r: if not widget_w or not widget_r:
@ -156,16 +156,16 @@ class Module(bumblebee.engine.Module):
widget_w = bumblebee.output.Widget(name=wname) widget_w = bumblebee.output.Widget(name=wname)
widgets.extend([widget_r, widget_w]) widgets.extend([widget_r, widget_w])
for w in [widget_r, widget_w]: for w in [widget_r, widget_w]:
w.set("theme.minwidth", self._ioformat.format(ops=9999, w.set('theme.minwidth', self._ioformat.format(ops=9999,
band=bytefmt(999.99*(1024**2)))) band=bytefmt(999.99*(1024**2))))
w.set("visited", True) w.set('visited', True)
widget_w.full_text(self._ioformat.format(ops=round(writes), widget_w.full_text(self._ioformat.format(ops=round(writes),
band=bytefmt(nwritten))) band=bytefmt(nwritten)))
widget_r.full_text(self._ioformat.format(ops=round(reads), widget_r.full_text(self._ioformat.format(ops=round(reads),
band=bytefmt(nread))) band=bytefmt(nread)))
for widget in widgets: for widget in widgets:
if widget.get("visited") is False: if widget.get('visited') is False:
widgets.remove(widget) widgets.remove(widget)
@staticmethod @staticmethod
@ -177,11 +177,11 @@ class Module(bumblebee.engine.Module):
# configuration. A faulted pool has corrupted metadata, or one or more faulted devices, and # configuration. A faulted pool has corrupted metadata, or one or more faulted devices, and
# insufficient replicas to continue functioning. # insufficient replicas to continue functioning.
shortstate = { shortstate = {
"DEGRADED": "DEG", 'DEGRADED': 'DEG',
"FAULTED": "FLT", 'FAULTED': 'FLT',
"ONLINE": "ONL", 'ONLINE': 'ONL',
} }
try: try:
return shortstate[status] return shortstate[status]
except KeyError: except KeyError:
return "" return ''