├── .gitignore ├── LICENSE.md ├── README.md ├── defaults └── main.yaml ├── handlers └── main.yaml ├── meta └── main.yml ├── tasks └── main.yaml └── templates ├── collectd.conf.j2 └── types.db.j2 /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/picotrading/ansible-collectd/01476d7f1bbacd8c27af557861940f7adfe1e82c/.gitignore -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Jiri Tyr 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | collectd 2 | ======== 3 | 4 | Ansible role which installs CollectD. 5 | 6 | The configuraton of the role is done in such way that it should not be necessary 7 | to change the role for any kind of configuration. All can be done either by 8 | changing role parameters or by declaring completely new configuration as a 9 | variable. That makes this role absolutely universal. See the examples below for 10 | more details. 11 | 12 | Please report any issues or send PR. 13 | 14 | 15 | Example 16 | ------- 17 | 18 | ``` 19 | --- 20 | 21 | # Example of default installation 22 | - hosts: myhost1 23 | roles: 24 | - collectd 25 | 26 | # Example of how to customize the default installation 27 | - hosts: myhost2 28 | roles: 29 | - role: collectd 30 | # Collect metrics every 60 seconds 31 | collectd_global_options_default_interval: 60 32 | # Define additional global option 33 | collectd_global_options_custom: 34 | - options: 35 | - PIDFile: /var/run/collectd.pid 36 | 37 | # Example of how to add additional plugin 38 | - hosts: myhost3 39 | roles: 40 | - role: collectd 41 | collectd_plugins_custom: 42 | # Load df plugin 43 | - options: 44 | - LoadPlugin: df 45 | # Configure the df plugin 46 | - sections: 47 | - name: Plugin 48 | param: df 49 | content: 50 | # Options of the plugin 51 | - options: 52 | - ReportInodes: true 53 | - ValuesPercentage: true 54 | # Load threshold plugin 55 | - options: 56 | - LoadPlugin: threshold 57 | # Configure the threshold plugin 58 | - sections: 59 | - name: Plugin 60 | param: threshold 61 | content: 62 | # Add threshold for df plugin 63 | - sections: 64 | - name: Plugin 65 | param: df 66 | content: 67 | - options: 68 | - Instance: root 69 | - sections: 70 | - name: Type 71 | param: percent_bytes 72 | content: 73 | - options: 74 | - Persist: true 75 | - PersistOK: true 76 | - Instance: used 77 | - WarningMax: 70 78 | - FailureMax: 80 79 | 80 | # Example of how to write completely new configuration 81 | - hosts: myhost4 82 | roles: 83 | - role: collectd 84 | # Configure the collectd.conf file from cratch 85 | collectd_config: 86 | content: 87 | - options: 88 | - Hostname: myhost4 89 | - FQDNLookup: false 90 | - Interval: 10 91 | - Timeout: 2 92 | - ReadThreads: 5 93 | - AutoLoadPlugin: false 94 | - options: 95 | - LoadPlugin: syslog 96 | - sections: 97 | - name: Plugin 98 | param: syslog 99 | content: 100 | - options: 101 | - LogLevel: info 102 | - options: 103 | - LoadPlugin: write_graphite 104 | - sections: 105 | - name: Plugin 106 | param: write_graphite 107 | content: 108 | - sections: 109 | - name: Carbon 110 | content: 111 | - options: 112 | - Host: 192.168.56.104 113 | - Port: 2003 114 | - Prefix: "collectd." 115 | - StoreRates: false 116 | - AlwaysAppendDS: false 117 | - EscapeCharacter: _ 118 | - options: 119 | - LoadPlugin: write_sensu 120 | - sections: 121 | - name: Plugin 122 | param: write_sensu 123 | content: 124 | - options: 125 | - Tag: testtag1 126 | - Attribute: 127 | - collectd_sensu_test_param1 128 | - foobar 129 | - sections: 130 | - name: Node 131 | param: localhost 132 | content: 133 | - options: 134 | - Host: 127.0.0.1 135 | - Port: 3030 136 | - StoreRates: true 137 | - AlwaysAppendDS: false 138 | - Notifications: true 139 | - MetricHandler: default 140 | - NotificationHandler: default 141 | - Separator: . 142 | - options: 143 | - LoadPlugin: df 144 | - sections: 145 | - name: Plugin 146 | param: df 147 | content: 148 | - options: 149 | - ReportInodes: true 150 | - ValuesPercentage: true 151 | - options: 152 | - LoadPlugin: cpu 153 | - LoadPlugin: disk 154 | - LoadPlugin: entropy 155 | - LoadPlugin: interface 156 | - LoadPlugin: irq 157 | - LoadPlugin: memory 158 | - LoadPlugin: processes 159 | - LoadPlugin: swap 160 | - LoadPlugin: users 161 | - LoadPlugin: vmem 162 | - options: 163 | - LoadPlugin: load 164 | - sections: 165 | - name: Plugin 166 | param: threshold 167 | content: 168 | - options: 169 | - ReportRelative: true 170 | - options: 171 | - LoadPlugin: threshold 172 | - sections: 173 | - name: Plugin 174 | param: threshold 175 | content: 176 | - sections: 177 | - name: Plugin 178 | param: df 179 | content: 180 | - options: 181 | - Instance: root 182 | - sections: 183 | - name: Type 184 | param: percent_bytes 185 | content: 186 | - options: 187 | - Persist: true 188 | - PersistOK: true 189 | - Instance: used 190 | - WarningMax: 70 191 | - FailureMax: 80 192 | 193 | # Example of how to declare custom types 194 | - hosts: myhost5 195 | roles: 196 | - role: collectd 197 | # Specify where to create the custom types.db file 198 | collectd_global_options_default_typedb_custom: /usr/share/collectd/types.db.custom 199 | # Specify the content of the file 200 | collectd_types: 201 | content: 202 | - options: 203 | # types with single datasource (value) 204 | - mybitrate: value:GAUGE:0:4294967295 205 | - mycounter: value:COUNTER:U:U 206 | # type with multiple data sources (rx, tx) 207 | - myifoctects: 208 | - rx:COUNTER:0:4294967295, 209 | - tx:COUNTER:0:4294967295 210 | ``` 211 | 212 | This role requires [Config Encoder 213 | Macros](https://github.com/picotrading/config-encoder-macros) which must be 214 | placed into the same directory as the playbook: 215 | 216 | ``` 217 | $ ls -1 *.yaml 218 | site.yaml 219 | $ git clone https://github.com/picotrading/config-encoder-macros.git ./templates/encoder 220 | ``` 221 | 222 | 223 | Role variables 224 | -------------- 225 | 226 | List of variables used by the role: 227 | 228 | ``` 229 | # Package to be installed (you can force a specific version here) 230 | collectd_pkg: collectd 231 | 232 | # List of additional plugins (e.g. collectd-python) 233 | collectd_pkg_plugins: [] 234 | 235 | # Default path to the main config file 236 | collectd_config_path: /etc/collectd.conf 237 | 238 | # Default list of custom types 239 | collectd_types: {} 240 | 241 | 242 | # Global options 243 | collectd_global_options_default_hostname: "{{ ansible_hostname }}" 244 | collectd_global_options_default_fqdnlookup: true 245 | collectd_global_options_default_interval: 10 246 | collectd_global_options_default_timeout: 2 247 | collectd_global_options_default_readthreads: 5 248 | collectd_global_options_default_autoloadplugin: false 249 | collectd_global_options_default_typesdb: "{{ 250 | [ collectd_global_options_default_typesdb_default ] + ( 251 | [ collectd_global_options_default_typesdb_custom ] 252 | if collectd_global_options_default_typesdb_custom else []) 253 | }}" 254 | 255 | collectd_global_options_default: 256 | - options: 257 | - Hostname: "{{ collectd_global_options_default_hostname }}" 258 | - FQDNLookup: "{{ collectd_global_options_default_fqdnlookup }}" 259 | - Interval: "{{ collectd_global_options_default_interval }}" 260 | - Timeout: "{{ collectd_global_options_default_timeout }}" 261 | - ReadThreads: "{{ collectd_global_options_default_readthreads }}" 262 | - AutoLoadPlugin: "{{ collectd_global_options_default_autoloadplugin }}" 263 | - TypesDB: "{{ pico_collectd_global_options_default_typesdb }}" 264 | 265 | 266 | # Syslog plugin 267 | collectd_plugins_syslog_loglevel: info 268 | 269 | collectd_plugins_syslog: 270 | - options: 271 | - LoadPlugin: syslog 272 | - sections: 273 | - name: Plugin 274 | param: syslog 275 | content: 276 | - options: 277 | - LogLevel: "{{ collectd_plugins_syslog_loglevel }}" 278 | 279 | 280 | # CPU plugin 281 | collectd_plugins_cpu: 282 | - options: 283 | - LoadPlugin: cpu 284 | 285 | 286 | # Interface plugin 287 | collectd_plugins_interface: 288 | - options: 289 | - LoadPlugin: interface 290 | 291 | 292 | # Load plugin 293 | collectd_plugins_load: 294 | - options: 295 | - LoadPlugin: load 296 | 297 | 298 | # Memory plugin 299 | collectd_plugins_memory: 300 | - options: 301 | - LoadPlugin: memory 302 | 303 | 304 | # Plugins definitions 305 | collectd_plugins_default: "{{ 306 | collectd_plugins_syslog + 307 | collectd_plugins_cpu + 308 | collectd_plugins_interface + 309 | collectd_plugins_load + 310 | collectd_plugins_memory 311 | }}" 312 | 313 | 314 | # Default list of custom global options 315 | collectd_global_options_custom: [] 316 | 317 | # Default list of custom plugins 318 | collectd_plugins_custom: [] 319 | 320 | collectd_config: 321 | content: "{{ 322 | collectd_global_options_default + 323 | collectd_global_options_custom + 324 | collectd_plugins_default + 325 | collectd_plugins_custom 326 | }}" 327 | ``` 328 | 329 | 330 | Dependencies 331 | ------------ 332 | 333 | * [Config Encoder Macros](https://github.com/picotrading/config-encoder-macros) 334 | 335 | 336 | License 337 | ------- 338 | 339 | MIT 340 | 341 | 342 | Author 343 | ------ 344 | 345 | Jiri Tyr 346 | -------------------------------------------------------------------------------- /defaults/main.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # Package to be installed (you can force a specific version here) 4 | collectd_pkg: collectd 5 | 6 | # List of additional plugins (e.g. collectd-python) 7 | collectd_pkg_plugins: [] 8 | 9 | # Default path to the main config file 10 | collectd_config_path: /etc/collectd.conf 11 | 12 | # Default list of custom types 13 | collectd_types: {} 14 | 15 | 16 | # Global options 17 | collectd_global_options_default_hostname: "{{ ansible_hostname }}" 18 | collectd_global_options_default_fqdnlookup: true 19 | collectd_global_options_default_interval: 10 20 | collectd_global_options_default_timeout: 2 21 | collectd_global_options_default_readthreads: 5 22 | collectd_global_options_default_autoloadplugin: false 23 | collectd_global_options_default_typesdb_default: /usr/share/collectd/types.db 24 | collectd_global_options_default_typesdb_custom: "" 25 | collectd_global_options_default_typesdb: "{{ 26 | [ collectd_global_options_default_typesdb_default ] + ( 27 | [ collectd_global_options_default_typesdb_custom ] 28 | if collectd_global_options_default_typesdb_custom else []) 29 | }}" 30 | 31 | collectd_global_options_default: 32 | - options: 33 | - Hostname: "{{ collectd_global_options_default_hostname }}" 34 | - FQDNLookup: "{{ collectd_global_options_default_fqdnlookup }}" 35 | - Interval: "{{ collectd_global_options_default_interval }}" 36 | - Timeout: "{{ collectd_global_options_default_timeout }}" 37 | - ReadThreads: "{{ collectd_global_options_default_readthreads }}" 38 | - AutoLoadPlugin: "{{ collectd_global_options_default_autoloadplugin }}" 39 | - TypesDB: "{{ pico_collectd_global_options_default_typesdb }}" 40 | 41 | 42 | # Syslog plugin 43 | collectd_plugins_syslog_loglevel: info 44 | 45 | collectd_plugins_syslog: 46 | - options: 47 | - LoadPlugin: syslog 48 | - sections: 49 | - name: Plugin 50 | param: syslog 51 | content: 52 | - options: 53 | - LogLevel: "{{ collectd_plugins_syslog_loglevel }}" 54 | 55 | 56 | # CPU plugin 57 | collectd_plugins_cpu: 58 | - options: 59 | - LoadPlugin: cpu 60 | 61 | 62 | # Interface plugin 63 | collectd_plugins_interface: 64 | - options: 65 | - LoadPlugin: interface 66 | 67 | 68 | # Load plugin 69 | collectd_plugins_load: 70 | - options: 71 | - LoadPlugin: load 72 | 73 | 74 | # Memory plugin 75 | collectd_plugins_memory: 76 | - options: 77 | - LoadPlugin: memory 78 | 79 | 80 | # Plugins definitions 81 | collectd_plugins_default: "{{ 82 | collectd_plugins_syslog + 83 | collectd_plugins_cpu + 84 | collectd_plugins_interface + 85 | collectd_plugins_load + 86 | collectd_plugins_memory 87 | }}" 88 | 89 | 90 | # Default list of custom global options 91 | collectd_global_options_custom: [] 92 | 93 | # Default list of custom plugins 94 | collectd_plugins_custom: [] 95 | 96 | collectd_config: 97 | content: "{{ 98 | collectd_global_options_default + 99 | collectd_global_options_custom + 100 | collectd_plugins_default + 101 | collectd_plugins_custom 102 | }}" 103 | -------------------------------------------------------------------------------- /handlers/main.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Restart collectd service 4 | service: 5 | name: collectd 6 | state: restarted 7 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | galaxy_info: 4 | author: Jiri Tyr 5 | description: Role which installs CollectD 6 | license: MIT 7 | min_ansible_version: 1.8 8 | platforms: 9 | - name: EL 10 | versions: 11 | - all 12 | categories: 13 | - monitoring 14 | dependencies: [] 15 | -------------------------------------------------------------------------------- /tasks/main.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Test distribution 4 | assert: 5 | that: ansible_os_family == "RedHat" 6 | 7 | - name: Install Collectd RPM package 8 | yum: 9 | name: "{{ collectd_pkg }}" 10 | state: present 11 | notify: 12 | - Restart collectd service 13 | tags: 14 | - collectd_pkg 15 | 16 | - name: Install additional Collectd plugin RPM package 17 | yum: 18 | name: "{{ item }}" 19 | state: present 20 | with_items: collectd_pkg_plugins 21 | notify: 22 | - Restart collectd service 23 | tags: 24 | - collectd_pkg 25 | 26 | - name: Configure CollectD 27 | template: 28 | src: collectd.conf.j2 29 | dest: "{{ collectd_config_path }}" 30 | notify: 31 | - Restart collectd service 32 | tags: 33 | - collectd_config 34 | 35 | - name: Make sure collectd service is enabled and running 36 | service: 37 | name: collectd 38 | enabled: yes 39 | state: running 40 | 41 | - name: Configure custom types.db 42 | template: 43 | src: types.db.j2 44 | dest: "{{ collectd_global_options_default_typesdb_custom }}" 45 | when: > 46 | collectd_global_options_default_typesdb_custom and 47 | collectd_types 48 | notify: 49 | - Restart collectd service 50 | tags: 51 | - collectd_config 52 | 53 | - name: Remove custom types.db file 54 | file: 55 | path: "{{ collectd_global_options_default_typesdb_custom }}" 56 | state: absent 57 | when: > 58 | collectd_global_options_default_typesdb_custom and 59 | not collectd_types 60 | notify: 61 | - Restart collectd service 62 | tags: 63 | - collectd_config 64 | -------------------------------------------------------------------------------- /templates/collectd.conf.j2: -------------------------------------------------------------------------------- 1 | # 2 | # This file is managed by Ansible. 3 | # Do not edit this file manually. 4 | # Any changes will be automatically reverted. 5 | # 6 | 7 | {% from 'templates/encoder/macros/apache_encode_macro.j2' import apache_encode with context -%} 8 | 9 | {{ apache_encode( 10 | collectd_config, 11 | convert_bools=true, 12 | convert_nums=true, 13 | quote_all_strings=true) }} 14 | -------------------------------------------------------------------------------- /templates/types.db.j2: -------------------------------------------------------------------------------- 1 | # 2 | # This file is managed by Ansible. 3 | # Do not edit this file manually. 4 | # Any changes will be automatically reverted. 5 | # 6 | 7 | {% from "templates/encoder/macros/ini_encode_macro.j2" import ini_encode with context -%} 8 | 9 | {{ ini_encode(collectd_types, delimiter=" ", section_is_comment=true) }} 10 | --------------------------------------------------------------------------------