Send multiple logs from filebeat to logstash in a timely manner - elasticsearch

I have a server where all logs are present in a directory.
Now these files are separated by date. How can I setup filebeat such that all log files from these are sent to kibana (and how to configure this) on other server to receive logs in the same timely manner in a single file.
For example: in server A: I have 40 log files for last 40 days of log
I want these 40 logs in a timely manner, from oldest to newest in a single file in other server.
And also the file with today's date will be updating with new logs.
I have configured filebeat and logstash such that sync is being maintained, but the logs are not in timely manner because of which I'm facing problem in processing it by some of my logic.
glob pattern
/directory to logs/*.log

If you are asking how to remotely sync a set of log files to a single file in time sorted order using filebeat and logstash then...
If you set the harvester_limit to 1, so that only one file is processed at a time, then I think you can use scan.order and scan.sort to get filebeat to send the data in the right order. logstash is more of a problem. In the current version you can disable the java execution engine ('pipeline.java_execution: false' in logstash.yml) and set '--pipeline.workers 1', in which case logstash will preserve order.
In future releases I do not forsee elastic maintaining two execution engines, so once the ruby execution engine is retired it will not be possible to prevent events being re-ordered in the pipeline (the java engine routinely re-orders events in the pipeline in reproducible but unpredicatable ways).

Related

ELK (Elasticsearch, Logstash, Kibana) stack - Do I really need both Logstash and Filebeat configured?

I would like to deploy ELK stack on-premise for our custom application. So, I referred to the official docs for installation guides, installed Elasticsearch cluster and Kibana. Then comes the question: the documentation says I can process the logs from any custom app if I would like to (if built-in modules are not suitable for me), and I should just configure Filebeat so it can harvest these logs as an input. But what should be an output for Filebeat? I've heard that Elasticsearch should get processed, structured logs (for example, in JSON format) as an input; but our application produces plain text logs (as it's Java app, logs can include stack traces and other mixed data), and they should be processed and structured first... Or shouldn't they?
So, here are my questions regarding this situation:
Do I need to set Filebeat output as Logstash input to format and structure logs, and then set Logstash output as Elasticsearch input? Or I can forward logs from Filebeat straight to Elasticsearch?
Do I really need Filebeat in this situation, or maybe Logstash can be configured to read log files by its own?
Filebeat and Logstash can both work either on their own or in concert together. If all you have to do is to tail your log files and send them to Elasticsearch, without performing any processing on them, then I'd say go for Filebeat as it's more lightweight than Logstash.
If you need to perform some processing and transformation on your log files, then you have a few options depending on which solution you pick. You can leverage:
Filebeat processors
Logstash filters
Elasticsearch ingest processors
As a side note, I draw your attention on the fact that your Java app doesn't necessarily have to produce plain text logs. Using ecs-logging-java, it can also produce JSON logs ready to be ingested into Elasticsearch.
If you use the above logging library, then Filebeat would be perfectly suitable for your use case, but it depends of course on whether you need to parse and process the message field in your logs or not.

Difference between using Filebeat and Logstash to push log file to Elasticsearch

I am trying out the ELK to visualise my log file. I have tried different setups:
Logstash file input plugin https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html
Logstash Beats input plugin https://www.elastic.co/guide/en/logstash/current/plugins-inputs-beats.html with Filebeat Logstash output https://www.elastic.co/guide/en/beats/filebeat/current/logstash-output.html
Filebeat Elasticsearch output https://www.elastic.co/guide/en/beats/filebeat/current/elasticsearch-output.html
Can someone list out their differences and when to use which setup? If it is not for here, please point me to the right place like Super User or DevOp or Server Fault.
1) To use logstash file input you need a logstash instance running on the machine from where you want to collect the logs, if the logs are on the same machine that you are already running logstash this is not a problem, but if the logs are on remote machines, a logstash instance is not always recommended because it needs more resources than filebeat.
2 and 3) For collecting logs on remote machines filebeat is recommended since it needs less resources than a logstash instance, you would use the logstash output if you want to parse your logs, add or remove fields or make some enrichment on your data, if you don't need to do anything like that you can use the elasticsearch output and send the data directly to elasticsearch.
This is the main difference, if your logs are on the same machine that you are running logstash, you can use the file input, if you need to collect logs from remote machines, you can use filebeat and send it to logstash if you want to make transformations on your data, or send directly to elasticsearch if you don't need to make transformations on your data.
Another advantage of using filebeat, even on the logstash machine, is that if your logstash instance is down, you won't lose any logs, filebeat will resend the events, using the file input you can lose events in some cases.
An additional point for large scale application is that if you have a lot of Beat (FileBeat, HeartBeat, MetricBeat...) instances, you would not want them altogether open connection and sending data directly to Elasticsearch instance at the same time.
Having too many concurrent indexing connections may result in a high bulk queue, bad responsiveness and timeouts. And for that reason in most cases, the common setup is to have Logstash placed between Beat instances and Elasticsearch to control the indexing.
And for larger scale system, the common setup is having a buffering message queue (Apache Kafka, Rabbit MQ or Redis) between Beats and Logstash for resilency to avoid congestion on Logstash during event spikes.
Figures are captured from Logz.io. They also have a good
article on this topic.
Not really familiar with (2).
But,
Logstash(1) is usually a good choice to take a content play around with it using input/output filters, match it to your analyzers, then send it to Elasticsearch.
Ex.
You point the Logstash to your MySql which takes a row modify the data (maybe do some math on it, then Concat some and cut out some words then send it to ElasticSearch as processed data).
As for Logbeat(2), it's a perfect choice to pick up an already processed data and pass it to elasticsearch.
Logstash (as the name clearly states) is mostly good for log files and stuff like that. usually you can do tiny changes to those.
Ex. I have some log files in my servers (incl errors, syslogs, process logs..)
Logstash listens to those files, automatically picks up new lines added to it and sends those to Elasticsearch.
Then you can filter some things in elasticsearch and find what's important to you.
p.s: logstash has a really good way of load balancing too many data to ES.
You can now use filebeat to send logs to elasticsearch directly or logstash (without a logstash agent, but still need a logstash server of course).
Main advantage is that logstash will allow you to custom parse each line of the logs...whereas filebeat alone will simply send the log and there is not much separation of fields.
Elasticsearch will still index and store the data.

Simple way to analysis log file and display the result

I have a log file. I want to upload the log file and I want to do some query on the log file then I want to display the result. What is the simplest way to do this work? Is it possible to do with only Elastic search and Kibana without using logstash?
You need something to send the log file to elasticsearch, it could be a Logstash instance, Filebeat or a custom application/script.
With Logstash you will have more freedom if you want to parse the message or enrich the data, Filebeat is more limited on these aspects.
On my case I use both Logstash and Filebeat, I have a Logstash machine that receives the data sent by Filebeat agents installed on remote machines.
You need a log forwarder to read your log file and push them into elasticsearch cluster.
Famous log forwarders are,
logstash (which not only read log file and push log lines into elasticseach, but also you can perform intermediate filtering and formatting before you send each log line)
file-beat (a very light weight agent which read log lines from file and push into elasticsearch cannot perform intermediate filtering or formatting)

Elasticsearch - missing data

I have been planning to use ELK for our production environment and seems to be running into a weird problem -
the problem is that while loading a sample of the production log file I realized that there is a huge mismatch in the number of events being published by Filebeat and what we see in kibana. My first doubt was on filebeat but i could verify that all the events were successfully received in logstash.
I also checked logstash (by enabling debug mode ) and could see all the events were received and processed (i am using the following filters date , json ) and i could see them getting processed successfully
but when i do a search in kibana I only get to see the percent of the number of logs being actually published (e.g. only 16000 out of 350K). No exception or error in either logstash or elasticsearch logs.
I have tried zapping the entire data by doing the following so far :
Stopped all processes for ES, Logstash and kibana.
Deleted all the index files, cleared the cache , deleted mappings
stopped filebeat, deleted registry files (since its running in windows)
Restarted elasticsearch, logstash and filebeat (in that order)
but same results. i get only 2 out of 8 records (in the shortened file) and even less when i use the full file
i tried increasing the time windows in kibana to 10 years (:)) to see if they are being pushed to the wrong year but got nothing
I have read almost all threads related to the missing data but nothing seems to work.
any pointers would help !

FileBeat directly to ELS or via LogStash?

We are installing ELS and Kibana for log aggregation/analysis. The first system to use it is greenfield so we output structured logs from the services that make up our system. Given that we don't need to add structure to our logs I was planning on using FileBeat to ship the logs directly to ELS and not use LogStash. Is this a sensible option or does LogStash have value over and above parsing that we might need? If we do use LogStash can I use that to harvest log files or should I still use FileBeat to pump the logs to LogStash?
Logstash is useful if you need to aggregate logs from many servers and apply some common transformations and filtering to your events.
If your log events are already structured and you are ok with indexing them directly, then you can definitely have Filebeat send them directly to ES. If ES goes down (e.g. for maintenance), Filebeat will retry until it can successfully send the events.
Is this a sensible option or does LogStash have value over and above parsing that we might need?
Deciding to use Logstash or not, in your case, depends on whether you need to treat the logs before inserting them into ES.
In addition to parsing (which is apparently useless in your use case), you can use Logstash to add a location with the geoip filter, parse a date with the date filter, replace a word with another, replace a field with a hash, etc...
You can have a look at the available filters here.
If we do use LogStash can I use that to harvest log files or should I still use FileBeat to pump the logs to LogStash?
If you need Logstash and can afford to run it on the machine where your logs are, you can avoid using Filebeat, by using the file input.
But keep in mind that Logstash, especially if used for parsing, can consume a lot of resources. It is better to have it on another machine and use Filebeat to pump the logs to Logstash.

Resources