Skip to content

Commit e9a4930

Browse files
committed
diskstat: really discover devs when devices is missing
The diskstat plugin is supposed, by default, to monitor any entry not containing a number under /proc/diskstat. Hence I created a very basic diskstat.pyconf, roughly: modules { module { name = 'diskstat' language = 'python' } } The metric_init would get() 'devices' from the list of parameters which set it to None. The partition discovery is only done when 'devices' is an empty string so the rest of the code would try to interact with None. That eventually leads to: diskstat.py", line 181, in get_partitions for dev in out.split(): AttributeError: 'NoneType' object has no attribute 'split' The fix is to make DEVICES to default to None and change the boolean logic: - if DEVICES != '': + if DEVICES is not None: To be ultra explicit to python newbie, we might even want to update the get() call to: get('devices', None), but I dont think that is really needed.
1 parent e2e3bcb commit e9a4930

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

diskstat/python_modules/diskstat.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
### more information on these values, look in the Linux kernel
77
### documentation for "I/O statistics fields".
88
###
9+
### By default, the script would monitor any entry listed under
10+
### /proc/diskstats that is not containing a number. Override it by passing
11+
### a list of devices in the 'devices' parameter.
12+
###
913
### This script has the option of explicitly setting which devices
1014
### to check using the "devices" option in your configuration. If
1115
### you set this value, it will invalidate the MIN_DISK_SIZE and
@@ -58,7 +62,9 @@
5862

5963
# 5 GB
6064
MIN_DISK_SIZE = 5242880
61-
DEVICES = ''
65+
# Set to None to trigger disk discovery under /proc/diskstats
66+
# Pass a 'devices' parameter to explicitly list disks to monitor
67+
DEVICES = None
6268
IGNORE_DEV = 'dm-|loop|drbd'
6369

6470
PARTITIONS_FILE = '/proc/partitions'
@@ -162,7 +168,7 @@ def get_partitions():
162168
logging.debug('getting partitions')
163169
global PARTITIONS
164170

165-
if DEVICES != '':
171+
if DEVICES is not None:
166172
# Explicit device list has been set
167173
logging.debug(' DEVICES has already been set')
168174
out = DEVICES
@@ -179,7 +185,7 @@ def get_partitions():
179185
return p.returncode
180186

181187
for dev in out.split():
182-
if DEVICES != '':
188+
if DEVICES is not None:
183189
# Explicit device list has been set
184190
PARTITIONS.append(dev)
185191
else:

0 commit comments

Comments
 (0)