# \[Logstash\] multiline codecで処理したファイルを削除した際のエラーについて

**URL:** <https://discuss.elastic.co/t/logstash-multiline-codec/154815>\
**Category:** 日本語による質問・議論はこちら\
**Created:** [October 31, 2018, 10:53am UTC](https://discuss.elastic.co/t/logstash-multiline-codec/154815 "2018-10-31T10:53:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![drifting\_school](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@drifting\_school](https://discuss.elastic.co/u/drifting_school)\
**Post date:** [October 31, 2018, 10:53am UTC](https://discuss.elastic.co/t/logstash-multiline-codec/154815/1 "2018-10-31T10:53:41Z")

</div>

■環境

- Windows10 Pro 64bit
- メモリ : 64GB
- logstash-6.4.2

特定のフォルダにxmlファイルがコピーされたことをトリガーに内容をフィルタリングし  
elasticsearchへ送信するパイプラインの実装を進めています。

input, filter, outputの実装が完了しテストを繰り返しているのですが  
logstashのagent起動中に終端(eof)まで読み終わったxmlファイルを削除すると  
下記のようなエラーが繰り返し出力されます。（パスなど一部修正しています）

> [2018-10-31T19:17:06,800][ERROR][filewatch.tailmode.processor] Ignored - other error \<xmlファイルパス\>: (No such process - \<xmlファイルパス\>, ["org/jruby/RubyFile.java:938:in `stat'", "<logstashインストールパス>/vendor/bundle/jruby/2.3.0/gems/logstash-input-file-4.1.6/lib/filewatch/stat/windows_path.rb:19:in `restat'", "\<logstashインストールパス\>/vendor/bundle/jruby/2.3.0/gems/logstash-input-file-4.1.6/lib/filewatch/watched\_file.rb:110:in `restat'", "<logstashインストールパス>/vendor/bundle/jruby/2.3.0/gems/logstash-input-file-4.1.6/lib/filewatch/tail_mode/processor.rb:271:in `common\_restat'", "\<logstashインストールパス\>/vendor/bundle/jruby/2.3.0/gems/logstash-input-file-4.1.6/lib/filewatch/tail\_mode/processor.rb:261:in `common_restat_with_delay'", "<logstashインストールパス>/vendor/bundle/jruby/2.3.0/gems/logstash-input-file-4.1.6/lib/filewatch/tail_mode/processor.rb:117:in `block in process\_ignored'", "org/jruby/RubyArray.java:1734:in `each'", "<logstashインストールパス>/vendor/bundle/jruby/2.3.0/gems/logstash-input-file-4.1.6/lib/filewatch/tail_mode/processor.rb:116:in `process\_ignored'"])

このエラーは multiline codec を使用しない通常のinput-fileでの処理では発生しないので  
おそらくmultiline codecによる監視が外れないことが原因と考えています。

フォルダに蓄積されたxmlファイルから古い順に定期削除することを想定しており  
このエラーを回避できないかと調査しましたが解決に至りませんでした。

一度終端(eof)まで読み込んだxmlファイルを削除してもエラーが発生しないために  
必要な confの記述方法があれば情報をお願いします。

以下一部抜粋となりますが実装したconfファイルの内容です。

```
input {
	file {
		path => "<任意のパス>/**/*.xml"
		start_position => "beginning"
		close_older => 1
		codec => multiline {
			pattern => "^<\?Sample .*\>"
			negate => true
			what => "previous"
		}
	}
}
filter {
	xml {
		...
	}
}
output {
    elasticsearch {
    hosts => [<ホストURL>]
		index => "sample_index"
	}
}

```

よろしくお願いします。

---

<div class="post-metadata">

**Author:** ![drifting\_school](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@drifting\_school](https://discuss.elastic.co/u/drifting_school)\
**Post date:** [November 1, 2018, 1:12am UTC](https://discuss.elastic.co/t/logstash-multiline-codec/154815/2 "2018-11-01T01:12:19Z")

</div>

こちらの実現したい要点を追記させていただきます。

- 特定のフォルダに配置されたxmlファイルを対象とする
- xmlファイルは完成されたものが複数のPCから不定期にコピーされる（後に追記などは行われない）
- logstashはxmlをパースした内容をelasticsearchへ送信
- 蓄積されたxmlファイルは週単位/月単位で古いものからメンテナンスワークフローにて削除される
- xmlファイルは別用途でも利用されるため file\_completed\_action =\> delete は使用不可能

mode =\> read を利用することでこの問題が発生しないことも確認できています。  
その場合 file\_completed\_action が動作することになりますがログファイルを残す必要もなく(ログの肥大化メンテのコストを掛けたくない)  
前述したとおり delete も指定することができません。  
今後 file\_completed\_action が何もしなくなるような設定が可能になれば採用したいとは考えています。

以上です。

---

<div class="post-metadata">

**Author:** ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)\
**Post date:** [November 12, 2018, 3:01pm UTC](https://discuss.elastic.co/t/logstash-multiline-codec/154815/3 "2018-11-12T15:01:24Z")

</div>

[https://www.elastic.co/guide/en/logstash/current/plugins-codecs-multiline.html#plugins-codecs-multiline-auto\_flush\_interval](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-multiline.html#plugins-codecs-multiline-auto_flush_interval)

これを設定してみるとどうでしょうか？

もしくは、`what`を`next`にしてSampleという終了タグがこない間という条件にするのはどうでしょう？

---

<div class="post-metadata">

**Author:** ![drifting\_school](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@drifting\_school](https://discuss.elastic.co/u/drifting_school)\
**Post date:** [November 13, 2018, 8:59am UTC](https://discuss.elastic.co/t/logstash-multiline-codec/154815/4 "2018-11-13T08:59:35Z")

</div>

auto\_flush\_intervalの存在を失念していました。  
変更して検証を進めてみます。

ありがとうございました。

---

<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 11, 2018, 8:59am UTC](https://discuss.elastic.co/t/logstash-multiline-codec/154815/5 "2018-12-11T08:59:39Z")

</div>

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