# Metrics do nothing in my file

**URL:** <https://discuss.elastic.co/t/metrics-do-nothing-in-my-file/335700>\
**Category:** Logstash\
**Created:** [June 10, 2023, 9:47pm UTC](https://discuss.elastic.co/t/metrics-do-nothing-in-my-file/335700 "2023-06-10T21:47:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![javierelastic](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@javierelastic](https://discuss.elastic.co/u/javierelastic)\
**Post date:** [June 10, 2023, 9:47pm UTC](https://discuss.elastic.co/t/metrics-do-nothing-in-my-file/335700/1 "2023-06-10T21:47:34Z")

</div>

I am trying to count the number of logs that appear in my file. Now I am using a file with logs as an example, but later I will use a syslog, and I want it to count the logs that arrive in 2 minutes.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/4/84234edcfa29b783cc911dc04cfb889a61f595d0.png)

```auto
if [msgFinal] =~ /(?i:IPS Prevention Alert)/{
metrics {
			meter => ["logs_count"]			
			flush_interval => 120
			clear_interval => 120
			add_tag => ["ATTACK"]
		}
}

```

But it seems that metrics does not count anything or add the tag to me.  
When I try to print an output, nothing appears.

```auto
output{
	if "ATTACK" in [tags]{
		stdout{
			codec => line{
				format => "hay: %{[logs_count][count]}"
			}
		}
}}

```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [June 11, 2023, 1:21am UTC](https://discuss.elastic.co/t/metrics-do-nothing-in-my-file/335700/2 "2023-06-11T01:21:45Z")

</div>

Are you waiting two minutes for the metric to be generated? I suggest you reduce the intervals to maybe 2 seconds and switch to a stdin input. Then paste messages in slowly.

The metrics filter does not modify any of the events that pass through the filter. Every 5 seconds it checks to see whether it is time to generate a new event that contains the values of the counters, and then checks to see if it is time to clear the counters. It will then process the add\_tag option and apply it to the newly generated event.

If try the experiment I suggested in the first paragraph that may make it clearer what the filter is doing.

---

<div class="post-metadata">

**Author:** ![javierelastic](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@javierelastic](https://discuss.elastic.co/u/javierelastic)\
**Post date:** [June 11, 2023, 10:35am UTC](https://discuss.elastic.co/t/metrics-do-nothing-in-my-file/335700/3 "2023-06-11T10:35:19Z")

</div>

Thanks so much! you're right. I have to wait 2 minutes for the result to be printed on the screen.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/0/5056773d329fdde59a3980faa3efb64668e789b0.png)  
Now I have to check if that wait can be a problem when the logs are arriving continuously. My idea is to check if 50 logs of a specific type arrive in 2 minutes, but I have to check it over and over and over again.

---

<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 9, 2023, 10:35am UTC](https://discuss.elastic.co/t/metrics-do-nothing-in-my-file/335700/4 "2023-07-09T10:35:22Z")

</div>

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