ELK>> ELK>> 返回
项目作者: lfvilella

项目描述 :
This fork show how to implements ELK stack + filebeat on Docker + docker-compose.
高级语言: Shell
项目地址: git://github.com/lfvilella/ELK.git
创建时间: 2021-05-25T20:35:20Z
项目社区:https://github.com/lfvilella/ELK

开源协议:MIT License

下载


Elastic stack (ELK) + Filebeat on Docker

Project fork from deviantony/docker-elk.

This fork show how to implements ELK stack + filebeat on Docker + docker-compose.

Structure

Screen Shot 2021-05-31 at 09 24 34

About

We have one (or more) application (python for example) what write some logs on application/logs/.log, and the filebeat will read this file and send to logstash that will do regex filter and after also send to elasticsearch and finally we’ll build some graphics on kibana.

App example

This simple python example will write some logs for us.

  1. import os
  2. import uuid
  3. import time
  4. import log
  5. def hello_log():
  6. while True:
  7. log.registry(log.LOGGING_ENUM.INFO, f'Info {uuid.uuid4()}')
  8. log.registry(log.LOGGING_ENUM.WARNING, f'Warning {uuid.uuid4()}')
  9. log.registry(log.LOGGING_ENUM.ERROR, f'Error {uuid.uuid4()}')
  10. time.sleep(15)
  11. if __name__ == '__main__':
  12. if not os.path.exists(os.path.join(os.getcwd(), 'logs', '.log')):
  13. os.mkdir(f'{os.getcwd()}/logs3')
  14. hello_log()

ps: I split the logs in a specific module: log.py

Logs example

  1. 28/05/2021 20:33:19 INFO || 3e860697f14e || my_module || Company Name || Info 2473c107-aff8-4b48-85d6-a7ef6cdf89a6
  2. 28/05/2021 20:33:19 WARNING || 3e860697f14e || my_module || Company Name || Warning 9a2d445a-5859-4f6a-8496-059a04c461d3
  3. 28/05/2021 20:33:19 ERROR || 3e860697f14e || my_module || Company Name || Error d336fe31-86f9-4abe-b0c1-3738f5965351
  4. 28/05/2021 20:33:24 INFO || 3e860697f14e || my_module || Company Name || Info a469d96b-564e-4af9-a874-ef2237ae3e71
  5. 28/05/2021 20:33:24 WARNING || 3e860697f14e || my_module || Company Name || Warning a8a123b3-3379-4000-8c8a-83629a4ecd05
  6. 28/05/2021 20:33:24 ERROR || 3e860697f14e || my_module || Company Name || Error 6e07dbeb-8969-4b95-97df-c1253c934d19
  7. 28/05/2021 20:33:29 INFO || 3e860697f14e || my_module || Company Name || Info 9c6c5e09-2001-48ba-a33a-f2f2729b68a8

Click here to see the regex from this.

Running

  1. $ make build

This step takes a few minutes to start ELK and all services to connect.

See what’s happening

  1. $ docker-compose logs -f # all containers
  2. $ docker-compose logs -f <name> # [app, elasticsearch, logstash, filebeat, kibana]

Kibana

Go to http://localhost:5601/ to access kibana.

Default credentials

  1. username: elastic
  2. password: changeme

Search for index patterns

Screen Shot 2021-05-31 at 10 03 42

Create index patterns

We set the index to my_index_patterns on logstash.conf

image
ps: don’t care about my old tests

image
image
Select timestamp or not and CREATE INDEX PATTERNS

image

Select my_index_patterns and see the logs comming

image

Let’s create one visualization

Go to sidebar > dashboard > Create Dashboard

Screen Shot 2021-05-31 at 10 30 09

Click on Create Panel > Aggregation Based

image

Select bar chart and choose my_index_patterns

image

Let’s create X-axis

image

image

Click to update to see changes

Create Split Series too, and select terms > status.keyword > update > save return

image

Dashboard created 🥳

image
just save to persist

References