collectd / collectd

The system statistics collection daemon. Please send Pull Requests here!

Home Page:http://collectd.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swap plugin sends usage data twice

VikingExpat opened this issue · comments

  • Version of collectd: 5.12
  • Operating system / distribution: NetBSD
  • Kernel version (if applicable): NetBSD-9.3_STABLE

Expected behavior

Swap usage data entered into rrd without error messages.

Actual behavior

For each update of swap usage data the following error messages are logged:

[2023-09-12 22:12:27] rrdtool plugin: rrd_update_r (/data/collectd/rrd/host/swap/percent-used.rrd) failed: /data/collectd/rrd/host/swap/percent-used.rrd: illegal attempt to update using time 1694571027 when last update time is 0 (minimum one second step)  
[2023-09-12 22:12:27] rrdtool plugin: rrd_update_r (/data/collectd/rrd/host/swap/percent-free.rrd) failed: /data/collectd/rrd/host/swap/percent-free.rrd: illegal attempt to update using time 1694571027 when last update time is 0 (minimum one second step)  

Steps to reproduce

  • step 1
    Add the following to collectd.conf to configure the swap plugin:
LoadPlugin logfile
<Plugin logfile>
        LogLevel info
        File STDOUT
        Timestamp true
        PrintSeverity false
</Plugin>
LoadPlugin swap
<Plugin swap>
        ReportByDevice false
        ReportBytes false
        ValuesAbsolute false
        ValuesPercentage true
        ReportIO false
</Plugin>
LoadPlugin rrdtool
<Plugin rrdtool>
        DataDir "/data/collectd/rrd"
        CreateFilesAsync false
        CacheTimeout 120
        CacheFlush 900
        WritesPerSecond 50
</Plugin>
  • step 2
    Start collectd:
    collectd -C /path-to/collectd.conf -f

  • step 3
    After the first write to the rrd files the above messages are logged.

  • The fix:
    There is an extra call to swap_submit_usage() when it should only be called when ReportByDevice is false.

--- swap.c.orig 2023-09-12 22:33:35.289988884 -0400
+++ swap.c      2023-09-12 22:33:53.798834610 -0400
@@ -655,9 +655,8 @@
     sfree(swap_entries);
     return -1;
   }
 
-  swap_submit_usage(NULL, used, total - used, NULL, NAN); 
   /* If the "separate" option was specified (report_by_device == 1), all
    * values have already been dispatched from within the loop. */
   if (!report_by_device)
     swap_submit_usage(NULL, used, total - used, NULL, NAN);

Could you create pull request for this, so you get correct attribution for providing a fix for it?

See poll request #4141.

#4141 has been merged. Thanks @VikingExpat!