Skip to content

Commit

Permalink
#5 use env variables for elastic logstash index size and rollover… (#6)
Browse files Browse the repository at this point in the history
* #5 add parameters and fix launch scripts

* #5 add example docker-compose.yml file
  • Loading branch information
metas-jb committed Feb 26, 2020
1 parent ac97aea commit f5e0264
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
3 changes: 3 additions & 0 deletions elk/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ RUN apt update --quiet --assume-yes \
#RUN update-rc.d apm-server defaults

COPY start.sh /usr/local/bin/start.sh
RUN chmod +x /usr/local/bin/start.sh
COPY elastic-post-hooks.sh /usr/local/bin/elastic-post-hooks.sh
RUN chmod +x /usr/local/bin/elastic-post-hooks.sh


# copy logstash config files
COPY 01-tcp-input.conf /etc/logstash/conf.d/01-tcp-input.conf
Expand Down
66 changes: 66 additions & 0 deletions elk/docker-compose.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: '2.4'

services:
elk:
image: metasfresh/elk:latest
restart: always
ports:
- "127.0.0.1:5601:5601" #Kibana web interface
- "172.17.0.1:9200:9200" #Elasticsearch JSON interface - only set for docker-compose v1
- "172.17.0.1:9300:9300" #Elasticsearch transport interface - only set for docker-compose v1
- "172.17.0.1:5000:5000" #Logstash appender - only set for docker-compose v1
volumes:
- ./volumes/elk/elasticsearch:/var/lib/elasticsearch
environment:
- ELK_INDEX_ROLLOVER_SIZE=1G
- ELK_INDEX_ROLLOVER_AGE=30d
- ELK_INDEX_DELETE_AGE=7d
- ELK_ELASTIC_HOSTNAME=localhost
- ELK_ELASTIC_JSON_PORT=9200
networks:
backend:
aliases:
- elk
- elasticsearch
connector:
aliases:
- elk
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9200"]
interval: 10s
timeout: 10s
retries: 3
logging:
options:
max-size: "10m"
max-file: "10"

apm-server:
image: docker.elastic.co/apm/apm-server:7.5.2
restart: always
depends_on:
elk:
condition: service_healthy
ports:
- "172.17.0.1:8200:8200" #apm-server port - only set for docker-compose v1
environment:
- output.elasticsearch.hosts=['http://elasticsearch:9200']
- apm-server.host="0.0.0.0:8200"
- apm-server.secret_token="SUPERSECRETPASSWORDTOKEN"
- setup.kibana.host="elasticsearch:5601"
- setup.template.enabled=true
- logging.to_files=false
networks:
backend:
aliases:
- apm
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8200"]
logging:
options:
max-size: "10m"
max-file: "10"

networks:
backend:
connector:
25 changes: 20 additions & 5 deletions elk/elastic-post-hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,36 @@
# Invoked from start.sh right after elastic started
#

echo "put customized logstash ilm policy"
curl -s -XPUT "http://localhost:9200/_ilm/policy/logstash-policy" -H 'Content-Type: application/json' -d'{

elastic_hostname=${ELK_ELASTIC_HOSTNAME:-localhost}
elastic_json_port=${ELK_ELASTIC_JSON_PORT:-9200}
elastic_protocol=${ELK_ELASTIC_PROTOCOL:-http}

policy_max_size=$(echo ${ELK_INDEX_ROLLOVER_SIZE:-1GB} | tr -d \")
policy_max_age=$(echo ${ELK_INDEX_ROLLOVER_AGE:-30d} | tr -d \")
policy_del_min_age=$(echo ${ELK_INDEX_DELETE_AGE:-7d} | tr -d \")

echo "[INFO] put customized logstash ilm policy"
echo " - ${elastic_protocol}//${elastic_hostname}:${elastic_json_port}"
echo " - ELK_INDEX_ROLLOVER_SIZE: ${policy_max_size}"
echo " - ELK_INDEX_ROLLOVER_AGE: ${policy_max_age}"
echo " - ELK_INDEX_DELETE_AGE: ${policy_del_min_age}"


curl -XPUT "${elastic_protocol}://${elastic_hostname}:${elastic_json_port}/_ilm/policy/logstash-policy" -H 'Content-Type: application/json' -d'{
"policy": {
"phases": {
"hot": {
"min_age": "0ms",
"actions": {
"rollover": {
"max_age": "30d",
"max_size": "1GB"
"max_age": "'"${policy_max_age}"'",
"max_size": "'"${policy_max_size}"'"
}
}
},
"delete": {
"min_age": "7d",
"min_age": "'"${policy_del_min_age}"'",
"actions": {
"delete": {}
}
Expand Down

0 comments on commit f5e0264

Please sign in to comment.