Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilien Kenler committed Jun 11, 2015
0 parents commit 251cf20
Show file tree
Hide file tree
Showing 12 changed files with 1,795 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Wizcorp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
127 changes: 127 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
collectd role
===============

This role takes care of adding collectd to any given server.

It can be used to:

1. Collect metrics about a machines, and optionally forward them to an aggregation machine.

2. Create an aggregation machine, which will receive the metrics from a given set of machine within the same datacenter.
In this case too, metrics can optionally be forwarded to another service.

Configuration
--------------

### For any machines

Simply add the collector role to your playbook.

By default, we will save all metrics to RRD files under `/var/lib/collectd/rrd/${hostname}`.

### For forwarding machines

#### Inventory

Normally, we put all aggregation on a single machine.
However, it is possible to decouple them, and provision separate machines for any aggregators we might have.
This example demonstrate how to create a dedicated collectd aggregator.

```ini
[collectd:children]
collectd-somedc-prod

[collectd-somedc-prod]
collectd1.somedc.prod ansible_ssh_host=10.0.1.111

[... skipping ...]
[somedc-prod:children]
collectd-somedc-prod

[somedc-prod:vars]
collectd_forwarder = collectd1.somedc.prod

#
# Optional: if you are aggregating logs with logstash
# and are using ElasticSearch and Kibana, you might
# want to also keep track of your metrics through
# Kibana. If so, simply add the following to your
# global configuration - keep in mind that
# activating this will turn off any other
# forwarding you might have configured in
# favor of sending all entries to logstash
#
logstash_forwarder = collectd2.somedc.prod

collectd_forward_to_logstash = true
```

The following may also be added to your inventory.

* `collectd_interval`: at what interval in seconds to take measurements (default: 60)
* `check_disk`: a value which we will use to select what disk to monitor (default: xvde)
* `fs_type`: the file system type to monitor (default: ext4)
* `monitor_coretemp`: set to true if you want to monitor coretemp (only useful on real hardware)

### Roles addition

It is possible for any roles to add their own custom metric collection configuration.

In `myrole/templates/collectd.conf.j2`:

```
<Plugin "whatever">
...
</Plugin>
```

Then, in `myrole/tasks/main.yml`:

```yaml
- name: Adding collectd monitoring for myrole
template: >
src=collectd.conf.j2
dest=/etc/collectd.d/myrole.conf
notify:
- Restart collectd
tags:
- myrole
- files
- collectd
```
### Execution
#### For any machines
Simply follow the standard provisioning method.
### For the collector machine
When provisioning with this role, you can also add
[Librato](https://www.librato.com/) and
[Graphite](http://graphite.wikidot.com/) support.
As you should not add any credentials to your inventory,
it should be done by using `--extra-vars` as described below.

#### Librato

```
--extra-vars="use_librato=true" \
--extra-vars="librato_email=[email protected]" \
--extra-vars="librato_token=API-KEY"
```
### Graphite
```
--extra-vars="use_graphite=true" \
--extra-vars="graphite_host=some.host.com" \
--extra-vars="graphite_port="
```
See also
--------
* [collectd](http://collectd.org/)
5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
monitor_coretemp: false
collectd_forward_to_logstash: false

use_librato: false
use_graphite: false
30 changes: 30 additions & 0 deletions files/collectd-coretemp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

cd /sys/devices/platform/coretemp.0

host=${COLLECTD_HOSTNAME:=`hostname -f`}

while
true
do
LIST=$(ls | grep temp | cut -d"_" -f1 | sort | uniq)

for f in ${LIST}
do
timestamp=$(date +%s)
label="$(cat ${f}_label)"

if
! (echo ${label} | grep -q "Core")
then
continue
fi

cpunum="$(echo ${label} | sed "s/Core //")"
value="$(cat ${f}_input)"

echo "PUTVAL \"${host}/core-temp/gauge-core_${cpunum}\" ${timestamp}:${value}"
done

sleep ${COLLECTD_INTERVAL:-10} || true
done
6 changes: 6 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: "Restart collectd"
service: >
name=collectd
state=restarted
tags:
- collectd
24 changes: 24 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
galaxy_info:
author: Marc Trudel <[email protected]>
description: This role takes care of adding collectd to any given server
company: Wizcorp K.K.
license: MIT
min_ansible_version: 1.8.1
platforms:
- name: EL
versions:
- 6
- 7
- name: Debian
versions:
- wheezy
categories:
- monitoring
dependencies:
- role: aeriscloud.repos
repositories:
centos6:
- epel
centos7:
- epel
- role: aeriscloud.yum
49 changes: 49 additions & 0 deletions tasks/centos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
- name: "Set collectd's config file destination"
set_fact: >
collectd_config_dest=/etc/collectd.conf
tags:
- collectd

- name: "Clean old packages"
yum: >
name={{ item }}
state=absent
with_items:
- collectd-python
- collectd-hddtemp
- libcollectdclient
tags:
- collectd
- pkgs

- name: "Install Ghettoforge repo"
yum: >
name=http://mirror.symnds.com/distributions/gf/el/6/gf/x86_64/gf-release-6-8.gf.el6.noarch.rpm
state=present
when: ansible_distribution_major_version|int == 6
tags:
- collectd
- pkgs
- repos

- name: "Install required packages"
yum : >
name={{ item }}
enablerepo=epel,gf-plus
state=latest
with_items: packages
when: ansible_distribution_major_version|int == 6
tags:
- collectd
- pkgs

- name: "Install required packages"
yum : >
name={{ item }}
enablerepo=epel
state=latest
with_items: packages
when: ansible_distribution_major_version|int > 6
tags:
- collectd
- pkgs
19 changes: 19 additions & 0 deletions tasks/debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- name: "Set collectd's config file destination"
set_fact: >
collectd_config_dest=/etc/collectd/collectd.conf
tags:
- collectd

- name: "Install required packages"
apt : >
name={{ item }}
state=latest
with_items:
- git
- collectd
- collectd-core
- collectd-utils
tags:
- install
- collectd
- pkgs
91 changes: 91 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
- include: centos.yml
when: ansible_distribution == "CentOS"

- include: debian.yml
when: ansible_distribution == "Debian"

#####################
# Common
- name: "Install Librato backend"
git: >
repo=https://github.com/librato/collectd-librato.git
version=v0.0.8
dest=/opt/collectd-librato/
tags:
- collectd
- pkgs
- libs

- name: "Ensure the collectd python and exec module directory exists"
file: >
path=/opt/collectd-{{ item }}-modules
state=directory
with_items:
- python
- exec
tags:
- collectd
- pkgs
- libs

- name: "Symlink the librato module into the python module directory"
file: >
src=/opt/collectd-librato/lib/collectd-librato.py
dest=/opt/collectd-python-modules/collectd-librato.py
state=link
tags:
- collectd
- libs

- name: "Install coretemp plugin for collectd"
copy: >
src=collectd-coretemp.sh
dest=/opt/collectd-exec-modules/
mode=0755
owner=root
group=root
notify:
- Restart collectd
tags:
- collectd
- files

- name: "Install /etc/collectd.conf"
template: >
src=collectd.conf.j2
dest={{ collectd_config_dest }}
mode=0644
notify:
- Restart collectd
tags:
- collectd
- files
- configs

- name: "Make sure /etc/collectd.d is present"
file: >
path=/etc/collectd.d
state=directory
tags:
- collectd
- files
- configs

- name: "Add the coretemp kernel module"
modprobe: >
name=coretemp
state=present
when: monitor_coretemp
tags:
- collectd
- files
- configs

- name: "Make sure collectd is running"
service: >
name=collectd
state=running
enabled=yes
runlevel=5
tags:
- collectd
Loading

0 comments on commit 251cf20

Please sign in to comment.