awslabs / collectd-cloudwatch

A collectd plugin for sending data to Amazon CloudWatch
MIT License
199 stars 131 forks source link

Handle NaN values by replacing with 0 (zero) to allow publishing to CloudWatch #78

Open seans11 opened 5 years ago

seans11 commented 5 years ago

I am attempting to use the Collectd Tail Plugin for tracking my Postfix log file. I would like to publish Postfix frequency metrics to CloudWatch using the DSType:CountInc/Type:frequency (value:gauge:0:U) settings. I am using the csv plugin to view the output and it appears that Collectd is recording "nan" for the intervals where no metrics are received from the Postfix log file. With CloudWatch you are unable to publish "nan" values. Is there a method or setting I am missing that would allow me to substitute "nan" with "0" in publishing to CloudWatch? During the intervals where nan results occur, CloudWatch metrics do not get recorded resulting in a broken chart.

Plugin tail configuration:

<Plugin "tail">
<File "/var/log/maillog">
    Instance "postfix"
    Interval 60
    #Since 5.8, Collectd supports new options:
    #Plugin "postfix"
    #Instance "main"

    # number of connections
    # (incoming)
    <Match>
      Regex "\\<postfix\\/smtpd\\[[0-9]+\\]: connect from\\>"
      DSType "GaugeInc"
      Type "frequency"
      Instance "connection-in-open"
    </Match>
    <Match>
      Regex "\\<postfix\\/smtpd\\[[0-9]+\\]: disconnect from\\>"
      DSType "GaugeInc"
      Type "frequency"
      Instance "connection-in-close"
    </Match>
</File>
</Plugin>

Output sample of csv plugin for one of the Postfix metrics:

1547744157.415,nan
1547744217.415,nan
1547744277.415,nan
1547744337.415,nan
1547744397.415,nan
1547744457.415,1.000000
1547744517.415,nan
1547744577.415,nan
1547744637.415,nan
1547744697.415,nan
1547744757.415,nan
1547744817.415,nan

Output of what I would like to see:

1547744277.415,0
1547744337.415,0
1547744397.415,0
1547744457.415,1.000000
1547744517.415,0
1547744577.415,0