Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for systemd based OSes #46

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a045fdb
Bunch of changes, cleaning up the entire role and making it more gene…
stefanhorning Jun 8, 2017
c586bab
Added travis.yml, testruns and specs
stefanhorning Jun 8, 2017
2b708bf
Readme update and testrun fix
stefanhorning Jun 8, 2017
1a81ed6
Further cleanup. Guard against undfined variables in config template
stefanhorning Jun 8, 2017
624c5c2
Fix default value for telegraf_tags
stefanhorning Jun 8, 2017
11788ce
More cleanup and fixes
stefanhorning Jun 8, 2017
541feff
Update spec
stefanhorning Jun 8, 2017
dd78091
Fixed default/example values for instrumental
stefanhorning Jun 8, 2017
9c397a8
Removed a bunch of commented lines in the config template
stefanhorning Jun 8, 2017
3ca1883
Additional config features for tagdrop and tagpass, possible options …
stefanhorning Jun 8, 2017
6f7dc0d
Nicer indentation for config file
stefanhorning Jun 8, 2017
43e17f4
Change flush interval from 30 to 20s
stefanhorning Jun 9, 2017
f9ecbb9
README
stefanhorning Jun 9, 2017
470ff9f
Ensuring all plays are run with privilege escalation.
stefanhorning Jul 13, 2017
bcc3bea
Added feature to overwrite with you own telegraf build (for instance …
stefanhorning Jul 27, 2017
02bff5b
Force overwrite binary when overwrite tasks runs
stefanhorning Jul 27, 2017
65ec851
Guard binary replacing task with stop and start service arround it.
stefanhorning Jul 28, 2017
bacc5e5
Don't run the apt package install if install url for custom binary is…
stefanhorning Dec 8, 2017
5aeddef
Fix python before travis build to avoid red builds when pulling teleg…
stefanhorning Dec 8, 2017
c84859c
Added comment to travis.yml to explain install of extra python packages
stefanhorning Dec 8, 2017
5486b7b
Final fix to install problems on older Ubuntus (python TLS issues)
stefanhorning Dec 13, 2017
aaf4dc6
Drop in templates in favour of which also works in Python3.
stefanhorning Jan 23, 2018
af6bd4d
Cleaned up template files to make it much shorter and contain less no…
stefanhorning Feb 23, 2018
9cb801b
Merge pull request #1 from mediapeers/cleanup_template_file
stefanhorning Feb 23, 2018
cdfc8a3
Removed workarround tasks for Ubuntu 14.04 again as they seem to fail…
stefanhorning Mar 6, 2018
c150622
Replaced deprecated include statements
stefanhorning Apr 12, 2018
97b7912
Merge pull request #2 from mediapeers/remove_deprecations
stefanhorning Apr 12, 2018
4696772
Replaced forgotten includes with new syntax
stefanhorning Apr 13, 2018
54926ff
Merge pull request #3 from mediapeers/remove_deprecations_2
stefanhorning Apr 13, 2018
07e56dc
Simplified RedHat install
stefanhorning May 23, 2018
a00ab29
Moved telegraf flush settings from vars to defaults to easily set the…
stefanhorning May 24, 2018
0d9a6e5
Travis updates
stefanhorning Aug 31, 2018
7d5d1f9
Added feature to provide own config file directly. Cleanup in handlers
stefanhorning Sep 10, 2018
6743427
Added conditional to task for custom config file
stefanhorning Sep 10, 2018
ecd1e63
Idemp. test
stefanhorning Sep 10, 2018
8fd45c9
Idemp. test
stefanhorning Sep 10, 2018
b298237
Fixed issues with filenaming of custom config file.
stefanhorning Sep 10, 2018
7c7ec66
fix service check for systemd based OSes
Apr 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
*#
*~
venv/
.vagrant/
*deb
*rpm
playbooks/
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Logs #
######################
*.log
# Artifacts #
######################
*.retry
*.vault_pass
# Ansible #
######################
roles/
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format documentation
45 changes: 45 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
sudo: required
dist: xenial

language: python
python: "2.7"

# Install pip package manager
addons:
apt:
packages:
- python-pip

install:
# Install ruby and serverspec gem as root (used for test run later)
- sudo apt-get install -y ruby
- sudo ruby -v
- sudo gem install serverspec

# Install ansible
- pip install ansible
- ansible --version

# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' > ansible.cfg

script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
# Real run:
- ansible-playbook tests/test.yml -i tests/inventory --connection=local
# Second run to check for indempotence:
# Allowing 1 'change' for status read.
- >
ansible-playbook tests/test.yml -i tests/inventory --connection=local
| grep -q 'changed=1.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Run serverspec
- sudo rake spec
# Output result of config file (only non commented lines)
- sed '/ *#/d; /^ *$/d' /etc/telegraf/telegraf.conf

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
83 changes: 46 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,65 @@
Telegraf
========
[![Build Status](https://travis-ci.com/mediapeers/ansible-role-telegraf.svg?branch=master)](https://travis-ci.com/mediapeers/ansible-role-telegraf)

An Ansible role to install, configure, and manage [Telegraf](https://github.com/influxdb/telegraf), the plugin-driven server agent for reporting metrics into InfluxDB.

Requirements
------------
# Ansible role for Telegraf

Prior knowledge/experience with InfluxDB and Telegraf is highly recommended. Full documentation is available [here](https://docs.influxdata.com).
An Ansible role to install, configure, and manage [Telegraf](https://github.com/influxdb/telegraf), the plugin-driven server agent for reporting metrics into InfluxDB.

Installation
------------
Note: this is a fork of https://github.com/rossmcdonald/telegraf

Either clone this repository, or install through Ansible Galaxy directly using the command:
## Requirements

```
ansible-galaxy install rossmcdonald.telegraf
```
Linux server (Debian/RedHat based), place to send the events too.
Prior knowledge/experience with InfluxDB and Telegraf is highly recommended. See output plugins [here](https://github.com/influxdata/telegraf#output-plugins).

Role Variables
--------------
## Role Variables

The high-level variables are stored in the `defaults/main.yml` file. The most important ones being:

```
# Channel of Telegraf to install (currently only 'stable' is supported)
telegraf_install_version: stable
```
- `telegraf_output_plugins` - A list of dictionaries to configure your ouput plugins, for instance to influxdb or other destinations.
- `telegraf_input_plugins` - A list dictionaries to configure the metrics you want to collect. Either system metrics from the host the agent runs on or metrics of some services, DBs etc.
- `telegraf_custom_config_file` - A path to a file that contains (additional) telegraf config (can be a Jinja2 template too).

For more params see `defaults/main.yml`.

More advanced configuration options are stored in the `vars/main.yml` file, which includes all of the necessary bells and whistles to tweak your configuration.

Dependencies
------------
## Dependencies

No other Ansible dependencies are required. This role was tested and developed with Ansible 1.9.4.

Example Playbook
----------------

An example playbook is included in the `test.yml` file. There is also a `Vagrantfile`, which can be used for quick local testing leveraging [Vagrant](https://www.vagrantup.com/).

Contributions and Feedback
--------------------------

Any contributions are welcome. For any bugs or feature requests, please open an issue through Github.

License
-------
## Example Playbook

Example playbook using this role:

- name: My Play with Telegraf
hosts: servers
vars:
telegraf_output_plugins:
- name: instrumental
options:
api_token: "abc-1234"
prefix: ""
template: "measurement.host.system_measurement_tag.tags.field"
timeout: "2s"
debug: false
telegraf_input_plugins:
- name: cpu
options:
key: "value"
tags:
key: "value"
tagdrop:
key: "value"
tagpass:
key: "value"
roles:
- mediapeers.telegraf


## License

MIT

Author
------

Created by [Ross McDonald](https://github.com/rossmcdonald).
## Author

Created by [Ross McDonald](https://github.com/rossmcdonald). Extended by [Stefan Horning](https://github.com/stefanhorning).
26 changes: 26 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'rake'
require 'rspec/core/rake_task'

task :spec => 'spec:all'
task :default => :spec

namespace :spec do
targets = []
Dir.glob('./spec/*_spec.rb').each do |file|
target = File.basename(file)
target = "_#{target}" if target == "default"
targets << target
end

task :all => targets
task :default => :all

targets.each do |target|
original_target = target == "_default" ? target[1..-1] : target
desc "Run serverspec tests to #{original_target}"
RSpec::Core::RakeTask.new(target.to_sym) do |t|
ENV['TARGET_HOST'] = original_target
t.pattern = "spec/*_spec.rb"
end
end
end
40 changes: 0 additions & 40 deletions Vagrantfile

This file was deleted.

104 changes: 51 additions & 53 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,67 @@
---
# Channel of Telegraf to install
telegraf_install_version: stable
# Version to install when using the RedHat play (yum/rpm package)
telegraf_rpm_version: 1.6.3-1

# Configuration Variables
telegraf_tags:
telegraf_tags: {}
telegraf_logfile: "" # emtpy means no log
telegraf_hostname: "" # empty means fall back to os.Hostname()
telegraf_omit_hostname: "false"
# Define telegraf_custom_bin_url to overwrite telegraf bin with your own build
# telegraf_custom_bin_url: 'https://download.com/location/telegraf'

telegraf_agent_interval: 10s
telegraf_round_interval: "true"
telegraf_metric_batch_size: "1000"
telegraf_metric_buffer_limit: "10000"
telegraf_flush_interval: 20s
telegraf_flush_jitter: 5s

telegraf_collection_jitter: 0s
telegraf_flush_interval: 10s
telegraf_flush_jitter: 0s
telegraf_debug: "false"
telegraf_quiet: "false"
telegraf_hostname:
telegraf_omit_hostname: "false"
telegraf_install_url:
# Define this variable if you want to provide your own config file,
# without passing plugin configs through the telegraf_input_plugins variable.
# Will be put into /etc/telegraf/telegraf.d/ config dir.
# telegraf_custom_config_file: /path/to/template/file.conf.j2

telegraf_influxdb_urls:
- http://localhost:8086
telegraf_influxdb_database: telegraf
telegraf_influxdb_precision: s
telegraf_influxdb_retention_policy: autogen
telegraf_influxdb_write_consistency: any
telegraf_influxdb_ssl_ca:
telegraf_influxdb_ssl_cert:
telegraf_influxdb_ssl_key:
telegraf_influxdb_insecure_skip_verify:
# Replace with your own plugin configurations:

telegraf_influxdb_timeout: 5s
telegraf_influxdb_username:
telegraf_influxdb_password:
telegraf_influxdb_user_agent:
telegraf_influxdb_udp_payload:
telegraf_output_plugins:
- name: influxdb
options:
urls: ["http://localhost:8086"]
database: "telegraf"
write_consistency: "any"
timeout: "10s"
- name: instrumental
options:
api_token: "dummy-project-token"
prefix: ""
template: "measurement.host.system_measurement_tag.tags.field"
timeout: "2s"
debug: false

telegraf_plugins:
- name: mem
- name: system
telegraf_input_plugins:
- name: cpu
options:
percpu: "true"
totalcpu: "true"
fielddrop:
- "time_*"
percpu: true
totalcpu: true
collect_cpu_time: false
- name: disk
options:
mountpoints:
- "/"
mount_points: ["/"]
ignore_fs: ["tmpfs", "devtmpfs", "devfs"]
name_override: "system"
tagexclude: ["fstype"]
fieldpass: ["free", "total", "used", "used_percent"]
tags:
system_measurement_tag: "disk"
- name: diskio
options:
skip_serial_number: "true"
- name: procstat
options:
exe: "influxd"
prefix: "influxdb"
- name: procstat
options:
pid_file: "/var/lib/neo4j/data/neo4j-service.pid"
prefix: "neo4j_proc"

skip_serial_number: true
- name: kernel
- name: mem
- name: processes
- name: swap
- name: system
- name: net
options:
interfaces:
- "eth0"

telegraf_influxdata_base_url: "https://repos.influxdata.com"
name_override: "system"
tags:
system_measurement_tag: "network"
tagdrop:
interface: ["all"]
Loading