From d71aafe67277e44e8fe47f8be03cdfe5ac9648b8 Mon Sep 17 00:00:00 2001 From: Mikko Hakala Date: Sun, 10 May 2020 14:05:00 +0300 Subject: [PATCH] collectd leaks memory, mitigate by setting systemd-croup memory limit for the service --- defaults/main.yml | 3 +++ handlers/main.yml | 5 +++++ tasks/redhat.yml | 10 ++++++++++ 3 files changed, 18 insertions(+) create mode 100644 handlers/main.yml diff --git a/defaults/main.yml b/defaults/main.yml index f2216c6..0f1cd37 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -26,6 +26,9 @@ collectd_precache: True # Extra rules for collectd prefix mangling collectd_prefix_rules: [] +# default systemd unit memory limit for this service +collectd_memory_limit: "1536M" + # Example: This mimics the old behaviour if you had # collectd_prefix_rules: # - name: generic_prefix diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..04c6e8f --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +--- + +- name: restart_collectd + systemd: name=collectd state=restarted daemon_reload=yes + diff --git a/tasks/redhat.yml b/tasks/redhat.yml index 01ed073..ed340c2 100644 --- a/tasks/redhat.yml +++ b/tasks/redhat.yml @@ -58,6 +58,16 @@ register: collectd_rsyslog_drop when: (collectd_drop_rsyslog_spam and collectd_plugins_exec is defined) or (ansible_virtualization_role != "guest" and collectd_ipmitool|bool) + - name: Add memory-limit via systemd as collectd leaks memory + lineinfile: + path: /usr/lib/systemd/system/collectd.service + regexp: '^MemoryLimit=' + line: "MemoryLimit={{ collectd_memory_limit }}" + insertafter: '^\[Service\]' + firstmatch: yes + state: present + notify: restart_collectd + - name: enable and start collectd service: name=collectd state=started enabled=yes when: ansible_connection != 'chroot'