Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ Here is an example configuration:
Import "diskstats"

<Module diskstats>
DeltaPerSecond no
Disk sda
Disk sda1
</Module>
</Plugin>

The plugin produces data for the "diskstats" plugin. The plugin instance
will be the device name. The plugin will write gauge data for 10 types. The
will be the device name. The plugin will write data for 10 types. The
type instance corresponds to the fields in /proc/iostats.

DeltaPerSecond option allow to send either data as delta per seconds or as
delta per measurement interval (collectd use 10 second by default). This change
is backward incompatible: mixing per-seconds and per-interval would be
meaningless.
DeltaPerSecond could be either "yes" or "no", and defaults to "no".

The Documentation/iostats.txt file in the Linux kernel source tree
(http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob_plain;f=Documentation/iostats.txt;hb=refs/tags/v2.6.36)
describes the fields in /proc/diskstats and can help you make sense of the
Expand Down
49 changes: 45 additions & 4 deletions diskstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@
# </Module>
#</Plugin>
#
# Values from /proc/diskstats are increasing counters, to make values usable a
# delta is computed between two measurements. Delta could be either computed
# by this plugin or by collectd. This plugin compute the delta
# per-interval (usually 10 seconds). On the other hand, collectd compute the
# delta per-second.
#
# Note: This change is backward incompatible. Per-second value and
# per-interval (per 10 seconds with default config) values can not be mixed.
# In addition, because metric are send either as gauge (delta per-interval)
# or as counter (delta per-second), the metrics will not have the same name.
#
# This is configurable using the param 'DeltaPerSecond', which could be either
# 'yes' or 'no' (default to no).
#
# e.g.
#
#<Plugin python>
# ModulePath "/path/to/modules"
# Import "diskstats"
#
# <Module diskstats>
# DeltaPerSecond yes
# [...]
# </Module>
#</Plugin>
#
# The fields in /proc/diskstats are documented in Documentation/iostats.txt in
# the Linux kernel source tree.

Expand All @@ -53,9 +79,13 @@

disks = []

delta_per_second = False

previous_values = {}

def diskstats_config(c):
global delta_per_second

if c.values[0] != 'diskstats':
return

Expand All @@ -66,6 +96,9 @@ def diskstats_config(c):
disks.append(v)
if v not in previous_values:
previous_values[v] = {}
elif child.key == 'DeltaPerSecond':
if len(child.values) > 0 and child.values[0] is True:
delta_per_second = True

def diskstats_read(data=None):
# if no disks to monitor, do nothing
Expand All @@ -75,6 +108,7 @@ def diskstats_read(data=None):
fh = open('/proc/diskstats', 'r')

values = collectd.Values(type='gauge', plugin='diskstats')
values_counter = collectd.Values(type='counter', plugin='diskstats')

for line in fh:
fields = line.split()
Expand All @@ -96,6 +130,17 @@ def diskstats_read(data=None):

value = int(fields[i+2])

# field 9 is not a counter
if i == 9:
values.dispatch(plugin_instance=device, type_instance=field_map[i], values=[value])
continue

# when delta is per-second, send mertric as counter and let collectd
# do the delta. In other case, this plugin will do the delta.
if delta_per_second:
values_counter.dispatch(plugin_instance=device, type_instance=field_map[i], values=[value])
continue

# if this is the first value, simply record and move on to next field
if i not in previous_values[device]:
previous_values[device][i] = value
Expand All @@ -112,10 +157,6 @@ def diskstats_read(data=None):
else:
delta = value - previous_value

# field 9 is not a counter
if i == 9:
delta = value

# record the new previous value
previous_values[device][i] = value

Expand Down