Initial version

This commit is contained in:
Werner Dijkerman
2015-09-20 14:13:54 +02:00
commit 03adb259af
15 changed files with 439 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.kitchen/
.kitchen.local.yml
.idea/

19
.kitchen.yml Normal file
View File

@ -0,0 +1,19 @@
---
driver:
name: docker
provisioner:
name: ansible_playbook
ansible_yum_repo: "http://mirror.logol.ru/epel/6/x86_64/epel-release-6-8.noarch.rpm"
hosts: localhost
platforms:
- name: centos-6.6
verifier:
ruby_bindir: '/usr/bin'
suites:
- name: default
run_list:
attributes:

5
Gemfile Normal file
View File

@ -0,0 +1,5 @@
source "https://rubygems.org"
gem "test-kitchen"
gem "kitchen-docker"
gem "kitchen-ansible"

103
README.md Normal file
View File

@ -0,0 +1,103 @@
dj-wasabi.telegraf
=========
This role will install and configure telegraf.
Telegraf is an agent written in Go for collecting metrics from the system it's running on, or from other services, and writing them into InfluxDB.
Design goals are to have a minimal memory footprint with a plugin system so that developers in the community can easily add support for collecting metrics from well known services (like Hadoop, Postgres, or Redis) and third party APIs (like Mailchimp, AWS CloudWatch, or Google Analytics).
(https://github.com/influxdb/telegraf)
Requirements
------------
No requirements. (Yes, an Influxdb server somewhere on the network will help though ;-) )
Role Variables
--------------
The following parameters can be set for the Telegraf agent:
* `telegraf_agent_version`: The version of Telegraf to install. Default: `0.1.8`
* `telegraf_agent_interval`: The interval configured for sending data to the server. Default: `10`
* `telegraf_agent_debug`: Setting the Telegraf in debug mode. Default: `False`
* `telegraf_agent_utc`: Option for outputting data in UTC. Default: `True`
* `telegraf_agent_precision`: Precision to write data at. Valid values for Precision are n, u, ms, s, m, and h. Default: `s`
You can set tags for the host running telegraf:
telegraf_agent_tags:
- tag_name: some_name
tag_value: some_value
Specifying an output. The default is set to localhost, you'll have to specify the correct influxdb server:
telegraf_agent_output:
- type: influxdb
config:
- url = "http://localhost:8086"
- database = "telegraf"
The config will be printed line by line into the configuration, so you could also use:
config:
- # Print an documentation line
and it will be printed in the configuration file.
There are two properties which are the same, but are used differently. Those are:
* `telegraf_plugins_default`
* `telegraf_plugins_extra`
With the property `telegraf_plugins_default` it is set to use the default set of Telegraf plugins. You could override it with more plugins, which should be enabled at default.
telegraf_plugins_default:
- plugin: cpu
config:
- percpu = true
- plugin: disk
- plugin: io
- plugin: mem
- plugin: system
- plugin: swap
Every telegraf agent has these as an default configuration.
The 2nd parameter `telegraf_plugins_extra` can be used to add plugins specific to the servers goal. Following is an example for using this parameter for MySQL database servers:
cat group_vars/mysql_database
telegraf_plugins_extra
- plugin: mysql
config:
- servers = ["root:{{ mysql_root_password }}@tcp(localhost:3306)/"]
Dependencies
------------
No dependencies
Example Playbook
----------------
- hosts: servers
roles:
- { role: dj-wasabi.telegraf }
Test Kitchen
------------
This roles is configured to be tested with Test Kitchen. You can find on this page some more information regarding Test Kitchen: http://werner-dijkerman.nl/2015/08/20/using-test-kitchen-with-docker-and-serverspec-to-test-ansible-roles/
License
-------
BSD
Author Information
------------------
Please let me know if you have issues. Pull requests are also accepted! :-)
mail: ikben [ at ] werner-dijkerman . nl

28
defaults/main.yml Normal file
View File

@ -0,0 +1,28 @@
---
# defaults file for ansible-telegraf
telegraf_agent_version: 0.1.8
telegraf_agent_interval: 10
telegraf_agent_debug: False
telegraf_agent_utc: True
telegraf_agent_precision: s
telegraf_agent_tags:
telegraf_agent_output:
- type: influxdb
config:
- url = "http://localhost:8086"
- database = "telegraf"
telegraf_plugins_default:
- plugin: cpu
config:
- percpu = true
- plugin: disk
- plugin: io
- plugin: mem
- plugin: system
- plugin: swap
telegraf_plugins_extra:

9
handlers/main.yml Normal file
View File

@ -0,0 +1,9 @@
---
# handlers file for ansible-telegraf
- name: "Restart Telegraf"
action: service
name=telegraf
state=restarted
enabled=yes
sudo: yes

139
meta/main.yml Normal file
View File

@ -0,0 +1,139 @@
---
galaxy_info:
author: your name
description:
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)
min_ansible_version: 1.2
#
# Below are all platforms currently available. Just uncomment
# the ones that apply to your role. If you don't see your
# platform on this list, let us know and we'll get it added!
#
#platforms:
#- name: EL
# versions:
# - all
# - 5
# - 6
# - 7
#- name: GenericUNIX
# versions:
# - all
# - any
#- name: Fedora
# versions:
# - all
# - 16
# - 17
# - 18
# - 19
# - 20
# - 21
# - 22
#- name: Windows
# versions:
# - all
# - 2012R2
#- name: SmartOS
# versions:
# - all
# - any
#- name: opensuse
# versions:
# - all
# - 12.1
# - 12.2
# - 12.3
# - 13.1
# - 13.2
#- name: Amazon
# versions:
# - all
# - 2013.03
# - 2013.09
#- name: GenericBSD
# versions:
# - all
# - any
#- name: FreeBSD
# versions:
# - all
# - 8.0
# - 8.1
# - 8.2
# - 8.3
# - 8.4
# - 9.0
# - 9.1
# - 9.1
# - 9.2
#- name: Ubuntu
# versions:
# - all
# - lucid
# - maverick
# - natty
# - oneiric
# - precise
# - quantal
# - raring
# - saucy
# - trusty
# - utopic
# - vivid
#- name: SLES
# versions:
# - all
# - 10SP3
# - 10SP4
# - 11
# - 11SP1
# - 11SP2
# - 11SP3
#- name: GenericLinux
# versions:
# - all
# - any
#- name: Debian
# versions:
# - all
# - etch
# - jessie
# - lenny
# - squeeze
# - wheezy
#
# Below are all categories currently available. Just as with
# the platforms above, uncomment those that apply to your role.
#
#categories:
#- cloud
#- cloud:ec2
#- cloud:gce
#- cloud:rax
#- clustering
#- database
#- database:nosql
#- database:sql
#- development
#- monitoring
#- networking
#- packaging
#- system
#- web
dependencies: []
# List your role dependencies here, one per line.
# Be sure to remove the '[]' above if you add dependencies
# to this list.

13
tasks/Debian.yml Normal file
View File

@ -0,0 +1,13 @@
---
- name: "Fetch telegraf installation package | Debian"
action: get_url
url=http://get.influxdb.org/telegraf/telegraf-{{ telegraf_agent_version }}_amd64.deb
dest=/tmp/telegraf_{{ telegraf_agent_version }}_amd64.deb
mode=0440
- name: "Install telegraf package | Debian"
action: apt
deb=/tmp/telegraf_{{ telegraf_agent_version }}_amd64.deb
state=installed
sudo: yes

13
tasks/RedHat.yml Normal file
View File

@ -0,0 +1,13 @@
---
- name: "Fetch telegraf installation package | RedHat"
action: get_url
url=http://get.influxdb.org/telegraf/telegraf-{{ telegraf_agent_version }}-1.x86_64.rpm
dest=/tmp/telegraf_{{ telegraf_agent_version }}-1.x86_64.rpm
mode=0440
- name: "Install telegraf package | RedHat"
action: yum
name=/tmp/telegraf_{{ telegraf_agent_version }}-1.x86_64.rpm
state=installed
sudo: yes

20
tasks/main.yml Normal file
View File

@ -0,0 +1,20 @@
---
# tasks file for ansible-telegraf
- name: "Install the correct repository"
include: "RedHat.yml"
when: ansible_os_family == "RedHat"
- name: "Install the correct repository"
include: "Debian.yml"
when: ansible_os_family == "Debian"
- name: "Copy the template"
action: template
src=etc-opt-telegraf-telegraf.conf.j2
dest=/etc/opt/telegraf/telegraf.conf
owner=root
group=root
mode=644
sudo: yes
notify: "Restart Telegraf"

View File

@ -0,0 +1,52 @@
# Telegraf configuration
[tags]
{% if telegraf_agent_tags is defined and telegraf_agent_tags is iterable %}
{% for item in telegraf_agent_tags %}
{{ item.tag_name }} = "{{ item.tag_value }}"
{% endfor %}
{% endif %}
# Configuration for telegraf itself
[agent]
interval = "{{ telegraf_agent_interval }}s"
debug = {{ telegraf_agent_debug | lower }}
hostname = "{{ ansible_fqdn }}"
utc = {{ telegraf_agent_utc | lower }}
precision = "{{ telegraf_agent_precision }}"
# Configuration for influxdb server to send metrics to
[outputs]
{% if telegraf_agent_output is defined and telegraf_agent_output is iterable %}
{% for item in telegraf_agent_output %}
[outputs.{{ item.type }}]
{% for items in item.config %}
{{ items }}
{% endfor %}
{% endfor %}
{% endif %}
# PLUGINS
{% if telegraf_plugins_default is defined and telegraf_plugins_default is iterable %}
{% for item in telegraf_plugins_default %}
[{{ item.plugin }}]
{% if item.config is defined and item.config is iterable %}
{% for items in item.config %}
{{ items }}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% if telegraf_plugins_extra is defined and telegraf_plugins_extra is iterable %}
{% for item in telegraf_plugins_extra %}
[{{ item.plugin }}]
{% if item.config is defined and item.config is iterable %}
{% for items in item.config %}
{{ items }}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}

View File

@ -0,0 +1,4 @@
---
- hosts: localhost
roles:
- role: ansible-telegraf

View File

@ -0,0 +1,27 @@
require 'serverspec'
require 'spec_helper'
describe 'Telegraf Packages' do
describe package('telegraf') do
it { should be_installed }
end
end
describe 'Telegraf Services' do
describe service('telegraf') do
it { should be_enabled }
it { should be_running }
end
end
describe 'Telegraf Configuration' do
describe file('/etc/opt/telegraf/telegraf.conf') do
it { should be_file}
it { should be_owned_by 'root'}
it { should be_grouped_into 'root'}
it { should contain "[cpu]" }
it { should contain "[mem]" }
end
end

View File

@ -0,0 +1,2 @@
require 'serverspec'
set :backend, :exec

2
vars/main.yml Normal file
View File

@ -0,0 +1,2 @@
---
# vars file for .