Writing of collectd role #28
|
@ -31,6 +31,7 @@
|
||||||
# - openvpn
|
# - openvpn
|
||||||
# - ospf
|
# - ospf
|
||||||
# - bgp
|
# - bgp
|
||||||
|
# - { role: collectd, collectd_server: "127.0.0.1" }
|
||||||
|
|
||||||
post_tasks:
|
post_tasks:
|
||||||
- include: "tasks/commit_etc_git.yml"
|
- include: "tasks/commit_etc_git.yml"
|
||||||
|
|
13
roles/collectd/README.md
Normal file
13
roles/collectd/README.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Collectd
|
||||||
|
|
||||||
|
Installation and custom configuration of Collectd daemon.
|
||||||
|
|
||||||
|
## Tasks
|
||||||
|
|
||||||
|
Everything is in the `tasks/main.yml` file.
|
||||||
|
|
||||||
|
## Available variables
|
||||||
|
|
||||||
|
The full list of variables (with default values) can be found in `defaults/main.yml`.
|
||||||
|
|
||||||
|
* `collectd_server` : server to which the data will be sent (default: 127.0.0.1).
|
31
roles/collectd/defaults/main.yml
Normal file
31
roles/collectd/defaults/main.yml
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
# destination server
|
||||||
|
|
||||||
|
collectd_server: "127.0.0.1"
|
||||||
|
|
||||||
|
# execution interval
|
||||||
|
|
||||||
|
collectd_interval: "300"
|
||||||
|
|
||||||
|
# exec plugin
|
||||||
|
|
||||||
|
collectd_plugin_exec_interval: "{{ collectd_interval }}"
|
||||||
|
collectd_plugin_exec_ifq_drops: false
|
||||||
|
collectd_plugin_exec_dns_stats: false # Based on unbound
|
||||||
|
collectd_plugin_exec_dns_stats_interval: "{{ collectd_interval }}"
|
||||||
|
|
||||||
|
# others plugins
|
||||||
|
|
||||||
|
collectd_plugin_cpu: true
|
||||||
|
collectd_plugin_df: true
|
||||||
|
collectd_plugin_disk: true
|
||||||
|
collectd_plugin_interface: true
|
||||||
|
collectd_plugin_load: true
|
||||||
|
collectd_plugin_memory: true
|
||||||
|
collectd_plugin_pf: true
|
||||||
|
collectd_plugin_processes: true
|
||||||
|
collectd_plugin_swap: true
|
||||||
|
collectd_plugin_tcpconns: true
|
||||||
|
collectd_plugin_uptime: true
|
||||||
|
collectd_plugin_users: true
|
3
roles/collectd/files/dns_stats.sh
Executable file
3
roles/collectd/files/dns_stats.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/ksh
|
||||||
|
|
||||||
|
echo "PUTVAL $(hostname)/dns_stats/count N:$(doas /bin/cat /var/log/daemon | grep "server stats" | grep -v "requestlist max" | awk '{print $13}' | tail -1)"
|
3
roles/collectd/files/ifq_drops.sh
Executable file
3
roles/collectd/files/ifq_drops.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/ksh
|
||||||
|
|
||||||
|
echo "PUTVAL $(hostname)/ifq_drops/count N:$(sysctl net.inet.ip.arpq.drops | awk -F= '{print $NF}')"
|
10
roles/collectd/handlers/main.yml
Normal file
10
roles/collectd/handlers/main.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
- name: restart collectd
|
||||||
|
service:
|
||||||
|
name: collectd
|
||||||
|
state: restarted
|
||||||
|
|
||||||
|
- name: reload unbound
|
||||||
|
service:
|
||||||
|
name: unbound
|
||||||
|
state: reloaded
|
106
roles/collectd/tasks/main.yml
Normal file
106
roles/collectd/tasks/main.yml
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
---
|
||||||
|
- name: Install Collectd package
|
||||||
|
openbsd_pkg:
|
||||||
|
name: "collectd"
|
||||||
|
tags:
|
||||||
|
- collectd
|
||||||
|
|
||||||
|
- name: Deploy Collectd configuration
|
||||||
|
template:
|
||||||
|
src: "collectd.conf.j2"
|
||||||
|
dest: "/etc/collectd.conf"
|
||||||
|
notify: restart collectd
|
||||||
|
tags:
|
||||||
|
- collectd
|
||||||
|
|
||||||
|
- name: Enabling Collectd
|
||||||
|
service:
|
||||||
|
name: collectd
|
||||||
|
enabled: true
|
||||||
|
tags:
|
||||||
|
- collectd
|
||||||
|
|
||||||
|
- name: Create scripts directory for exec plugins
|
||||||
|
file:
|
||||||
|
path: /usr/local/share/collectd/scripts
|
||||||
|
state: directory
|
||||||
|
when: collectd_plugin_exec_ifq_drops or collectd_plugin_exec_dns_stats
|
||||||
|
tags:
|
||||||
|
- collectd
|
||||||
|
|
||||||
|
- name: Copy ifq_drops.sh
|
||||||
|
copy:
|
||||||
|
src: ifq_drops.sh
|
||||||
|
dest: /usr/local/share/collectd/scripts/ifq_drops.sh
|
||||||
|
mode: 0755
|
||||||
|
force: true
|
||||||
|
when: collectd_plugin_exec_ifq_drops
|
||||||
|
tags:
|
||||||
|
- collectd
|
||||||
|
|
||||||
|
- name: Remove ifq_drops.sh
|
||||||
|
file:
|
||||||
|
path: /usr/local/share/collectd/scripts/ifq_drops.sh
|
||||||
|
state: absent
|
||||||
|
when: not collectd_plugin_exec_ifq_drops
|
||||||
|
tags:
|
||||||
|
- collectd
|
||||||
|
|
||||||
|
- name: Copy dns_stats.sh
|
||||||
|
copy:
|
||||||
|
src: dns_stats.sh
|
||||||
|
dest: /usr/local/share/collectd/scripts/dns_stats.sh
|
||||||
|
mode: 0755
|
||||||
|
force: true
|
||||||
|
when: collectd_plugin_exec_dns_stats
|
||||||
|
tags:
|
||||||
|
- collectd
|
||||||
|
|
||||||
|
- name: Add stats DNS on unbound
|
||||||
|
lineinfile:
|
||||||
|
path: /var/unbound/etc/unbound.conf
|
||||||
|
regexp: 'statistics-interval'
|
||||||
|
line:
|
||||||
|
' statistics-interval: {{ collectd_plugin_exec_dns_stats_interval }}'
|
||||||
|
insertafter: 'hide-version:'
|
||||||
|
backup: true
|
||||||
|
notify: reload unbound
|
||||||
|
when: collectd_plugin_exec_dns_stats
|
||||||
|
tags:
|
||||||
|
- collectd
|
||||||
|
|
||||||
|
- name: Remove dns_stats.sh
|
||||||
|
file:
|
||||||
|
path: /usr/local/share/collectd/scripts/dns_stats.sh
|
||||||
|
state: absent
|
||||||
|
when: not collectd_plugin_exec_dns_stats
|
||||||
|
tags:
|
||||||
|
- collectd
|
||||||
|
|
||||||
|
- name: Remove stats DNS on unbound
|
||||||
|
lineinfile:
|
||||||
|
path: /var/unbound/etc/unbound.conf
|
||||||
|
regexp: 'statistics-interval'
|
||||||
|
backup: true
|
||||||
|
state: absent
|
||||||
|
notify: reload unbound
|
||||||
|
when: not collectd_plugin_exec_dns_stats
|
||||||
|
tags:
|
||||||
|
- collectd
|
||||||
|
|
||||||
|
- name: Add doas configuration for dns_stats.sh execution
|
||||||
|
lineinfile:
|
||||||
|
path: /etc/doas.conf
|
||||||
|
line: 'permit nopass _collectd as root cmd /bin/cat'
|
||||||
|
when: collectd_plugin_exec_dns_stats
|
||||||
|
tags:
|
||||||
|
- collectd
|
||||||
|
|
||||||
|
- name: Delete doas configuration for dns_stats.sh execution
|
||||||
|
lineinfile:
|
||||||
|
path: /etc/doas.conf
|
||||||
|
line: 'permit nopass _collectd as root cmd /bin/cat'
|
||||||
|
state: absent
|
||||||
|
when: not collectd_plugin_exec_dns_stats
|
||||||
|
tags:
|
||||||
|
- collectd
|
122
roles/collectd/templates/collectd.conf.j2
Normal file
122
roles/collectd/templates/collectd.conf.j2
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
Interval {{ collectd_interval }}
|
||||||
|
Timeout 2
|
||||||
|
|
||||||
|
LoadPlugin syslog
|
||||||
|
<Plugin syslog>
|
||||||
|
LogLevel warning
|
||||||
|
</Plugin>
|
||||||
|
|
||||||
|
{% if (collectd_plugin_exec_ifq_drops is sameas true) or (collectd_plugin_exec_dns_stats is sameas true) %}
|
||||||
|
<LoadPlugin exec>
|
||||||
|
Interval {{ collectd_plugin_exec_interval }}
|
||||||
|
</LoadPlugin>
|
||||||
|
|
||||||
|
<Plugin exec>
|
||||||
|
{% if collectd_plugin_exec_ifq_drops is sameas true %}
|
||||||
|
Exec "_collectd" "/usr/local/share/collectd/scripts/ifq_drops.sh"
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_exec_dns_stats is sameas true %}
|
||||||
|
Exec "_collectd" "/usr/local/share/collectd/scripts/dns_stats.sh"
|
||||||
|
{% endif %}
|
||||||
|
</Plugin>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_load is sameas true %}
|
||||||
|
LoadPlugin load
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_processes is sameas true %}
|
||||||
|
LoadPlugin processes
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_uptime is sameas true %}
|
||||||
|
LoadPlugin uptime
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_users is sameas true %}
|
||||||
|
LoadPlugin users
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_pf is sameas true %}
|
||||||
|
LoadPlugin pf
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if collectd_plugin_df is sameas true %}
|
||||||
|
LoadPlugin df
|
||||||
|
<Plugin df>
|
||||||
|
# expose host's mounts into container using -v /:/host:ro (location inside container does not matter much)
|
||||||
|
# ignore rootfs; else, the root file-system would appear twice, causing
|
||||||
|
# one of the updates to fail and spam the log
|
||||||
|
## Seems to be fixed with collectd 5.5+
|
||||||
|
## FSType rootfs
|
||||||
|
# ignore the usual virtual / temporary file-systems
|
||||||
|
FSType sysfs
|
||||||
|
FSType proc
|
||||||
|
FSType devtmpfs
|
||||||
|
FSType devpts
|
||||||
|
FSType tmpfs
|
||||||
|
FSType fusectl
|
||||||
|
FSType cgroup
|
||||||
|
FSType overlay
|
||||||
|
FSType debugfs
|
||||||
|
FSType pstore
|
||||||
|
FSType securityfs
|
||||||
|
FSType hugetlbfs
|
||||||
|
FSType squashfs
|
||||||
|
FSType mqueue
|
||||||
|
IgnoreSelected true
|
||||||
|
|
||||||
|
ReportByDevice false
|
||||||
|
ReportInodes true # Default false
|
||||||
|
ValuesAbsolute true
|
||||||
|
ValuesPercentage true
|
||||||
|
</Plugin>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_disk is sameas true %}
|
||||||
|
LoadPlugin disk
|
||||||
|
<Plugin "disk">
|
||||||
|
#Disk "/^[hsv]d[a-z]/"
|
||||||
|
IgnoreSelected false
|
||||||
|
</Plugin>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_cpu is sameas true %}
|
||||||
|
LoadPlugin cpu
|
||||||
|
<Plugin cpu>
|
||||||
|
ValuesPercentage true
|
||||||
|
</Plugin>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_memory is sameas true %}
|
||||||
|
LoadPlugin memory
|
||||||
|
<Plugin memory>
|
||||||
|
ValuesPercentage true
|
||||||
|
</Plugin>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_swap is sameas true %}
|
||||||
|
LoadPlugin swap
|
||||||
|
<Plugin swap>
|
||||||
|
ValuesPercentage true
|
||||||
|
</Plugin>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_interface is sameas true %}
|
||||||
|
LoadPlugin interface
|
||||||
|
<Plugin interface>
|
||||||
|
Interface "/^lo[0-9]*/"
|
||||||
|
Interface "/^veth.*/"
|
||||||
|
Interface "/^docker.*/"
|
||||||
|
IgnoreSelected true
|
||||||
|
ReportInactive false
|
||||||
|
</Plugin>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if collectd_plugin_tcpconns is sameas true %}
|
||||||
|
LoadPlugin tcpconns
|
||||||
|
<Plugin "tcpconns">
|
||||||
|
AllPortsSummary true
|
||||||
|
</Plugin>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
LoadPlugin network
|
||||||
|
<Plugin "network">
|
||||||
|
Server "{{ collectd_server }}" "25826"
|
||||||
|
</Plugin>
|
Loading…
Reference in a new issue