From 15a1bcbe9f8d1cc65fb5e4787e71cc5f89226f84 Mon Sep 17 00:00:00 2001 From: Sheppy Date: Tue, 3 Jan 2023 21:49:28 +0100 Subject: [PATCH] feat: collectd/influx role --- playbook.yaml | 3 +- roles/global-handlers/handlers/main.yml | 10 ++++++ roles/monitoring-influx/meta/main.yml | 2 ++ roles/monitoring-influx/tasks/main.yaml | 31 +++++++++++++++++ .../templates/collectd.conf.j2 | 34 +++++++++++++++++++ .../templates/influxdb.conf.j2 | 29 ++++++++++++++++ 6 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 roles/monitoring-influx/meta/main.yml create mode 100644 roles/monitoring-influx/tasks/main.yaml create mode 100644 roles/monitoring-influx/templates/collectd.conf.j2 create mode 100644 roles/monitoring-influx/templates/influxdb.conf.j2 diff --git a/playbook.yaml b/playbook.yaml index 3a7f5b5..bc20eca 100644 --- a/playbook.yaml +++ b/playbook.yaml @@ -4,7 +4,8 @@ - { role : monitoring-client, tags : [ "monitoring", "monitoring-client", "client"] } - { role : sshd-config, tags : [ "sshd" ] } - { role : rsyslog, tags : [ "rsyslog" ] } + - { role : monitoring-influx, tags : [ "influx" ] } - hosts: monitoring roles: - - monitoring-master + - { role : monitoring-master, tags : [ "monitoring-master" ] } diff --git a/roles/global-handlers/handlers/main.yml b/roles/global-handlers/handlers/main.yml index 973b02c..b55b5fb 100644 --- a/roles/global-handlers/handlers/main.yml +++ b/roles/global-handlers/handlers/main.yml @@ -9,3 +9,13 @@ systemd: name: rsyslog state: restarted + +- name: restart collectd + systemd: + name: collectd + state: restarted + +- name: restart influxdb + systemd: + name: influxdb + state: restarted diff --git a/roles/monitoring-influx/meta/main.yml b/roles/monitoring-influx/meta/main.yml new file mode 100644 index 0000000..c808c92 --- /dev/null +++ b/roles/monitoring-influx/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - global-handlers diff --git a/roles/monitoring-influx/tasks/main.yaml b/roles/monitoring-influx/tasks/main.yaml new file mode 100644 index 0000000..d6e32fb --- /dev/null +++ b/roles/monitoring-influx/tasks/main.yaml @@ -0,0 +1,31 @@ +- name: Install influxdb + apt: + name: influxdb + state: present + when: monitoring_master + +- name: Influxdb master server config + template: + src: influxdb.conf.j2 + dest: /etc/influxdb/influxdb.conf + when: monitoring_master + notify: + - restart influxdb + +- name: Create Influx collectd-db + shell: 'echo "CREATE DATABASE collectd;" | influx' + changed_when: False + when: monitoring_master + +- name: Install collectd + apt: + name: collectd + install_recommends: false + state: present + +- name: Collectd config + template: + src: collectd.conf.j2 + dest: /etc/collectd/collectd.conf + notify: + - restart collectd diff --git a/roles/monitoring-influx/templates/collectd.conf.j2 b/roles/monitoring-influx/templates/collectd.conf.j2 new file mode 100644 index 0000000..5df4889 --- /dev/null +++ b/roles/monitoring-influx/templates/collectd.conf.j2 @@ -0,0 +1,34 @@ +FQDNLookup true +LoadPlugin cpu +LoadPlugin df +LoadPlugin disk +LoadPlugin entropy +LoadPlugin interface +LoadPlugin irq +LoadPlugin load +LoadPlugin memory +LoadPlugin network +LoadPlugin processes +LoadPlugin swap +LoadPlugin users +LoadPlugin rrdtool + + FSType rootfs + FSType sysfs + FSType proc + FSType devtmpfs + FSType devpts + FSType tmpfs + FSType fusectl + FSType cgroup + IgnoreSelected true + + + Server "internal.monitoring.atlantishq.de" "25826" + + + DataDir "/var/lib/collectd/rrd" + + + Filter "*.conf" + diff --git a/roles/monitoring-influx/templates/influxdb.conf.j2 b/roles/monitoring-influx/templates/influxdb.conf.j2 new file mode 100644 index 0000000..aac96e9 --- /dev/null +++ b/roles/monitoring-influx/templates/influxdb.conf.j2 @@ -0,0 +1,29 @@ +[meta] + + dir = "/var/lib/influxdb/meta" + +[data] + + dir = "/var/lib/influxdb/data" + wal-dir = "/var/lib/influxdb/wal" + +[[collectd]] + + enabled = true + bind-address = ":25826" + database = "collectd" + retention-policy = "" + + # security-level = "none" + # auth-file = "/etc/collectd/auth_file" + + batch-size = 5000 + batch-pending = 10 + batch-timeout = "10s" + read-buffer = 0 + + # Multi-value plugins can be handled two ways. + # "split" will parse and store the multi-value plugin data into separate measurements + # "join" will parse and store the multi-value plugin as a single multi-value measurement. + # "split" is the default behavior for backward compatability with previous versions of influxdb. + # parse-multivalue-plugin = "split"