From 17a028869aa65ee5c806aa40478532a8e9c3e152 Mon Sep 17 00:00:00 2001 From: "felix.niederwanger@suse.com" Date: Thu, 25 Mar 2021 15:57:31 +0100 Subject: [PATCH] first commit --- .gitignore | 2 + .yamllint | 34 +++ README.md | 28 ++ defaults/main.yml | 28 ++ handlers/main.yml | 11 + meta/main.yml | 23 ++ tasks/main.yml | 33 +++ templates/collectd.conf.j2 | 577 ++++++++++++++++++++++++++++++++++++ vars/main.yml | 2 + vars/openSUSE Leap_15.2.yml | 3 + 10 files changed, 741 insertions(+) create mode 100644 .gitignore create mode 100644 .yamllint create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/collectd.conf.j2 create mode 100644 vars/main.yml create mode 100644 vars/openSUSE Leap_15.2.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b77a956 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Python cache +__pycache__ diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..2102f83 --- /dev/null +++ b/.yamllint @@ -0,0 +1,34 @@ +--- + +yaml-files: + - '*.yaml' + - '*.yml' + - '.yamllint' + +rules: + braces: enable + brackets: enable + colons: enable + commas: enable + comments: + level: warning + comments-indentation: + level: warning + document-end: disable + document-start: + level: warning + empty-lines: enable + empty-values: disable + hyphens: enable + indentation: enable + key-duplicates: enable + key-ordering: disable + line-length: + level: warning + new-line-at-end-of-file: enable + new-lines: enable + octal-values: disable + quoted-strings: disable + trailing-spaces: enable + truthy: + level: warning diff --git a/README.md b/README.md new file mode 100644 index 0000000..022707d --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# geekoops-collectd + +Easy ansible role to setup `collectd`. This ansible role works with + +- openSUSE Leap 15.2 + + +## Role Variables + +| Value | Description | Default | +|-------|-------------|---------| + + +## Example Playbook + + - hosts: jellyfish + roles: + - { role: geekoops-collectd } + +## License + +MIT + +## Author Information + +phoenix + +Have a lot of fun! diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..df5cff6 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,28 @@ +--- +# defaults file for geekoops-collectd + +nodename: "localhost" +interval: 10 +overwrite: false + +enable_influx: false +influx_host: "127.0.0.1" +influx_port: 25826 + +enable_prometheus: false +prometheus_port: "9103" + +## Plugins + +enable_disk: true +enable_cpu: true +enable_load: true +enable_memory: true +enable_swap: true +enable_smart: false +enable_df: false + +disk_disks: [] +df_disks: [] +smart_disk: "" +smart_use_serial: true diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..166ab81 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,11 @@ +--- +# handlers file for geekoops-collectd + + +- name: reload firewalld + shell: firewall-cmd --reload + +- name: restart collectd + systemd: + name: "{{collectd_service}}" + state: restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..f0ace22 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,23 @@ +--- +galaxy_info: + author: Felix Niederwanger + description: Configurable collectd installation role + company: SUSE + issue_tracker_url: https://github.com/GeekOops/geekoops-collectd/issues + + license: license MIT + + min_ansible_version: 2.9 + + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + platforms: + - name: opensuse + versions: + - 15.2 + + galaxy_tags: + - collectd + +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..0c3d1f7 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,33 @@ +--- +# tasks file for geekoops-collectd + +# Distribution specific vars are ALWAYS needed, so don't forget the tags here +- name: include distribution specific vars + include_vars: "{{ansible_distribution}}_{{ansible_distribution_version}}.yml" + tags: ['collectd'] + +- name: Install collectd + package: + name: "{{ packages }}" + state: present + register: install + tags: ['collectd'] + +- name: Ensure collectd is configured + template: + src: collectd.conf.j2 + dest: /etc/collectd.conf + owner: root + group: root + mode: 0640 + force: "{{overwrite}} or install.changed" + tags: ['collectd'] + notify: restart collectd + +- name: Ensure collectd is enabled + systemd: + name: collectd + state: started + enabled: true + tags: ['collectd'] + diff --git a/templates/collectd.conf.j2 b/templates/collectd.conf.j2 new file mode 100644 index 0000000..97a7698 --- /dev/null +++ b/templates/collectd.conf.j2 @@ -0,0 +1,577 @@ +{% if overwrite %} +################################################################################ +## collectd configuration file ## +## This file is managed by geekoops-collectd ## +## Please don't edit this file manually as your changes will be overwritten ## +################################################################################ + +{% endif %} +Hostname "{{ nodename }}" +#FQDNLookup true +AutoLoadPlugin true +Interval {{ interval }} + +LoadPlugin syslog +LoadPlugin cpu +#LoadPlugin cpufreq +#LoadPlugin cpusleep +{% if enable_df == true %} +LoadPlugin df +{% else %} +#LoadPlugin df +{% endif %} +{% if enable_disk == true %} +LoadPlugin disk +{% else %} +#LoadPlugin disk +{% endif %} +#LoadPlugin hddtemp +#LoadPlugin hugepages +LoadPlugin interface +#LoadPlugin ipmi +{% if enable_load == true %} +LoadPlugin load +{% else %} +#LoadPlugin load +{% endif %} +#LoadPlugin md +{% if enable_memory == true %} +LoadPlugin memory +{% else %} +#LoadPlugin memory +{% endif %} +#LoadPlugin mysql +#LoadPlugin netlink +#LoadPlugin network +#LoadPlugin nfs +#LoadPlugin nginx +#LoadPlugin ntpd +#LoadPlugin openvpn +#LoadPlugin pcie_errors +#LoadPlugin postgresql +#LoadPlugin processes +#LoadPlugin procevent +#LoadPlugin rrdcached +#LoadPlugin rrdtool +#LoadPlugin sensors +#LoadPlugin serial + +{% if enable_smart == true and smart_disk != "" %} +#LoadPlugin smart +{% else %} +#LoadPlugin smart +{% endif %} +#LoadPlugin snmp +#LoadPlugin snmp_agent +#LoadPlugin statsd +{% if enable_swap == true %} +LoadPlugin swap +{% else %} +#LoadPlugin swap +{% endif %} +#LoadPlugin thermal +LoadPlugin uptime +#LoadPlugin users +#LoadPlugin virt +#LoadPlugin vmem + +{% if enable_prometheus == true %} +LoadPlugin write_prometheus +{% endif %} + +# +# Host "localhost" +# Port "3551" +# ReportSeconds true +# PersistentConnection true +# + +# +# ValuesPercentage false +# ReportDegraded false +# QueryStateFS false +# + +# +# Host "localhost" +# Port "323" +# Timeout "2" +# + +# +# Interface eth0 +# + +# +# CGroup "libvirt" +# IgnoreSelected false +# + +{% if enable_cpu == true %} + + ReportByCpu true + ReportByState true + ValuesPercentage true + ReportNumCpu false + ReportGuestState false + SubtractGuestState true + +{% endif %} + +{% if enable_df == true %} + +{% for disk in df_disks %} + Device "{{ disk }}" +{% endfor %} +# IgnoreSelected false +# ReportByDevice false +# ReportInodes false + ValuesAbsolute true + ValuesPercentage true + +{% endif %} + +{% if enable_disk == true %} +{% for disk in disk_disks %} + + Disk "{{ disk }}" + IgnoreSelected false + # UdevNameAttr "DEVNAME" + +{% endfor %} +{% endif %} + +# +# Interface "eth0" +# Map "rx_csum_offload_errors" "if_rx_errors" "checksum_offload" +# Map "multicast" "if_multicast" +# MappedOnly false +# + +# +# +# #Plugin "foo" +# Instance "foodir" +# Name "*.conf" +# MTime "-5m" +# Size "+10k" +# Recursive true +# IncludeHidden false +# RegularOnly true +# #FilesSizeType "bytes" +# #FilesCountType "files" +# #TypeInstance "instance" +# +# + +# +# Host "127.0.0.1" +# Port "7634" +# + +# +# ReportPerNodeHP true +# ReportRootHP true +# ValuesPages true +# ValuesBytes false +# ValuesPercentage false +# + +# +# Interface "eth0" +# IgnoreSelected false +# ReportInactive true +# UniqueName false +# + +{% if enable_load == true %} + + ReportRelative true + +{% endif %} + +# +# Device "/dev/md0" +# IgnoreSelected false +# + +{% if enable_memory == true %} + + ValuesAbsolute false + ValuesPercentage true + +{% endif %} + +# +# +# Host "database.serv.er" +# User "db_user" +# Password "secret" +# Database "db_name" +# SSLKey "/path/to/key.pem" +# SSLCert "/path/to/cert.pem" +# SSLCA "/path/to/ca.pem" +# SSLCAPath "/path/to/cas/" +# SSLCipher "DHE-RSA-AES256-SHA" +# MasterStats true +# ConnectTimeout 10 +# InnodbStats true +# +# +# +# Alias "squeeze" +# Host "localhost" +# Socket "/var/run/mysql/mysqld.sock" +# SlaveStats true +# SlaveNotifications true +# +# +# Alias "galera" +# Host "localhost" +# Socket "/var/run/mysql/mysqld.sock" +# WsrepStats true +# +# + +# +# Interface "All" +# VerboseInterface "All" +# QDisc "eth0" "pfifo_fast-1:0" +# Class "ppp0" "htb-1:10" +# Filter "ppp0" "u32-1:0" +# IgnoreSelected false +# + +{% if enable_influx %} + + Server "{{ influx_host }}" "{{ influx_port }}" + +{% endif %} + +# +# ReportV2 false +# #ReportV3 false +# #ReportV4 false +# + +# +# URL "http://localhost/status?auto" +# User "www-user" +# Password "secret" +# CACert "/etc/ssl/ca.crt" +# + +# +# Host "localhost" +# Port 123 +# ReverseLookups false +# IncludeUnitID true +# + +# +# +# URL "ldap://localhost:389" +# StartTLS false +# VerifyHost true +# CACert "/path/to/ca.crt" +# Timeout -1 +# Version 3 +# +# + +# +# StatusFile "/etc/openvpn/openvpn-status.log" +# ImprovedNamingSchema false +# CollectCompression true +# CollectIndividualUsers true +# CollectUserCount false +# + +# +# Source "sysfs" +# ReportMasked false +# PersistentNotifications false +# + +# +# Host "host.foo.bar" +# Interval 1.0 +# Timeout 0.9 +# TTL 255 +# SourceAddress "1.2.3.4" +# AddressFamily "any" +# Device "eth0" +# MaxMissed -1 +# + +# +# +# Statement "SELECT magic FROM wizard WHERE host = $1;" +# Param hostname +# +# Type gauge +# InstancePrefix "magic" +# ValuesFrom magic +# +# +# +# Statement "SELECT COUNT(type) AS count, type \ +# FROM (SELECT CASE \ +# WHEN resolved = 'epoch' THEN 'open' \ +# ELSE 'resolved' END AS type \ +# FROM tickets) type \ +# GROUP BY type;" +# +# Type counter +# InstancePrefix "rt36_tickets" +# InstancesFrom "type" +# ValuesFrom "count" +# +# +# +# # See contrib/postgresql/collectd_insert.sql for details +# Statement "SELECT collectd_insert($1, $2, $3, $4, $5, $6, $7, $8, $9);" +# StoreRates true +# +# +# #Plugin "kingdom" +# Host "hostname" +# Port "5432" +# User "username" +# Password "secret" +# SSLMode "prefer" +# KRBSrvName "kerberos_service_name" +# Query magic +# +# +# Interval 60 +# Service "service_name" +# Query backends # predefined +# Query rt36_tickets +# +# +# Service "collectd_store" +# Writer sqlstore +# # see collectd.conf(5) for details +# CommitInterval 30 +# +# + +# +# CollectFileDescriptor true +# CollectContextSwitch true +# CollectMemoryMaps true +# CollectDelayAccounting false +# Process "name" +# ProcessMatch "name" "regex" +# +# CollectFileDescriptor false +# CollectContextSwitch false +# CollectDelayAccounting true +# +# +# CollectFileDescriptor false +# CollectContextSwitch true +# +# + +# +# Value "/^Tcp:/" +# IgnoreSelected false +# + +# +# +# Host "redis.example.com" +# Port "6379" +# #Socket "/var/run/redis/redis.sock" +# Timeout 2000 +# +# #Database 0 +# Type "queue_length" +# Instance "myqueue" +# +# +# + +# +# DaemonAddress "unix:/tmp/rrdcached.sock" +# DataDir "/var/lib/collectd/rrd" +# CreateFiles true +# CreateFilesAsync false +# CollectStatistics true +# + +# +# DataDir "/var/lib/collectd/rrd" +# CreateFilesAsync false +# CacheTimeout 120 +# CacheFlush 900 +# WritesPerSecond 50 +# + +# +# SensorConfigFile "/etc/sensors.conf" +# Sensor "it8712-isa-0290/temperature-temp1" +# Sensor "it8712-isa-0290/fanspeed-fan3" +# Sensor "it8712-isa-0290/voltage-in8" +# IgnoreSelected false +# + + +{% if enable_smart == true and smart_disk != "" %} + + Disk "/^[hs]d[a-f][0-9]?$/" + IgnoreSelected false + IgnoreSleepMode false + UseSerial {{ smart_use_serial }} + +{% endif %} + +# +# +# Table false +# Type "voltage" +# TypeInstance "input_line1" +# Values "SNMPv2-SMI::enterprises.6050.5.4.1.1.2.1" +# +# +# Table false +# Type "users" +# TypeInstance "" +# Values "HOST-RESOURCES-MIB::hrSystemNumUsers.0" +# +# +# Table true +# Type "if_octets" +# TypeInstanceOID "IF-MIB::ifDescr" +# #TypeInstancePrefix "port" +# Values "IF-MIB::ifInOctets" "IF-MIB::ifOutOctets" +# #FilterOID "IF-MIB::ifOperStatus" +# #FilterValues "1", "2" +# +# +# Table true +# Type "if_octets" +# Plugin "interface" +# PluginInstanceOID "IF-MIB::ifDescr" +# Values "IF-MIB::ifInOctets" "IF-MIB::ifOutOctets" +# +# +# +# Address "192.168.0.2" +# Version 1 +# Community "community_string" +# Collect "std_traffic" +# Interval 120 +# Timeout 10 +# Retries 1 +# +# +# Address "192.168.0.42" +# Version 2 +# Community "another_string" +# Collect "std_traffic" "hr_users" +# +# +# Address "192.168.0.3" +# Version 1 +# Community "more_communities" +# Collect "powerplus_voltge_input" +# Interval 300 +# Timeout 5 +# Retries 5 +# +# + +# +# +# Plugin "memory" +# Type "memory" +# TypeInstance "free" +# OIDs "1.3.6.1.4.1.2021.4.6.0" +# +# +# IndexOID "IF-MIB::ifIndex" +# SizeOID "IF-MIB::ifNumber" +# +# +# Source "PluginInstance" +# +# Plugin "interface" +# OIDs "IF-MIB::ifDescr" +# +# +# Plugin "interface" +# Type "if_octets" +# TypeInstance "" +# OIDs "IF-MIB::ifInOctets" "IF-MIB::ifOutOctets" +# +#
+#
+ +# +# Host "::" +# Port "8125" +# DeleteCounters false +# DeleteTimers false +# DeleteGauges false +# DeleteSets false +# CounterSum false +# TimerPercentile 90.0 +# TimerPercentile 95.0 +# TimerPercentile 99.0 +# TimerLower false +# TimerUpper false +# TimerSum false +# TimerCount false +# + +{% if enable_swap == true %} + + ReportByDevice false + ReportBytes true + ValuesAbsolute true + ValuesPercentage true + ReportIO true + +{% endif %} + +{% if enable_prometheus == true %} + + Port "{{ prometheus_port }}" + + +{% endif %} + +# +# Listen "127.0.0.1" "6666" +# BufferSize 1024 +# BufferLength 10 +# RegexFilter "regex" +# + +# +# Connection "xen:///" +# RefreshInterval 60 +# Domain "name" +# ReportBlockDevices true +# ReportNetworkInterfaces true +# BlockDevice "name:device" +# BlockDeviceFormat target +# BlockDeviceFormatBasename false +# InterfaceDevice "name:device" +# IgnoreSelected false +# HostnameFormat name +# HostnameMetadataXPath "/instance/name/text()" +# HostnameMetadataNS "http://openstack.org/xmlns/libvirt/nova/1.0" +# InterfaceFormat name +# PluginInstanceFormat name +# Instances 1 +# ExtraStats "cpu_util disk disk_err domain_state fs_info job_stats_background pcpu perf vcpu vcpupin disk_physical disk_allocation disk_capacity memory" +# PersistentNotification false +# + +# +# Verbose false +# diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..c491f20 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for geekoops-collectd \ No newline at end of file diff --git a/vars/openSUSE Leap_15.2.yml b/vars/openSUSE Leap_15.2.yml new file mode 100644 index 0000000..54841fb --- /dev/null +++ b/vars/openSUSE Leap_15.2.yml @@ -0,0 +1,3 @@ +--- +packages: ['collectd'] +collectd_service: "collectd"