# Statsd - send metric only if exists

**URL:** <https://discuss.elastic.co/t/statsd-send-metric-only-if-exists/24072>\
**Category:** Logstash\
**Created:** [June 22, 2015, 10:44am UTC](https://discuss.elastic.co/t/statsd-send-metric-only-if-exists/24072 "2015-06-22T10:44:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matejzero](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@matejzero](https://discuss.elastic.co/u/matejzero)\
**Post date:** [June 22, 2015, 10:44am UTC](https://discuss.elastic.co/t/statsd-send-metric-only-if-exists/24072/1 "2015-06-22T10:44:43Z")

</div>

Hello!

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]}",  
"amavis.timeelapsed.total", "%{[elapsed][Total]}" ]  
namespace =\> 'servers'  
host =\> '1.2.3.4'  
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?

Matej

---

<div class="post-metadata">

**Author:** ![eperry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eperry/32/551_2.png) [@eperry](https://discuss.elastic.co/u/eperry)\
**Post date:** [June 22, 2015, 12:50pm UTC](https://discuss.elastic.co/t/statsd-send-metric-only-if-exists/24072/2 "2015-06-22T12:50:12Z")

</div>

Wrap it in a IF statement

```auto
if ![somefield] {
   do something 
else 
   do something else
}

```

---

<div class="post-metadata">

**Author:** ![matejzero](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@matejzero](https://discuss.elastic.co/u/matejzero)\
**Post date:** [June 22, 2015, 5:56pm UTC](https://discuss.elastic.co/t/statsd-send-metric-only-if-exists/24072/3 "2015-06-22T17:56:08Z")

</div>

Hum...

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.

Matej

---

<div class="post-metadata">

**Author:** ![Censored](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/censored/32/3854_2.png) [@Censored](https://discuss.elastic.co/u/Censored)\
**Post date:** [July 25, 2015, 12:42am UTC](https://discuss.elastic.co/t/statsd-send-metric-only-if-exists/24072/4 "2015-07-25T00:42:56Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 5:33am UTC](https://discuss.elastic.co/t/statsd-send-metric-only-if-exists/24072/5 "2017-07-06T05:33:49Z")

</div>

Closed on July 6, 2017, 5:33am UTC


