Skip to content

Commit

Permalink
feature to include collectd plugin dependencies and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jellevandehaterd committed Feb 19, 2020
1 parent 688f854 commit 229ae9e
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 20 deletions.
223 changes: 218 additions & 5 deletions 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
# <Nested block>
# NestedKey: "value"
# </Nested>
# - name: write_http
# config: |4
# <Node "oms">
# URL "127.0.0.1:26000/oms.collectd"
# Format "JSON"
# StoreRates true
# </Node>
# - name: postgresql
# dependencies:
# - collectd-postgresql
# config: |4
# <Query tickets>
# Statement "SELECT count(t.id) AS count FROM tickets t WHERE t.closed is null;"
# <Result>
# Type gauge
# InstancePrefix "tickets"
# ValuesFrom "count"
# </Result>
# </Query>
# <Database "ptfe">
# Host "psql-database.hostname.com"
# Port "5432"
# User "my_psqladminuser"
# Password "my_passwd"
# SSLMode "prefer"
# Query tickets
# </Database>


37 changes: 36 additions & 1 deletion molecule/default/playbook.yml
Expand Up @@ -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: |
<Node "oms">
URL "127.0.0.1:26000/oms.collectd"
Format "JSON"
StoreRates true
</Node>
- name: postgresql
dependencies:
- postgresql96
- collectd-postgresql
config: |
<Query tickets>
Statement "SELECT count(t.id) AS count FROM tickets t WHERE t.closed is null;"
<Result>
Type gauge
InstancePrefix "tickets"
ValuesFrom "count"
</Result>
</Query>
<Database "ptfe">
Host "psql-database.hostname.com"
Port "5432"
User "my_psqladminuser"
Password "my_passwd"
SSLMode "prefer"
Query tickets
</Database>
roles:
- role: ansible-role-collectd
44 changes: 30 additions & 14 deletions tasks/main.yml
Expand Up @@ -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:
Expand Down
27 changes: 27 additions & 0 deletions 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

0 comments on commit 229ae9e

Please sign in to comment.