I'm using Logstash + Elasticsearch + Kibana to have an overview of my Tomcat log files.
For each log entry I need to know the name of the file from which it came. I'd like to add it as a field. Is there a way to do it? I've googled a little and I've only found this SO question, but the answer is no longer up-to-date.
So far the only solution I see is to specify separate configuration for each possible file name with different "add_field" like so:
input { file { type => "catalinalog" path => [ "/path/to/my/files/catalina**" ] add_field => { "server" => "prod1" } } }
But then I need to reconfigure logstash each time there is a new possible file name. Any better ideas?
sincedb_path just needs to be a directory where logstash has write permission for the registry. sincedb_write_interval defines how often logstash should write the sincedb registry. A larger value puts you at risk in logstash were to crash.
Logstash is the “L” in the ELK Stack — the world's most popular log analysis platform and is responsible for aggregating data from different sources, processing it, and sending it down the pipeline, usually to be directly indexed in Elasticsearch.
Hi I added a grok filter to do just this. I only wanted to have the filename not the path, but you can change this to your needs.
filter { grok { match => ["path","%{GREEDYDATA}/%{GREEDYDATA:filename}\.log"] } }
In case you would like to combine the message and file name in one event:
filter { grok { match => { message => "ERROR (?<function>[\S]*)" } } grok { match => { path => "%{GREEDYDATA}/%{GREEDYDATA:filename}\.log" } }}
The result in ElasticSearch (focus on 'filename' and 'function' fields):
"_index": "logstash-2016.08.03", "_type": "logs", "_id": "AVZRyEI49-A6kyBCq6Yt", "_score": 1, "_source": { "message": "27/07/16 12:16:18,321 ERROR blaaaaaaaaa.internal.com", "@version": "1", "@timestamp": "2016-08-03T19:01:33.083Z", "path": "/home/admin/mylog.log", "host": "my-virtual-machine", "function": "blaaaaaaaaa.internal.com", "filename": "mylog" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With