ELK

https://www.notion.so/ELK-2503f149b5074c079d372ec41f8346cb

Installations & Usage

Refer https://elk-docker.readthedocs.io/#installation

1
$ sudo docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -it --name elk sebp/elk

Running the container using Docker Compose

1
2
3
4
5
6
elk:
  image: sebp/elk
  ports:
    - "5601:5601"
    - "9200:9200"
    - "5044:5044"
1
$ sudo docker-compose up elk

Creating a dummy log entry

1
2
3
$ sudo docker exec -it <container-name> /bin/bash
# /opt/logstash/bin/logstash --path.data /tmp/logstash/data \
    -e 'input { stdin { } } output { elasticsearch { hosts => ["localhost"] } }'

http://localhost:9200/_search?pretty&size=1000 You will see:

1
2
3
4
5
6
7
8
9
10
11
12
{
  ...
  "hits": {
    ...
    "hits": [ {
      "_index": "logstash-...",
      "_type": "logs",
      ...
      "_source": { "message": "this is a dummy entry", "@version": "1", "@timestamp": ... }
    } ]
  }
}

Urls or Ports

Logstash

Commands

1
2
3
4
/opt/logstash/bin/logstash --debug
/opt/logstash/bin/logstash -f your-config-file
/opt/logstash/bin/logstash-plugin list

Configurations

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
input {
  http {
    host => "0.0.0.0"
    port => 5044
    type => http
    response_headers => {
      "Access-Control-Allow-Origin" => "*"
      "Content-Type" => "text/plain"
      "Access-Control-Allow-Headers" => "Origin, X-Requested-With, Content-Type,
       Accept"
    }
  }
  tcp {
    host => "0.0.0.0"
    port => 5045
    codec => json_lines
    type => logback
  }
}

filter {
  if [headers][request_method] == "OPTIONS" {
    drop {}
  }
}

output {
  if [type]=="http" and [headers.request_method]!="OPTIONS" {
    elasticsearch {
      hosts => ["127.0.0.1:9200"]
      manage_template => false
      #index => "%{APP_NAME}-%{[@metadata][beat]}-%{+YYYY.MM.dd}"
      index => "http-%{+YYYY.MM.dd}"
    }
  }
  if [type]=="logback" {
    elasticsearch {
      hosts => ["127.0.0.1:9200"]
      manage_template => false
      #index => "%{APP_NAME}-%{[@metadata][beat]}-%{+YYYY.MM.dd}"
      index => "logback-%{APP_NAME}-%{+YYYY.MM.dd}"
    }
  }
}
This post is licensed under CC BY 4.0 by the author.