GCP Stackdriver Agent: “write_gcm: can not take infinite value” Error

PROBLEM

When running the stackdriver-agent (v6.x), the log file contains the following errors:-

collectd[1496]: write_gcm: can not take infinite value
collectd[1496]: write_gcm: wg_typed_value_create_from_value_t_inline failed for swap/percent/value! Continuing.
collectd[1496]: write_gcm: can not take infinite value
collectd[1496]: write_gcm: wg_typed_value_create_from_value_t_inline failed for swap/percent/value! Continuing.
collectd[1496]: write_gcm: can not take infinite value
collectd[1496]: write_gcm: wg_typed_value_create_from_value_t_inline failed for swap/percent/value! Continuing.

SOLUTION

By default, the swap metric is enabled.

To verify, go to /etc/stackdriver/collectd.conf and locate the following configuration:-

LoadPlugin swap
<Plugin "swap">
  ValuesPercentage true
</Plugin>

This error occurs because the VM instance does not have swap memory, hence this metric plugin tries to divide by 0.

To verify the VM’s swap memory:-

$ free -m
              total        used        free      shared  buff/cache   available
Mem:           3536         191        3197           8         147        3151
Swap:             0           0           0

To fix this, remove this configuration and restart stackdriver-agent.