Kill logstash when finished parsing

2019-08-01 07:01发布

I'm only outputting my parsed data into a mongodb from logstash, but it there any way to tell when the logs are finished parsing, so that I can kill logstash? As a lot of logs are being processed, I cannot stdout my data.

1条回答
爷、活的狠高调
2楼-- · 2019-08-01 07:41

Since you are using a file input, there should be a .sincedb file somewhere. That file keeps track of how many lines have already been parsed. As far as I understand it, it is structured this way:

INODE_NUMBER              CURRENT_LINE_NUMBER 

The inode number identifies a file (so if you are parsing several files or if your file is being rolled over, there will be several lines). The other number is like a bookmark for logstash to remember what it already read (in case you would proceed the same file in several times). So basically, when this number stops moving up, this should mean that logstash is done parsing the file.

Alternatively if you have no multiline filter set up, you could simply compare the number of lines the file has to the number of records in mongodb.

Third possibility, you can setup another output, not necessarily stdout, this could be for example a pipe to a script that will simply drop the data and print a message when it got nothing new after some time, or some other alternative, see the docs.

查看更多
登录 后发表回答