diff --git a/defaults/main.yml b/defaults/main.yml
index 2ba1b14..abbd818 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,12 +1,225 @@
---
# defaults file for collectd
-collectd_settings:
- - parameter: Hostname
- value: "{{ ansible_hostname }}"
+collectd_conf_hostname: "{{ ansible_hostname }}"
+collectd_conf_fqdnlookup: "false"
+collectd_conf_basedir: /var/lib/collectd
+collectd_conf_pidfile: /var/run/collectd.pid
+collectd_conf_plugindir: /usr/lib64/collectd
+collectd_conf_typesdb: /usr/share/collectd/types.db
-collectd_plugins:
- - syslog
+collectd_conf_autoloadplugin: "false"
+collectd_conf_collectinternalstats: "false"
+
+collectd_conf_interval: 10
+collectd_conf_maxreadinterval: 86400
+collectd_conf_timeout: 2
+collectd_conf_readthreads: 5
+collectd_conf_writethreads: 5
+
+collectd_conf_include_dir: /etc/collectd.d
+collectd_conf_fnmatch_filters:
+ - "*.conf"
+
+#### Logging Configuration
+
+collectd_plugin_logging: syslog
+
+collectd_plugin_logging_directory: "/var/log/collectd"
+
+collectd_plugin_logfile_loglevel: "info"
+collectd_plugin_logfile_file: "{{ collectd_plugin_logging_directory }}/collectd.log"
+collectd_plugin_logfile_timestamp: "true"
+collectd_plugin_logfile_printseverity: "false"
+
+collectd_plugin_logstash_loglevel: "info"
+collectd_plugin_logstash_file: "{{ collectd_plugin_logging_directory }}/collectd.json.log"
+
+collectd_plugin_syslog_loglevel: "info"
+#collectd_plugin_syslog_notifylevel: ""
+
+# Use 'collectd_basic_plugins' to enable plugins not requiring additional configuration and/or dependencies to work
+collectd_basic_plugins:
- cpu
- interface
- load
- memory
+ #-aggregation
+ #-amqp
+ #-apache
+ #-apcups
+ #-apple_sensors
+ #-aquaero
+ #-ascent
+ #-barometer
+ #-battery
+ #-bind
+ #-ceph
+ #-cgroups
+ #-chrony
+ #-conntrack
+ #-contextswitch
+ #-cpu
+ #-cpufreq
+ #-cpusleep
+ #-csv
+ #-curl
+ #-curl_json
+ #-curl_xml
+ #-dbi
+ #-df
+ #-disk
+ #-dns
+ #-dpdkevents
+ #-dpdkstat
+ #-drbd
+ #-email
+ #-entropy
+ #-ethstat
+ #-exec
+ #-fhcount
+ #-filecount
+ #-fscache
+ #-gmond
+ #-gps
+ #-grpc
+ #-hddtemp
+ #-hugepages
+ #-intel_pmu
+ #-intel_rdt
+ #-interface
+ #-ipc
+ #-ipmi
+ #-iptables
+ #-ipvs
+ #-irq
+ #-java
+ #-load
+ #-lpar
+ #-lua
+ #-lvm
+ #-madwifi
+ #-mbmon
+ #-mcelog
+ #-md
+ #-memcachec
+ #-memcached
+ #-memory
+ #-mic
+ #-modbus
+ #-mqtt
+ #-multimeter
+ #-mysql
+ #-netapp
+ #-netlink
+ #-network
+ #-nfs
+ #-nginx
+ #-notify_desktop
+ #-notify_email
+ #-notify_nagios
+ #-ntpd
+ #-numa
+ #-nut
+ #-olsrd
+ #-onewire
+ #-openldap
+ #-openvpn
+ #-oracle
+ #-ovs_events
+ #-ovs_stats
+ #-perl
+ #-pinba
+ #-ping
+ #-postgresql
+ #-powerdns
+ #-processes
+ #-protocols
+ #-python
+ #-redis
+ #-routeros
+ #-rrdcached
+ #-rrdtool
+ #-sensors
+ #-serial
+ #-sigrok
+ #-smart
+ #-snmp
+ #-snmp_agent
+ #-statsd
+ #-swap
+ #-table
+ #-tail
+ #-tail_csv
+ #-tape
+ #-tcpconns
+ #-teamspeak2
+ #-ted
+ #-thermal
+ #-tokyotyrant
+ #-turbostat
+ #-unixsock
+ #-uptime
+ #-users
+ #-uuid
+ #-varnish
+ #-virt
+ #-vmem
+ #-vserver
+ #-wireless
+ #-write_graphite
+ #-write_http
+ #-write_kafka
+ #-write_log
+ #-write_mongodb
+ #-write_prometheus
+ #-write_redis
+ #-write_riemann
+ #-write_sensu
+ #-write_tsdb
+ #-xencpu
+ #-xmms
+ #-zfs_arc
+ #-zone
+ #-zookeeper
+
+# Use 'collectd_plugins' to enable plugins requiring additional configuration and/or dependencies to work
+collectd_plugins: []
+# examples:
+# - name: example
+# interval: 120 #seconds
+# flush_interval: 600 #seconds
+# flush_timeout:
+# config: |4
+# Something: true
+#
+# NestedKey: "value"
+#
+# - name: write_http
+# config: |4
+#
+# URL "127.0.0.1:26000/oms.collectd"
+# Format "JSON"
+# StoreRates true
+#
+# - name: postgresql
+# dependencies:
+# - collectd-postgresql
+# config: |4
+#
+# Statement "SELECT count(t.id) AS count FROM tickets t WHERE t.closed is null;"
+#
+# Type gauge
+# InstancePrefix "tickets"
+# ValuesFrom "count"
+#
+#
+#
+# Host "psql-database.hostname.com"
+# Port "5432"
+# User "my_psqladminuser"
+# Password "my_passwd"
+# SSLMode "prefer"
+# Query tickets
+#
+
+
diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml
index 4a5b12b..e9730a7 100644
--- a/molecule/default/playbook.yml
+++ b/molecule/default/playbook.yml
@@ -3,6 +3,41 @@
hosts: all
become: yes
gather_facts: yes
-
+ vars:
+ collectd_basic_plugins:
+ - cpu
+ - interface
+ - load
+ - memory
+ collectd_plugins:
+ - name: oms
+ dependencies: []
+ config: |
+
+ URL "127.0.0.1:26000/oms.collectd"
+ Format "JSON"
+ StoreRates true
+
+ - name: postgresql
+ dependencies:
+ - postgresql96
+ - collectd-postgresql
+ config: |
+
+ Statement "SELECT count(t.id) AS count FROM tickets t WHERE t.closed is null;"
+
+ Type gauge
+ InstancePrefix "tickets"
+ ValuesFrom "count"
+
+
+
+ Host "psql-database.hostname.com"
+ Port "5432"
+ User "my_psqladminuser"
+ Password "my_passwd"
+ SSLMode "prefer"
+ Query tickets
+
roles:
- role: ansible-role-collectd
diff --git a/tasks/main.yml b/tasks/main.yml
index 4e9004d..8aa2312 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -9,25 +9,41 @@
retries: 3
- name: configure collectd
- lineinfile:
- path: "{{ collectd_configuration_path }}"
- regexp: "^{{ item.parameter }}"
- line: "{{ item.parameter }} \"{{ item.value }}\""
+ template:
+ src: collectd.conf.j2
+ dest: "{{ collectd_configuration_path }}"
+ owner: root
+ group: root
+ mode: 0644
validate: collectd -C %s -t
- loop: "{{ collectd_settings }}"
- loop_control:
- label: "{{ item.parameter }}"
notify:
- restart collectd
-- name: configure plugins
- lineinfile:
- path: "{{ collectd_configuration_path }}"
- line: "LoadPlugin {{ item }}"
- validate: collectd -C %s -t
+- name: set _plugins_configured to empty list
+ set_fact:
+ _new_plugins_configured: []
+ _plugins_configured: []
+
+- name: find existing plugins files
+ find:
+ paths: "{{ collectd_conf_include_dir }}"
+ file_type: file
+ patterns: '*.conf'
+ register: _plugins_configured
+
+- name: configure collectd plugins
+ include_tasks: plugins.yml
loop: "{{ collectd_plugins }}"
- notify:
- - restart collectd
+ loop_control:
+ label: "{{ plugin.name }}"
+ loop_var: plugin
+ index_var: index
+
+- name: remove obsolete plugin files
+ file:
+ path: "{{ item }}"
+ state: absent
+ loop: "{{ (_plugins_configured.files | map(attribute='path') | list) | difference(_new_plugins_configured) }}"
- name: start and enable collectd
service:
diff --git a/tasks/plugins.yml b/tasks/plugins.yml
new file mode 100644
index 0000000..54bbdd4
--- /dev/null
+++ b/tasks/plugins.yml
@@ -0,0 +1,27 @@
+---
+- name: install collectd plugin dependencies
+ package:
+ name: "{{ plugin.dependencies }}"
+ state: present
+ register: collectd_install_collectd_deps
+ until: collectd_install_collectd_deps is succeeded
+ when: plugin.dependencies is defined
+ retries: 3
+
+- name: configure collectd plugins
+ template:
+ src: collectd.d/plugin.conf.j2
+ dest: "{{ collectd_conf_include_dir }}/{{ '%03d' | format(index + 1) }}-{{ plugin.name }}.conf"
+ owner: root
+ group: root
+ mode: 0644
+ validate: collectd -C %s -t
+ register: configured_plugin
+ when: plugin.config is defined
+ notify:
+ - restart collectd
+
+- name: Append configured plugin to list
+ set_fact:
+ _new_plugins_configured: "{{ _new_plugins_configured + [ configured_plugin.dest ]}}"
+ when: plugin.config is defined
diff --git a/templates/collectd.conf.j2 b/templates/collectd.conf.j2
new file mode 100644
index 0000000..682ffd4
--- /dev/null
+++ b/templates/collectd.conf.j2
@@ -0,0 +1,125 @@
+# {{ ansible_managed }}
+#
+# Config file for collectd(1).
+# Please read collectd.conf(5) for a list of options.
+# http://collectd.org/
+#
+
+##############################################################################
+# Global #
+#----------------------------------------------------------------------------#
+# Global settings for the daemon. #
+##############################################################################
+
+{% if collectd_conf_hostname is defined %}
+Hostname "{{ collectd_conf_hostname }}"
+{% endif %}
+FQDNLookup {{ collectd_conf_fqdnlookup }}
+BaseDir "{{ collectd_conf_basedir }}"
+PIDFile "{{ collectd_conf_pidfile }}"
+PluginDir "{{ collectd_conf_plugindir }}"
+TypesDB "{{ collectd_conf_typesdb }}"
+
+#----------------------------------------------------------------------------#
+# When enabled, plugins are loaded automatically with the default options #
+# when an appropriate block is encountered. #
+# Disabled by default. #
+#----------------------------------------------------------------------------#
+AutoLoadPlugin {{ collectd_conf_autoloadplugin }}
+
+#----------------------------------------------------------------------------#
+# When enabled, internal statistics are collected, using "collectd" as the #
+# plugin name. #
+# Disabled by default. #
+#----------------------------------------------------------------------------#
+CollectInternalStats {{ collectd_conf_collectinternalstats }}
+
+#----------------------------------------------------------------------------#
+# Interval at which to query values. This may be overwritten on a per-plugin #
+# base by using the 'Interval' option of the LoadPlugin block: #
+# #
+# Interval 60 #
+# #
+#----------------------------------------------------------------------------#
+Interval {{ collectd_conf_interval }}
+
+MaxReadInterval {{ collectd_conf_maxreadinterval }}
+Timeout {{ collectd_conf_timeout }}
+ReadThreads {{ collectd_conf_readthreads }}
+WriteThreads {{ collectd_conf_writethreads }}
+
+# Limit the size of the write queue. Default is no limit. Setting up a limit is
+# recommended for servers handling a high volume of traffic.
+{% if collectd_conf_writequeuelimithigh is defined %}
+WriteQueueLimitHigh {{ collectd_conf_writequeuelimithigh }}
+{% endif -%}
+{% if collectd_conf_writequeuelimitlow is defined %}
+WriteQueueLimitLow {{ collectd_conf_writequeuelimitlow }}
+{% endif -%}
+
+##############################################################################
+# Logging #
+#----------------------------------------------------------------------------#
+# Plugins which provide logging functions should be loaded first, so log #
+# messages generated when loading or configuring other plugins can be #
+# accessed. #
+##############################################################################
+
+LoadPlugin {{ collectd_plugin_logging }}
+
+{% if collectd_plugin_logging == "logfile" %}
+
+ LogLevel {{ collectd_plugin_logfile_loglevel }}
+ File "{{ collectd_plugin_logfile_file }}"
+ Timestamp {{ collectd_plugin_logfile_timestamp }}
+ PrintSeverity {{ collectd_plugin_logfile_printseverity }}
+
+{% endif -%}
+
+{% if collectd_plugin_logging== "log_logstash" %}
+
+ LogLevel {{ collectd_plugin_logstash_loglevel }}
+ File "{{ collectd_plugin_logstash_file }}"
+
+{% endif -%}
+
+{% if collectd_plugin_logging== "syslog" %}
+
+ LogLevel {{ collectd_plugin_syslog_loglevel }}
+{% if collectd_plugin_syslog_notifylevel is defined %}
+ NotifyLevel {{ collectd_plugin_syslog_notifylevel }}
+{% endif %}
+
+{% endif %}
+
+{% if collectd_conf_autoloadplugin -%}
+#----------------------------------------------------------------------------#
+# LoadPlugin section
+#----------------------------------------------------------------------------#
+{% for plugin in collectd_basic_plugins -%}
+LoadPlugin {{ plugin }}
+{% endfor %}
+{%- endif %}
+
+##############################################################################
+# Filter configuration #
+#----------------------------------------------------------------------------#
+# The following configures collectd's filtering mechanism. Before changing #
+# anything in this section, please read the `FILTER CONFIGURATION' section #
+# in the collectd.conf(5) manual page. #
+##############################################################################
+
+##############################################################################
+# Threshold configuration #
+#----------------------------------------------------------------------------#
+# The following outlines how to configure collectd's threshold checking #
+# plugin. The plugin and possible configuration options are documented in #
+# the collectd-threshold(5) manual page. #
+##############################################################################
+
+
+ {% for filter in collectd_conf_fnmatch_filters -%}
+ Filter "{{ filter }}"
+ {%- endfor %}
+
+
diff --git a/templates/collectd.d/plugin.conf.j2 b/templates/collectd.d/plugin.conf.j2
new file mode 100644
index 0000000..be7d818
--- /dev/null
+++ b/templates/collectd.d/plugin.conf.j2
@@ -0,0 +1,22 @@
+# {{ ansible_managed }}
+{% if collectd_conf_autoloadplugin -%}
+LoadPlugin {{ plugin.name }}
+{%- endif %}
+
+{% if plugin.config is defined -%}
+
+ {% if plugin.interval is defined -%}
+ Interval {{ plugin.interval }}
+ {%- endif %}
+
+ {% if plugin.flush_interval is defined -%}
+ FlushInterval {{ plugin.flush_interval }}
+ {%- endif %}
+
+ {% if plugin.flush_timeout is defined -%}
+ FlushTimeout {{ plugin.flush_timeout }}
+ {%- endif %}
+
+{{ plugin.config | indent(2, first=True) }}
+
+{% endif %}