# Logstash Index problem after logrotate

**URL:** https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463
**Category:** Logstash
**Created:** [November 20, 2017, 9:20pm UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463 "2017-11-20T21:20:09Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Vafa\_Ronaghi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vafa_ronaghi/32/43519_2.png) [@Vafa\_Ronaghi](https://discuss.elastic.co/u/Vafa_Ronaghi)
#### Post date: [November 20, 2017, 9:20pm UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/1 "2017-11-20T21:20:09Z")

</div>

Logstash is having problem to read log files after log rotation and send it to Elasticsearch.  
This issue occures when a log file with only one line of log is getting rotated and the new log file also has only one line.

Is there anything i can do? any Idea ?

Thanks  
Vafa

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [November 21, 2017, 6:31am UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/2 "2017-11-21T06:31:18Z")

</div>

What does your configuration look like? How are the files rotated (truncated or renamed)?

---

<div class="post-metadata">

### Author: ![Vafa\_Ronaghi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vafa_ronaghi/32/43519_2.png) [@Vafa\_Ronaghi](https://discuss.elastic.co/u/Vafa_Ronaghi)
#### Post date: [November 21, 2017, 1:19pm UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/3 "2017-11-21T13:19:14Z")

</div>

Hi Magnus,  
Files are truncatated (gziped)  
After log rotation, only one line is written into the file.

My problem is , that that single line is not read by logstash.

can start\_position be a problem ?

## Below is logstash pipeline config

```
input {
  file {
    path => "/logs/wpdirect/wpdirect/server1/wpdirectabnahmetest/1/wpdirect_order.log"
    type => "wpdirect"
    start_position => "end"
    codec => multiline {
                   pattern => "^20"
                   negate => true
                   what => previous
    }
  }
}

filter {
  if [type] =~ /^wpdirect$/ {
        grok {
                match => { "path" => "/logs/wpdirect/wpdirect/dwp(wpd|tuv|tus|tuh|)app(?<stage>[^/?0?]+)" }
        }
        mutate {
                add_field => { "customer" => "dwpbank" }
                add_field => { "app" => "wpdir" }
                convert => { "logtype" => "string" }
                convert => { "loglevel" => "string" }
                convert => { "path" => "string" }
                convert => { "stage" => "string" }
                convert => { "user" => "string" }
                convert => { "path" => "string" }
    }
  }
  grok {
      match => { "path" => "/logs/wpdirect/wpdirect/(?<host>[^/]+)/" }
  }
  if ("wpdirect_order.log" in [path]) {
     mutate {
        convert => { "thread" => "string" }
        convert => { "integration" => "string" }
        convert => { "class" => "string" }
        convert => { "orderid" => "integer" }
    }
    grok {
        patterns_dir => ["/usr/share/logstash/patterns"]
        match => { "message" => "^%{TIMESTAMP_ISO8601:timestamp};%{LOGLEVEL:loglevel}(.*);%{OPTIONALUSERNAME:user};%{TNR:tnr};%{INTEGRATION:integration};%{THREAD:thread};%{CLASS:class};%{CLASS:irgendwas};%{NUMBER:orderid:int}$" }
        add_field => ["logtype", "wpdirect_order"]
    }
  }
  date {
    match => ["timestamp", "yyyy-MM-dd HH:mm:ss,SSS", "yyyy-MM-d HH:mm:ss,SSS"]
  }
  
  }
  
  output {
    redis {
      id => "output_redis"
      data_type => "list"
      host => ["REDIS-SERVER:6379"]
      key => "logstash"
    }
    stdout { codec => json }
  }
```

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [November 21, 2017, 1:32pm UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/4 "2017-11-21T13:32:59Z")

</div>

Yes, try using `start_position => "beginning"` instead.

---

<div class="post-metadata">

### Author: ![Vafa\_Ronaghi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vafa_ronaghi/32/43519_2.png) [@Vafa\_Ronaghi](https://discuss.elastic.co/u/Vafa_Ronaghi)
#### Post date: [November 21, 2017, 3:08pm UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/5 "2017-11-21T15:08:34Z")

</div>

Thanks Magnus, It works now.

---

<div class="post-metadata">

### Author: ![Vafa\_Ronaghi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vafa_ronaghi/32/43519_2.png) [@Vafa\_Ronaghi](https://discuss.elastic.co/u/Vafa_Ronaghi)
#### Post date: [November 22, 2017, 8:38am UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/6 "2017-11-22T08:38:31Z")

</div>

Hi Magnus

I found another problem after changing start\_position to beginning.

It seems that Logstash loses position of last read offset when ever we have to restart the instance.

Is this a normal behavior or it is a bug ?

Thanks  
Vafa

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [November 22, 2017, 8:57am UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/7 "2017-11-22T08:57:50Z")

</div>

That's not normal behavior. Increasing the log level will make Logstash emit more messages related to sincedb and you can e.g. verify whether Logstash saves the correct offset upon shutdown.

---

<div class="post-metadata">

### Author: ![Vafa\_Ronaghi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vafa_ronaghi/32/43519_2.png) [@Vafa\_Ronaghi](https://discuss.elastic.co/u/Vafa_Ronaghi)
#### Post date: [November 22, 2017, 9:13am UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/8 "2017-11-22T09:13:40Z")

</div>

I am not using sincedb in this configuration, because due to this help page , sincedb will be created in home dir of the user rungs logstash.

[https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html#\_tracking\_of\_current\_position\_in\_watched\_files](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html#_tracking_of_current_position_in_watched_files)

I can't find any sincedb file.

What shall i do, shall i create a sincedb\_path for each file inside inplut plugin ?

Thanks in advance for your support.

Regards  
Vafa

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [November 22, 2017, 9:15am UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/9 "2017-11-22T09:15:48Z")

</div>

Well, if you disable sincedb then Logstash will of course start from the beginning each time. If the default sincedb location isn't suitable (and overriding the HOME variable for Logstash isn't an option) you'll have to set `sincedb_path` for each file input.

---

<div class="post-metadata">

### Author: ![Vafa\_Ronaghi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vafa_ronaghi/32/43519_2.png) [@Vafa\_Ronaghi](https://discuss.elastic.co/u/Vafa_Ronaghi)
#### Post date: [November 22, 2017, 11:13am UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/10 "2017-11-22T11:13:23Z")

</div>

Ok, this means i should use a sincedb for every file  
path=\> "file1"  
sincedb\_path =\> "sincedb\_file1"

Shall i still use start\_position =\> "beginning" ?

* * *

I ask beause now everytime make a config change and restart logstash, it start to read files from beginning

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [November 22, 2017, 11:19am UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/11 "2017-11-22T11:19:07Z")

</div>

> Ok, this means i should use a sincedb for every file  
> path=\> "file1"  
> sincedb\_path =\> "sincedb\_file1"

Yes.

> Shall i still use start\_position =\> "beginning" ?

Yes.

---

<div class="post-metadata">

### Author: ![Vafa\_Ronaghi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vafa_ronaghi/32/43519_2.png) [@Vafa\_Ronaghi](https://discuss.elastic.co/u/Vafa_Ronaghi)
#### Post date: [November 25, 2017, 10:19pm UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/12 "2017-11-25T22:19:37Z")

</div>

Thanks Magnus,  
I did this but I still have the problem after logrotate , when the file is only having one line of log.

This application most of the time writes only one sigle lineto the file after every logrotate.  
Logs are looking like this:

`2017-11-25 02:00:01,022;INFO ;NA;NA;;[Timer-0];AdminFacade;Logging started`

After log rotate this single line of log is not read by Logstash and also not indexed.

**But if we write a second line of log , than it will be read by Logstash and indexed by ES.**

Any Idea ?

Thanks in advance

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [November 26, 2017, 7:58pm UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/13 "2017-11-26T19:58:26Z")

</div>

How are the files being rotated? What's the logrotate configuration?

---

<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: [December 24, 2017, 7:58pm UTC](https://discuss.elastic.co/t/logstash-index-problem-after-logrotate/108463/14 "2017-12-24T19:58:31Z")

</div>

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