# Grok gives an error, causing cpu to be high

**URL:** https://discuss.elastic.co/t/grok-gives-an-error-causing-cpu-to-be-high/170465
**Category:** Logstash
**Created:** [March 1, 2019, 9:29am UTC](https://discuss.elastic.co/t/grok-gives-an-error-causing-cpu-to-be-high/170465 "2019-03-01T09:29:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![shenshensinian](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@shenshensinian](https://discuss.elastic.co/u/shenshensinian)
#### Post date: [March 1, 2019, 9:29am UTC](https://discuss.elastic.co/t/grok-gives-an-error-causing-cpu-to-be-high/170465/1 "2019-03-01T09:29:18Z")

</div>

Hello, I don't know why I set the matching specifications, logstash keeps getting error log and cpu usage rate rises rapidly.

The error log is as follows:  
[WARN][logstash.filters.grok] Timeout executing grok '(._?)"%{GREEDYDATA:timestamp}" fw=%{HOSTNAME:HostName}(._?)user=%{USERNAME:UserName}(._?)%{IP:SourceAddress} op="%{USERNAME:UserLogging}"(._?)user login(.\*?)' against field 'message' with value 'Value too large to output (534 bytes)! First 255 chars are:

A single sample log message is as follows:  
id=tos time="2008-5-14 06:53:10" fw=TopsecOS pri=6 type=ips recorder=IPSAR proto=tcp src=192.168.3.2 sport=80 dst=192.168.2.2 dport=69000 rule= repeat= msg= appendix= application="qq" op="block" interface= sdev=eth10 ddev=eth11  
id=tos time="2008-5-14 06:53:10" fw=TopsecOS pri=6 type=ips recorder=IPSAR proto=tcp src=192.168.3.2 sport=80 dst=192.168.2.2 dport=69000 rule= repeat= msg= appendix= application="qq" op="block" interface= sdev=eth10 ddev=eth11  
id=tos time="2008-5-14 06:53:10" fw=TopsecOS pri=6 type=ips recorder=IPSAR proto=tcp src=192.168.3.2 sport=80 dst=192.168.2.2 dport=69000 rule= repeat= msg= appendix= application="qq" op="block" interface= sdev=eth10 ddev=eth11  
id=tos time="2008-5-14 06:53:10" fw=TopsecOS pri=6 type=ips recorder=IPSAR proto=tcp src=192.168.3.2 sport=80 dst=192.168.2.2 dport=69000 rule= repeat= msg= appendix= application="qq" op="block" interface= sdev=eth10 ddev=eth11

---

<div class="post-metadata">

### Author: ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)
#### Post date: [March 1, 2019, 10:01am UTC](https://discuss.elastic.co/t/grok-gives-an-error-causing-cpu-to-be-high/170465/2 "2019-03-01T10:01:47Z")

</div>

> [@shenshensinian](#):
>
> (. _?)"%{GREEDYDATA:timestamp}" fw=%{HOSTNAME:HostName}(._ ?)user=%{USERNAME:UserName}(. _?)%{IP:SourceAddress} op="%{USERNAME:UserLogging}"(._ ?)user login(.\*?)

are you sure your using correct grok pattern and let me know what value you need to extract

---

<div class="post-metadata">

### Author: ![shenshensinian](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@shenshensinian](https://discuss.elastic.co/u/shenshensinian)
#### Post date: [March 1, 2019, 10:18am UTC](https://discuss.elastic.co/t/grok-gives-an-error-causing-cpu-to-be-high/170465/3 "2019-03-01T10:18:58Z")

</div>

There is also no prompt problem with the grok online matching test. What do you mean by the value?

---

<div class="post-metadata">

### Author: ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)
#### Post date: [March 1, 2019, 10:21am UTC](https://discuss.elastic.co/t/grok-gives-an-error-causing-cpu-to-be-high/170465/4 "2019-03-01T10:21:20Z")

</div>

which message your try to extract with this pattern

---

<div class="post-metadata">

### Author: ![shenshensinian](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@shenshensinian](https://discuss.elastic.co/u/shenshensinian)
#### Post date: [March 1, 2019, 10:27am UTC](https://discuss.elastic.co/t/grok-gives-an-error-causing-cpu-to-be-high/170465/5 "2019-03-01T10:27:31Z")

</div>

Still keep reporting errors, can you help me write a change and let me test it?

---

<div class="post-metadata">

### Author: ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)
#### Post date: [March 1, 2019, 10:45am UTC](https://discuss.elastic.co/t/grok-gives-an-error-causing-cpu-to-be-high/170465/6 "2019-03-01T10:45:46Z")

</div>

can you share your logstash config file

---

<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: [March 1, 2019, 1:02pm UTC](https://discuss.elastic.co/t/grok-gives-an-error-causing-cpu-to-be-high/170465/7 "2019-03-01T13:02:53Z")

</div>

Patterns that start with GREEDYDATA are very expensive because they have to backtrack and retry so much. This can result in timeouts.

Why not use

```
kv { whitespace => "strict" }

```

which will parse the first line as

```
   "sequence" => 0,
        "pri" => "6",
        "dst" => "192.168.2.2",
      "proto" => "tcp",
      "sport" => "80",
      "dport" => "69000",
"application" => "qq",
         "op" => "block",
       "ddev" => "eth11",
       "time" => "2008-5-14 06:53:10",
       "type" => "ips",
         "fw" => "TopsecOS",
   "recorder" => "IPSAR",
       "sdev" => "eth10",
         "id" => "tos",
        "src" => "192.168.3.2"

```

Empty fields such as rule, repeat, msg and appendix are discarded.

---

<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: [March 29, 2019, 1:02pm UTC](https://discuss.elastic.co/t/grok-gives-an-error-causing-cpu-to-be-high/170465/8 "2019-03-29T13:02:54Z")

</div>

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