# Need grok pattern for logstash

**URL:** <https://discuss.elastic.co/t/need-grok-pattern-for-logstash/305835>\
**Category:** Logstash\
**Created:** [May 27, 2022, 9:47pm UTC](https://discuss.elastic.co/t/need-grok-pattern-for-logstash/305835 "2022-05-27T21:47:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaeemmasood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zaeemmasood/32/102383_2.png) [@zaeemmasood](https://discuss.elastic.co/u/zaeemmasood)\
**Post date:** [May 27, 2022, 9:47pm UTC](https://discuss.elastic.co/t/need-grok-pattern-for-logstash/305835/1 "2022-05-27T21:47:52Z")

</div>

Hi All,

I need to use grok filter to parse the following log pattern:

```auto
[2022-05-24T02:15:20.979+0000][info][gc] GC(187) Pause Full (G1 Evacuation Pause) 2559M->1698M(2560M) 724.899ms

```

The idea is to capture the following from the log:

1. Date/Time

2. 2559M-\>1698M showing drop in the heap due to garbage collection

3. 2560M Total heap

4. 724.899ms Time take for GC

I get stumped at the first pattern for date/ timestamp and following does not seem to work when I put in the debugger:

```auto
%{TIMESTAMP_ISO8601:time} 

```

Please guide what filters should I use for the entire log message?

Thanks

---

<div class="post-metadata">

**Author:** ![sudhagar\_ramesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sudhagar_ramesh/32/105673_2.png) [@sudhagar\_ramesh](https://discuss.elastic.co/u/sudhagar_ramesh)\
**Post date:** [May 29, 2022, 5:22am UTC](https://discuss.elastic.co/t/need-grok-pattern-for-logstash/305835/2 "2022-05-29T05:22:31Z")

</div>

Hello @zaeemmasood

Hope this grok pattern would help you

```auto
\[%{TIMESTAMP_ISO8601:date_time}\]\[%{WORD:loglevel}\]\[%{WORD:gc}\s*\]\s+%{GREEDYDATA:message} %{GREEDYDATA:drop_heap}\(%{DATA:total_gc}\) %{GREEDYDATA:time_taken}

```

Attached screenshot for your reference.

 ![grok2](https://us1.discourse-cdn.com/elastic/original/3X/9/e/9e4f3ef175fceb23415447f85b9ff2e57f0df4ad.png)

Keep Posted!!! Thanks 🙂 !!!

---

<div class="post-metadata">

**Author:** ![zaeemmasood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zaeemmasood/32/102383_2.png) [@zaeemmasood](https://discuss.elastic.co/u/zaeemmasood)\
**Post date:** [May 30, 2022, 9:27pm UTC](https://discuss.elastic.co/t/need-grok-pattern-for-logstash/305835/3 "2022-05-30T21:27:43Z")

</div>

Thanks. That solves my issue. I need to display the fields individually in Kibana. This does not seem to work:

```auto
        filter {
                if [type] == "tv_gclog_analysis" {

                        grok {
                                match => { "message" => "\[%{TIMESTAMP_ISO8601:createdTime}\]\[%{WORD:logLevel}\]+%{GREEDYDATA:message} %{GREEDYDATA:heapDrop}\(%{DATA:maxHeap:int}\) %{GREEDYDATA:timeTaken:int}" }
                                        }

                               }
                        }

```

Do I need to somehow split the message as follows:

```auto
        if [type] == "tv_gclog_analysis" {
                
				   filter {
					grok {
						match => { "message" => \[%{TIMESTAMP_ISO8601:createdTime}\]\[%{WORD:logLevel}\]+%{GREEDYDATA:message} %{GREEDYDATA:heapDrop}\(%{DATA:maxHeap:int}\) %{GREEDYDATA:timeTaken:int} }
					}
					
				mutate {
                        split => ["message",]
                        add_field =>{
                           "createdTime" => "%{[message][0]}"
                           "logLevel" => "%{[message][1]}"
                           "message" => "%{[message][2]}"
                           "heapDrop" => "%{[message][3]}"
			               "maxHeap" => "%{[message][4]}"
			               "time_taken" => "%{[message][5]}"

                       }
					}
				}

```

Please guide

---

<div class="post-metadata">

**Author:** ![sudhagar\_ramesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sudhagar_ramesh/32/105673_2.png) [@sudhagar\_ramesh](https://discuss.elastic.co/u/sudhagar_ramesh)\
**Post date:** [May 31, 2022, 1:52am UTC](https://discuss.elastic.co/t/need-grok-pattern-for-logstash/305835/4 "2022-05-31T01:52:44Z")

</div>

Hello @zaeemmasood

this grok pattern should be inside single quotes like the below . if still not working please a raise a new case to assist you further.

```auto
 filter {
					grok {
						match => { "message" => '\[%{TIMESTAMP_ISO8601:createdTime}\]\[%{WORD:logLevel}\]+%{GREEDYDATA:message} %{GREEDYDATA:heapDrop}\(%{DATA:maxHeap:int}\) %{GREEDYDATA:timeTaken:int}' }
					}

```

---

<div class="post-metadata">

**Author:** ![zaeemmasood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zaeemmasood/32/102383_2.png) [@zaeemmasood](https://discuss.elastic.co/u/zaeemmasood)\
**Post date:** [May 31, 2022, 4:03pm UTC](https://discuss.elastic.co/t/need-grok-pattern-for-logstash/305835/5 "2022-05-31T16:03:49Z")

</div>

Thanks for your help!

Please let me know if there is a central place where all the possible grok patterns are mentioned?

---

<div class="post-metadata">

**Author:** ![sudhagar\_ramesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sudhagar_ramesh/32/105673_2.png) [@sudhagar\_ramesh](https://discuss.elastic.co/u/sudhagar_ramesh)\
**Post date:** [June 1, 2022, 2:15am UTC](https://discuss.elastic.co/t/need-grok-pattern-for-logstash/305835/6 "2022-06-01T02:15:21Z")

</div>

Hello @zaeemmasood

In this below elastic article you would find a git repo where it contains mostly all the patterns.

> **[Grok filter plugin | Logstash Reference \[8.2\] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html)**

---

<div class="post-metadata">

**Author:** ![zaeemmasood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zaeemmasood/32/102383_2.png) [@zaeemmasood](https://discuss.elastic.co/u/zaeemmasood)\
**Post date:** [June 1, 2022, 6:09pm UTC](https://discuss.elastic.co/t/need-grok-pattern-for-logstash/305835/7 "2022-06-01T18:09:18Z")

</div>

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, 2022, 6:10pm UTC](https://discuss.elastic.co/t/need-grok-pattern-for-logstash/305835/8 "2022-06-29T18:10:01Z")

</div>

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