Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/role-logstash.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Role Variables
* *logstash_manage_logging*: Manage log4j configuration (default: `false`)
* *logstash_plugins*: List of plugins to install (default: none)
* *logstash_certs_dir*: Path to certificates. Will be used to build paths of several files. (Default: `/etc/logstash/certs`)
* *logstash_heap*: JVM heap size in GB (default: `1`). Elastic recommends 4-8 GB for typical ingestion and staying below 50-75% of physical memory. Keep it low when Logstash shares a host with Elasticsearch so they do not compete for memory.

If `logstash.yml` is managed, the following settings apply.

Expand Down
2 changes: 2 additions & 0 deletions roles/logstash/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ logstash_config_backup: no
logstash_manage_yaml: true
logstash_manage_logging: false

logstash_heap: "1"

# config items in yaml file #

logstash_config_autoreload: true
Expand Down
35 changes: 35 additions & 0 deletions roles/logstash/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,41 @@
- configuration
- logstash_configuration

- name: Create systemd drop-in directory for Logstash
ansible.builtin.file:
path: /etc/systemd/system/logstash.service.d
state: directory
owner: root
group: root
mode: "0755"
tags:
- configuration
- logstash_configuration

- name: Set Logstash JVM heap size via systemd drop-in
ansible.builtin.template:
src: jvm-heap.conf.j2
dest: /etc/systemd/system/logstash.service.d/heap.conf
owner: root
group: root
mode: "0644"
register: logstash_heap_dropin
notify:
- Restart Logstash
tags:
- configuration
- logstash_configuration

# Reload systemd inline (not via handler) so a fresh install picks up the drop-in before
# "Start Logstash" runs. Handlers only fire at the end of the play, which would be too late.
- name: Reload systemd to apply Logstash heap drop-in
ansible.builtin.systemd:
daemon_reload: true
when: logstash_heap_dropin.changed
tags:
- configuration
- logstash_configuration

- name: Configure Logstash logging
ansible.builtin.template:
src: log4j2.properties.j2
Expand Down
5 changes: 5 additions & 0 deletions roles/logstash/templates/jvm-heap.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Managed by Ansible
# Logstash has no jvm.options.d directory, and /etc/logstash/jvm.options is a package
# config file. So we set the heap via LS_JAVA_OPTS in a systemd drop-in.
[Service]
Environment="LS_JAVA_OPTS=-Xms{{ logstash_heap }}g -Xmx{{ logstash_heap }}g"
Loading