commit d26570536428ad8e160ba52d5ef8a53a0395a725 Author: Pim Kunis Date: Wed Aug 9 21:06:25 2023 +0200 init diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..2c2edf5 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,10 @@ +[defaults] +roles_path=~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:roles +inventory=inventory +# vault_password_file=util/secret-service-client.sh +interpreter_python=/usr/bin/python3 +host_key_checking = False +remote_user = root + +[diff] +always = True diff --git a/fluentbit.yml b/fluentbit.yml new file mode 100644 index 0000000..d6acea2 --- /dev/null +++ b/fluentbit.yml @@ -0,0 +1,4 @@ +- name: Install fluentbit + hosts: hypervisors + roles: + - {role: fluentbit, tags: fluentbit} diff --git a/inventory/hosts.yml b/inventory/hosts.yml new file mode 100644 index 0000000..28e93c4 --- /dev/null +++ b/inventory/hosts.yml @@ -0,0 +1,10 @@ +all: + children: + hypervisors: + hosts: + atlas: + ansible_host: atlas.hyp + jefke: + ansible_host: jefke.hyp + lewis: + ansible_host: lewis.hyp diff --git a/roles/fluentbit/fluent-bit.conf.j2 b/roles/fluentbit/fluent-bit.conf.j2 new file mode 100644 index 0000000..83bfa71 --- /dev/null +++ b/roles/fluentbit/fluent-bit.conf.j2 @@ -0,0 +1,119 @@ +# 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 + +[INPUT] + Name exec + Tag memory + Command free -m | tail -2 | tr '\n' ' ' + Interval_Sec 1 + +[OUTPUT] + Name forward + Match * + Host maestro.dmz + Port {{ fluent_forward_port }} + +[FILTER] + Name parser + Match memory + Key_Name exec + Parser free + +[FILTER] + Name record_modifier + Match * + Record hostname ${HOSTNAME} + +[FILTER] + Name record_modifier + Match cpu + Allowlist_key hostname + Allowlist_key cpu_p diff --git a/roles/fluentbit/handlers/main.yml b/roles/fluentbit/handlers/main.yml new file mode 100644 index 0000000..eb43e6e --- /dev/null +++ b/roles/fluentbit/handlers/main.yml @@ -0,0 +1,4 @@ +- name: restart fluent-bit + systemd: + name: fluent-bit + state: restarted diff --git a/roles/fluentbit/parsers.conf.j2 b/roles/fluentbit/parsers.conf.j2 new file mode 100644 index 0000000..86c51ae --- /dev/null +++ b/roles/fluentbit/parsers.conf.j2 @@ -0,0 +1,6 @@ +# vi: ft=conf +[PARSER] + Name free + Format regex + Regex ^Mem:\s+(?\d+)\s+(?\d+)\s+(?\d+)\s+(?\d+)\s+(?\d+)\s+(?\d+) Swap:\s+(?\d+)\s+(?\d+)\s+(?\d+) + Types mem_total:integer mem_used:integer mem_free:integer mem_shared:integer mem_buff_cache:integer mem_available:integer swap_total:integer swap_used:integer diff --git a/roles/fluentbit/tasks/main.yml b/roles/fluentbit/tasks/main.yml new file mode 100644 index 0000000..389526d --- /dev/null +++ b/roles/fluentbit/tasks/main.yml @@ -0,0 +1,26 @@ +- 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 + +- name: Copy fluent-bit parsers configuration + template: + src: "{{ role_path }}/parsers.conf.j2" + dest: /etc/fluent-bit/parsers.conf + notify: restart fluent-bit diff --git a/roles/fluentbit/vars/main.yml b/roles/fluentbit/vars/main.yml new file mode 100644 index 0000000..51b2cb3 --- /dev/null +++ b/roles/fluentbit/vars/main.yml @@ -0,0 +1 @@ +fluent_forward_port: 24224