diff --git a/roles/collectd-prometheus/defaults/main.yml b/roles/collectd-prometheus/defaults/main.yml new file mode 100644 index 0000000..30a73ea --- /dev/null +++ b/roles/collectd-prometheus/defaults/main.yml @@ -0,0 +1,2 @@ +collectd_load_prometheus_plugin: true +collectd_prometheus_port: 9103 diff --git a/roles/collectd-prometheus/files/collectd-local.pp b/roles/collectd-prometheus/files/collectd-local.pp new file mode 100644 index 0000000..4695d7b Binary files /dev/null and b/roles/collectd-prometheus/files/collectd-local.pp differ diff --git a/roles/collectd-prometheus/handlers/main.yml b/roles/collectd-prometheus/handlers/main.yml new file mode 100644 index 0000000..64ac7b7 --- /dev/null +++ b/roles/collectd-prometheus/handlers/main.yml @@ -0,0 +1,8 @@ +- name: install collectd-local selinux module + command: + semodule -i /var/lib/selinux/collectd-local.pp + +- name: restart collectd + service: + name: collectd + state: restarted diff --git a/roles/collectd-prometheus/tasks/main.yml b/roles/collectd-prometheus/tasks/main.yml new file mode 100644 index 0000000..93c7d0d --- /dev/null +++ b/roles/collectd-prometheus/tasks/main.yml @@ -0,0 +1,34 @@ +- name: load distribution-specific values + include_vars: '{{ item }}' + with_first_found: + - '{{ ansible_distribution }}.yml' + - defaults.yml + tags: + - always + +- name: ensure collectd write_prometheus plugin is installed + package: + name: '{{ collectd_prometheus_package }}' + state: present + when: collectd_prometheus_package is not none + tags: + - install + +- name: ensure collectd-local selinux module is installed + copy: + src: collectd-local.pp + dest: /var/lib/selinux/collectd-local.pp + notify: + - install collectd-local selinux module + tags: + - selinux + +- name: ensure collectd write_prometheus plugin is configured + template: + src: collectd-prometheus.conf.j2 + dest: /etc/collectd.d/prometheus.conf + mode: '0644' + notify: + - restart collectd + tags: + - collectd-config diff --git a/roles/collectd-prometheus/templates/collectd-prometheus.conf.j2 b/roles/collectd-prometheus/templates/collectd-prometheus.conf.j2 new file mode 100644 index 0000000..8a6369d --- /dev/null +++ b/roles/collectd-prometheus/templates/collectd-prometheus.conf.j2 @@ -0,0 +1,10 @@ +{% if collectd_load_prometheus_plugin %} +LoadPlugin write_prometheus + +{% endif %} + + Port {{ collectd_prometheus_port }} +{% if collectd_prometheus_host is defined %} + Host "{{ collectd_prometheus_host }}" +{% endif %} + diff --git a/roles/collectd-prometheus/vars/defaults.yml b/roles/collectd-prometheus/vars/defaults.yml new file mode 100644 index 0000000..ec78586 --- /dev/null +++ b/roles/collectd-prometheus/vars/defaults.yml @@ -0,0 +1 @@ +collectd_prometheus_package: collectd-write_prometheus