Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Grzybek committed Nov 9, 2017
0 parents commit 3314198
Show file tree
Hide file tree
Showing 41 changed files with 1,056 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Openstack-Ansible Telegraf
==========================

This role is used to create and manage telegraf in an openstack-ansible-based deployment.

Requirements
------------

An openstack-ansible deployment is required.

Role Variables
--------------

By default, the role does not configure any output. The available choices are Graphite / InfluxDB over AMQP or InfluxDB.

Dependencies
------------

None.

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

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: all
gather_facts: "{{ gather_facts | default(True) }}"
user: root
roles:
- { role: ansible-telegraf }
vars:
telegraf_output: amqp
telegraf_output_amqp_user: metrics
telegraf_output_amqp_password: secret # should be in user_secrets.yml
telegraf_output_amqp_server: my-mq.local
telegraf_output_amqp_vhost: /
telegraf_output_amqp_url: "amqp://{{ telegraf_output_amqp_user }}:{{ telegraf_output_amqp_password }}@{{ telegraf_output_amqp_server }}:5672/{{ telegraf_output_amqp_vhost }}"

License
-------

GPL-3+

Author Information
------------------

Mathieu GRZYBEK
51 changes: 51 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---

influxdb_repo_root: https://repos.influxdata.com
influxdb_repo_key: https://repos.influxdata.com/influxdb.key

telegraf_server_package_state: latest
cache_timeout: 600

telegraf_global_tags_dc: None
telegraf_global_tags_rack: None
telegraf_global_tags_add_node_type: false

telegraf_agent_interval: 60

telegraf_metric_batch_size: 1024
telegraf_metric_buffer_limit: 10240
telegraf_collection_jitter: 8s

telegraf_output: amqp # influxdb
telegraf_output_amqp_url: None
telegraf_output_amqp_exchange: None
telegraf_output_amqp_auth_method: PLAIN
telegraf_output_amqp_routing_tag: field
telegraf_output_amqp_data_format: graphite
telegraf_output_amqp_template: host.measurement.tags.field

telegraf_output_influxdb_targets:
- "http://localhost:8086"

telegraf_output_influxdb_database: telegraf
telegraf_output_influxdb_retention_policy:
telegraf_output_influxdb_write_consistency: any # any, one, quorum, all
telegraf_output_influxdb_timeout: 5s
telegraf_output_influxdb_username: None
telegraf_output_influxdb_password: None
telegraf_output_influxdb_user_agent: telegraf
telegraf_output_influxdb_udp_payload: 512
telegraf_output_influxdb_ssl_ca:
telegraf_output_influxdb_ssl_cert:
telegraf_output_influxdb_ssl_key:
telegraf_output_influxdb_insecure_skip_verify: false
telegraf_output_influxdb_http_proxy: None
telegraf_output_influxdb_http_headers_key: None
telegraf_output_influxdb_http_headers_value: None

telegraf_openstack_scripts:
- glance-stats.sh
- hypervisors-stats.sh
- instances-stats.sh
- neutron-stats.sh
- usage-stats.sh
7 changes: 7 additions & 0 deletions files/glance-stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /usr/bin/env bash

source /root/openrc

# Number of images in the catalog
openstack image list -c ID -f value|wc -l|awk '{print "openstack.images.available "$1,systime()}'

7 changes: 7 additions & 0 deletions files/hypervisors-stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /usr/bin/env bash

source /root/openrc

# Usage of the whole compute nodes
openstack hypervisor stats show -f shell --prefix openstack.hypervisors.usage.total.|gawk '{gsub("\"","") ; gsub("="," ") ; print $0,systime()}'

13 changes: 13 additions & 0 deletions files/instances-stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! /usr/bin/env bash

source /root/openrc

# Number of instances per tenant
for tenant in $(openstack project list --format=value|tr ' ' ':') ; do
tenant_id=$(echo $tenant|awk -F: '{print $1}')
tenant_name=$(echo $tenant|awk -F: '{print $2}')

instances=$(openstack server list --project $tenant_id --format value -c ID|wc -l)
echo "openstack.tenants.$tenant_name.instances $instances" | gawk '{print $0" "systime()}'
done

32 changes: 32 additions & 0 deletions files/neutron-stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /usr/bin/env bash

source /root/openrc

# TODO: Public IPs usage
# openstack floating ip list

# TODO: Public IPs usage per tenant
# openstack.tenants.ID.floating_ips.available
# openstack.tenants.ID.floating_ips.used

for tenant in $(openstack project list --format=value|tr ' ' ':') ; do
tenant_id=$(echo $tenant|awk -F: '{print $1}')
tenant_name=$(echo $tenant|awk -F: '{print $2}')

# Network usage rate per tenant
for net in $(openstack network list --column ID --format value --project $tenant_id) ; do
openstack ip availability show $net --format=yaml -c network_name -c total_ips -c used_ips | \
awk '{gsub(": ", "=") ; print}'| \
tr '\n' ' '| \
gawk '{print $0,systime()}' | \
perl -ne '/network_name=(\w+) total_ips=(\d+) used_ips=(\d+) (\d+)/ ; print("$1.total_ips $2 $4\n$1.used_ips $3 $4\n")' | \
perl -pe "s/^/openstack.tenants.$tenant_name.networks./"
done

# Number of security groups per tenant
echo -n openstack.tenants.$tenant_name.
openstack security group list -c Project --format value --project $tenant_id| wc -l | gawk '{print "security-groups.number "$1" "systime()}'
done



8 changes: 8 additions & 0 deletions files/usage-stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /usr/bin/env bash

source /root/openrc

# Get general usage stats (4 weeks by default)
openstack usage list --format csv | \
fgrep -v Project | \
gawk -F, '{gsub("\"","") ; print "openstack.tenants."$1".usage.instances "$2,systime()"\nopenstack.tenants."$1".usage.ram-mb-hours "$3,systime()"\nopenstack.tenants."$1".usage.cpu-hours "$4,systime()"\nopenstack.tenants."$1".usage.disks-gb-hours "$5,systime()}'
3 changes: 3 additions & 0 deletions files/user.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ansible managed
[Service]
User=root
11 changes: 11 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

- name: restart telegraf
service:
name: telegraf
state: restarted

- name: reload systemd
shell: systemctl daemon-reload
notify: restart telegraf

64 changes: 64 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
galaxy_info:
author: Mathieu GRZYBEK
description: Telegraf client installation
company: Gendarmerie Nationale

# 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: GPLv3

min_ansible_version: 2.3

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:

#
# platforms is a list of platforms, and each platform has a name and a list of versions.
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

categories:
- client
- telegraf
- monitoring
- metrics
- openstack

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
25 changes: 25 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# tasks file for metrics

- name: Gather variables for each operating system
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}.yml"
tags:
- always

- include: telegraf_pre_install.yml
tags:
- telegraf-install

- include: telegraf_install.yml
tags:
- telegraf-install

- include: telegraf_post_install.yml
tags:
- telegraf-install
15 changes: 15 additions & 0 deletions tasks/telegraf_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: Install telegraf packages
package:
name: "{{ telegraf_distro_packages }}"
state: "{{ telegraf_package_state }}"
update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}"
cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}"
register: install_packages
until: install_packages | success
retries: 5
delay: 2
tags:
- install-apt
- install-yum
- install-zypper

71 changes: 71 additions & 0 deletions tasks/telegraf_post_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
- name: Telegraf basic setup
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "root"
group: "root"
with_items:
- { src: "telegraf.conf.j2", dest: "/etc/telegraf/telegraf.conf" }
- { src: "system.conf.j2", dest: "/etc/telegraf/telegraf.d/system.conf" }
- { src: "processes.conf.j2", dest: "/etc/telegraf/telegraf.d/processes.conf" }
- { src: "cgroup.conf.j2", dest: "/etc/telegraf/telegraf.d/cgroup.conf" }
- { src: "output.conf.j2", dest: "/etc/telegraf/telegraf.d/output.conf" }
tags:
- client-config
notify:
- restart telegraf

- include: telegraf_post_install_net.yml

- name: Telegraf setup for physical hosts
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "root"
group: "root"
with_items:
- { src: "ipmi.conf.j2", dest: "/etc/telegraf/telegraf.d/ipmi.conf" }
when: ansible_virtualization_role == 'host'
tags:
- client-config
notify:
- restart telegraf

- name: Telegraf privileges on physical or haproxy hosts (systemd custom directory)
file:
path: /etc/systemd/system/telegraf.service.d
state: directory
when: ansible_virtualization_role == 'host' or inventory_hostname in groups['haproxy']
tags:
- client-config
notify:
- restart telegraf

- name: Telegraf privileges on physical or haproxy hosts (systemd custom file)
copy:
src: user.conf
dest: /etc/systemd/system/telegraf.service.d/user.conf
when: ansible_virtualization_role == 'host' or inventory_hostname in groups['haproxy']
tags:
- client-config
notify:
- reload systemd
- restart telegraf

- include: telegraf_post_install_rabbitmq.yml
when: inventory_hostname in groups['rabbitmq']

- include: telegraf_post_install_galera.yml
when: inventory_hostname in groups['galera']

- include: telegraf_post_install_haproxy.yml
when: inventory_hostname in groups['haproxy'] or inventory_hostname in groups['network_all']

- include: telegraf_post_install_utility.yml
when: inventory_hostname in groups['utility']

- include: telegraf_post_install_swift.yml
when: inventory_hostname in groups['swift-proxy_containers']

- name: Enable Telegraf at boot time
service: name=telegraf enabled=true
13 changes: 13 additions & 0 deletions tasks/telegraf_post_install_galera.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: Telegraf configuration for Galera
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "root"
group: "root"
with_items:
- { src: "mariadb.conf.j2", dest: "/etc/telegraf/telegraf.d/mariadb.conf" }
tags:
- telegraf_client-config
notify:
- restart telegraf

Loading

0 comments on commit 3314198

Please sign in to comment.