diff --git a/README b/README index 1a1d17c..cced252 100644 --- a/README +++ b/README @@ -20,15 +20,22 @@ Here is an example configuration: Import "diskstats" + DeltaPerSecond no Disk sda Disk sda1 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 diff --git a/diskstats.py b/diskstats.py index 0cc413f..f51deb9 100644 --- a/diskstats.py +++ b/diskstats.py @@ -32,6 +32,32 @@ # # # +# 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. +# +# +# ModulePath "/path/to/modules" +# Import "diskstats" +# +# +# DeltaPerSecond yes +# [...] +# +# +# # The fields in /proc/diskstats are documented in Documentation/iostats.txt in # the Linux kernel source tree. @@ -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 @@ -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 @@ -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() @@ -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 @@ -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