Add logrotate to the elasticstack
To ensure we're not creating too many logs files the logrotate config has been added to truncate and compress log files every other day with a max retention priod of 5 days. Change-Id: I0dd85a334dba48e9fce3aad67ead867e2f46cb02 Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
parent
82182589f0
commit
62b8c8b45d
@ -25,9 +25,10 @@
|
|||||||
tags:
|
tags:
|
||||||
- always
|
- always
|
||||||
|
|
||||||
- name: Set heap facts
|
- name: Set elasticsearch facts
|
||||||
set_fact:
|
set_fact:
|
||||||
elastic_heap_size: "{{ ((h_mem | int) > 30720) | ternary(30720, h_mem) }}"
|
elastic_heap_size: "{{ ((h_mem | int) > 30720) | ternary(30720, h_mem) }}"
|
||||||
|
elastic_log_rotate_path: "/var/log/elasticsearch"
|
||||||
tags:
|
tags:
|
||||||
- always
|
- always
|
||||||
|
|
||||||
@ -90,9 +91,12 @@
|
|||||||
|
|
||||||
- name: Ensure elasticsearch is installed
|
- name: Ensure elasticsearch is installed
|
||||||
apt:
|
apt:
|
||||||
name: elasticsearch
|
name: "{{ item }}"
|
||||||
state: "{{ elk_package_state | default('present') }}"
|
state: "{{ elk_package_state | default('present') }}"
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
with_items:
|
||||||
|
- logrotate
|
||||||
|
- elasticsearch
|
||||||
register: _apt_task
|
register: _apt_task
|
||||||
until: _apt_task is success
|
until: _apt_task is success
|
||||||
retries: 3
|
retries: 3
|
||||||
@ -163,6 +167,11 @@
|
|||||||
group: "elasticsearch"
|
group: "elasticsearch"
|
||||||
mode: "0750"
|
mode: "0750"
|
||||||
|
|
||||||
|
- name: Create logrotate config
|
||||||
|
template:
|
||||||
|
src: "templates/logrotate.j2"
|
||||||
|
dest: "/etc/logrotate.d/elasticsearch"
|
||||||
|
|
||||||
handlers:
|
handlers:
|
||||||
- name: Enable and restart elastic
|
- name: Enable and restart elastic
|
||||||
systemd:
|
systemd:
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
set_fact:
|
set_fact:
|
||||||
elastic_heap_size: "{{ ((q_mem | int) > 30720) | ternary(30720, q_mem) }}"
|
elastic_heap_size: "{{ ((q_mem | int) > 30720) | ternary(30720, q_mem) }}"
|
||||||
logstash_queue_size: "{{ (((q_storage | int) > 16) | ternary(16, q_storage) | int) * 1024 }}"
|
logstash_queue_size: "{{ (((q_storage | int) > 16) | ternary(16, q_storage) | int) * 1024 }}"
|
||||||
|
elastic_log_rotate_path: "/var/log/logstash"
|
||||||
tags:
|
tags:
|
||||||
- always
|
- always
|
||||||
|
|
||||||
@ -84,9 +85,12 @@
|
|||||||
|
|
||||||
- name: Ensure Logstash is installed
|
- name: Ensure Logstash is installed
|
||||||
apt:
|
apt:
|
||||||
name: logstash
|
name: "{{ item }}"
|
||||||
state: "{{ elk_package_state | default('present') }}"
|
state: "{{ elk_package_state | default('present') }}"
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
with_items:
|
||||||
|
- logrotate
|
||||||
|
- logstash
|
||||||
register: _apt_task
|
register: _apt_task
|
||||||
until: _apt_task is success
|
until: _apt_task is success
|
||||||
retries: 3
|
retries: 3
|
||||||
@ -242,6 +246,11 @@
|
|||||||
group: "logstash"
|
group: "logstash"
|
||||||
mode: "0750"
|
mode: "0750"
|
||||||
|
|
||||||
|
- name: Create logrotate config
|
||||||
|
template:
|
||||||
|
src: "templates/logrotate.j2"
|
||||||
|
dest: "/etc/logrotate.d/logstash"
|
||||||
|
|
||||||
handlers:
|
handlers:
|
||||||
- name: Enable and restart logstash
|
- name: Enable and restart logstash
|
||||||
systemd:
|
systemd:
|
||||||
|
12
elk_metrics_6x/templates/logrotate.j2
Normal file
12
elk_metrics_6x/templates/logrotate.j2
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{{ elastic_log_rotate_path }}/*.log
|
||||||
|
{
|
||||||
|
copytruncate
|
||||||
|
weekly
|
||||||
|
missingok
|
||||||
|
rotate 2
|
||||||
|
compress
|
||||||
|
dateext
|
||||||
|
maxage 5
|
||||||
|
notifempty
|
||||||
|
nocreate
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user