# Getting metrics count of dynamic meter name

**URL:** <https://discuss.elastic.co/t/getting-metrics-count-of-dynamic-meter-name/87986>\
**Category:** Logstash\
**Created:** [June 1, 2017, 8:52pm UTC](https://discuss.elastic.co/t/getting-metrics-count-of-dynamic-meter-name/87986 "2017-06-01T20:52:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kbop543](https://avatars.discourse-cdn.com/v4/letter/k/ecd19e/32.png) [@kbop543](https://discuss.elastic.co/u/kbop543)\
**Post date:** [June 1, 2017, 8:52pm UTC](https://discuss.elastic.co/t/getting-metrics-count-of-dynamic-meter-name/87986/1 "2017-06-01T20:52:03Z")

</div>

Hey,  
So I have been testing how to use metrics to tell me the count of how many times a logfile logged errors.

I use indexes to distinguish between logfiles by grabbing the filename from the path in a field called filename.  
I have tried this in my logstash config file and it works:

metrics {  
meter =\> "events"  
add\_tag =\> "metric"  
}

output {  
elasticsearch {  
hosts =\> "g-elasticsearch:9200"  
manage\_template =\> false  
index =\> "%{filename}"

}  
stdout {codec =\> rubydebug}

if "metric" in [tags] and [events][count] \> 1{  
stdout {  
codec =\> line {  
format =\> "rate: %{[events][count]}"  
}  
}  
}  
}

This will give me the total count of all logs with errors. But I want it per logfile. I have tried various variations of this:

metrics {  
meter =\> "%{filename}"  
add\_tag =\> "metric"  
}

output {  
elasticsearch {  
hosts =\> "g-elasticsearch:9200"  
manage\_template =\> false  
index =\> "%{filename}"

}  
stdout {codec =\> rubydebug}

if "metric" in [tags] and [%{filename}][count] \> 1{  
stdout {  
codec =\> line {  
format =\> "rate: %{[%{filename}][count]}"  
}  
}  
}  
}

this does not work. In /var/log/logstash/.. it says "[2017-06-01T20:48:14,929][FATAL][logstash.runner] An unexpected error occurred! {:error=\>#\<NoMethodError: undefined method `>' for nil:NilClass>, :backtrace=>["(eval):175:in`output\_func'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:400:in `output_batch'", "org/jruby/RubyProc.java:281:in`call'", "/usr/share/logstash/logstash-core/lib/logstash/util/wrapped\_synchronous\_queue.rb:227:in `each'", "org/jruby/RubyHash.java:1342:in`each'", "/usr/share/logstash/logstash-core/lib/logstash/util/wrapped\_synchronous\_queue.rb:226:in `each'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:394:in`output\_batch'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:352:in `worker_loop'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:317:in`start\_workers'"]}"

I know that the syntax is somehow wrong. What is the right syntax? I have tried variations of the above to see which one would work, aka switching around curly braces or quotation marks but nothing seems to work!

Hoping someone can help me,  
Thanks

---

<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:** [June 29, 2017, 8:52pm UTC](https://discuss.elastic.co/t/getting-metrics-count-of-dynamic-meter-name/87986/2 "2017-06-29T20:52:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
