From d8342c306786daf0ae16540d8320d8a68036d2aa Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Thu, 3 Aug 2023 13:52:54 +0200 Subject: [PATCH] add fluent-bit for physical servers --- ansible/hypervisors.yml | 5 + ansible/roles/fluentbit/fluent-bit.conf.j2 | 107 +++++++++++++++++++++ ansible/roles/fluentbit/handlers/main.yml | 4 + ansible/roles/fluentbit/tasks/main.yml | 20 ++++ ansible/roles/fluentbit/vars/main.yml | 1 + 5 files changed, 137 insertions(+) create mode 100644 ansible/roles/fluentbit/fluent-bit.conf.j2 create mode 100644 ansible/roles/fluentbit/handlers/main.yml create mode 100644 ansible/roles/fluentbit/tasks/main.yml create mode 100644 ansible/roles/fluentbit/vars/main.yml diff --git a/ansible/hypervisors.yml b/ansible/hypervisors.yml index 69d4e38..bb2e9c7 100644 --- a/ansible/hypervisors.yml +++ b/ansible/hypervisors.yml @@ -65,3 +65,8 @@ hosts: lewis roles: - {role: borg, tags: borg} + +- name: Install fluentbit + hosts: hypervisors + roles: + - {role: fluentbit, tags: fluentbit} diff --git a/ansible/roles/fluentbit/fluent-bit.conf.j2 b/ansible/roles/fluentbit/fluent-bit.conf.j2 new file mode 100644 index 0000000..bc68809 --- /dev/null +++ b/ansible/roles/fluentbit/fluent-bit.conf.j2 @@ -0,0 +1,107 @@ +# vi: ft=conf +[SERVICE] + # Flush + # ===== + # set an interval of seconds before to flush records to a destination + flush 1 + + # Daemon + # ====== + # instruct Fluent Bit to run in foreground or background mode. + daemon Off + + # Log_Level + # ========= + # Set the verbosity level of the service, values can be: + # + # - error + # - warning + # - info + # - debug + # - trace + # + # by default 'info' is set, that means it includes 'error' and 'warning'. + log_level info + + # Parsers File + # ============ + # specify an optional 'Parsers' configuration file + parsers_file parsers.conf + + # Plugins File + # ============ + # specify an optional 'Plugins' configuration file to load external plugins. + plugins_file plugins.conf + + # HTTP Server + # =========== + # Enable/Disable the built-in HTTP Server for metrics + http_server Off + http_listen 0.0.0.0 + http_port 2020 + + # Storage + # ======= + # Fluent Bit can use memory and filesystem buffering based mechanisms + # + # - https://docs.fluentbit.io/manual/administration/buffering-and-storage + # + # storage metrics + # --------------- + # publish storage pipeline metrics in '/api/v1/storage'. The metrics are + # exported only if the 'http_server' option is enabled. + # + storage.metrics on + + # storage.path + # ------------ + # absolute file system path to store filesystem data buffers (chunks). + # + # storage.path /tmp/storage + + # storage.sync + # ------------ + # configure the synchronization mode used to store the data into the + # filesystem. It can take the values normal or full. + # + # storage.sync normal + + # storage.checksum + # ---------------- + # enable the data integrity check when writing and reading data from the + # filesystem. The storage layer uses the CRC32 algorithm. + # + # storage.checksum off + + # storage.backlog.mem_limit + # ------------------------- + # if storage.path is set, Fluent Bit will look for data chunks that were + # not delivered and are still in the storage layer, these are called + # backlog data. This option configure a hint of maximum value of memory + # to use when processing these records. + # + # storage.backlog.mem_limit 5M + +[INPUT] + name cpu + tag cpu + + # Read interval (sec) Default: 1 + interval_sec 1 + +[OUTPUT] + name forward + match * + host maestro.dmz + port {{ fluent_forward_port }} + +[FILTER] + Name record_modifier + Match * + Record hostname ${HOSTNAME} + +[FILTER] + Name record_modifier + Match * + Allowlist_key hostname + Allowlist_key cpu_p diff --git a/ansible/roles/fluentbit/handlers/main.yml b/ansible/roles/fluentbit/handlers/main.yml new file mode 100644 index 0000000..eb43e6e --- /dev/null +++ b/ansible/roles/fluentbit/handlers/main.yml @@ -0,0 +1,4 @@ +- name: restart fluent-bit + systemd: + name: fluent-bit + state: restarted diff --git a/ansible/roles/fluentbit/tasks/main.yml b/ansible/roles/fluentbit/tasks/main.yml new file mode 100644 index 0000000..f8d0d56 --- /dev/null +++ b/ansible/roles/fluentbit/tasks/main.yml @@ -0,0 +1,20 @@ +- name: Install APT key + apt_key: + url: https://packages.fluentbit.io/fluentbit.key + state: present + +- name: Install APT repository + apt_repository: + repo: "deb https://packages.fluentbit.io/debian/{{ ansible_distribution_release }} {{ ansible_distribution_release }} main" + state: present + update_cache: true + +- name: Install fluent-bit + apt: + name: fluent-bit + +- name: Copy fluent-bit configuration + template: + src: "{{ role_path }}/fluent-bit.conf.j2" + dest: /etc/fluent-bit/fluent-bit.conf + notify: restart fluent-bit diff --git a/ansible/roles/fluentbit/vars/main.yml b/ansible/roles/fluentbit/vars/main.yml new file mode 100644 index 0000000..51b2cb3 --- /dev/null +++ b/ansible/roles/fluentbit/vars/main.yml @@ -0,0 +1 @@ +fluent_forward_port: 24224