Statsd - send metric only if exists



I'm using logstash to send apache and amavis metrics to statsd. I define all fields that should be sent to statsd but sometimes, some of the fields doesn't exist and I get error on stasd side.

Statsd config:
statsd {
timing => [ "amavis.timeelapsed.amavis", "%{[elapsed][Amavis]}",
"amavis.timeelapsed.decoding", "%{[elapsed][Decoding]}",
"amavis.timeelapsed.receiving", "%{[elapsed][Receiving]}",
"amavis.timeelapsed.sending", "%{[elapsed][Sending]}",
"amavis.timeelapsed.viruscheck", "%{[elapsed][VirusCheck]}",
"amavis.timeelapsed.spamcheck", "%{[elapsed][SpamCheck]}",
"", "%{[elapsed][Total]}" ]
namespace => 'servers'
host => ''
port => '8125'

Sometimes, elapsed.VirusCheck and elapsed.SpamCheck fields doesn't exist. This is when statsd gives me the error:
DEBUG: Bad line: %{[elapsed][Decoding]},ms in msg "servers.amavis.timeelapsed.decoding:%{[elapsed][Decoding]}|ms"
DEBUG: Bad line: %{[elapsed][VirusCheck]},ms in msg "servers.amavis.timeelapsed.viruscheck:%{[elapsed][VirusCheck]}|ms"

How could I force statsd plugin, to not send metrics if the field doesn't exists?


(Ed) #2

Wrap it in a IF statement

if ![somefield] {
   do something 
   do something else



I guess I can put VirusCheck and SpamCheck into another statsd instance and put an if condition in front of it.

I was hoping there is a config option to not send metric if string doesn't exist.


(Stephanie) #4

Were you ever able to create something using ifs/conditional to send data to statsd? I keep running into issues trying to create output without generating tons of errors, such as you. Do you have an example you can share of how you solved this?

Thank you!

(system) #5