forked from sansible/prometheus_cloudwatch_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GITHUB-1] Prometheus AWS CloudWatch Exporter
- Loading branch information
Rob Goodall
committed
Dec 13, 2017
1 parent
04498ce
commit bcea862
Showing
23 changed files
with
704 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[*.{yml,md,json.j2}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## IDEs, editors, ... | ||
.DS_Store | ||
.idea | ||
.project | ||
*.bak | ||
*.iml | ||
*.sublime* | ||
*.swp | ||
/.settings | ||
|
||
|
||
|
||
|
||
# Build and Tests Artefacts | ||
*.retry | ||
/.make | ||
/.venv_* | ||
/meta/.galaxy_install_info | ||
/tests/.vagrant | ||
/tests/*.log | ||
/tests/roles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
|
||
group: stable | ||
dist: trusty | ||
|
||
language: python | ||
python: "2.7" | ||
|
||
branches: | ||
only: | ||
- develop | ||
- master | ||
|
||
env: | ||
- ANSIBLE_INSTALL_VERSION=2.0.2.0 | ||
- ANSIBLE_INSTALL_VERSION=2.1.6.0 | ||
- ANSIBLE_INSTALL_VERSION=2.2.3.0 | ||
- ANSIBLE_INSTALL_VERSION=2.3.2.0 | ||
- ANSIBLE_INSTALL_VERSION=2.4.1.0 | ||
|
||
before_install: | ||
# Make sure everything's up to date. | ||
- sudo apt-get update -qq | ||
|
||
install: | ||
# Download dependencies | ||
- make test_deps | ||
|
||
script: | ||
- make lint | ||
- make test_ansible | ||
|
||
notifications: | ||
webhooks: https://galaxy.ansible.com/api/v1/notifications/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016-2017 | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
include .make | ||
|
||
ANSIBLE_INSTALL_VERSION ?= 2.2.3.0 | ||
ANSIBLE_CONFIG ?= tests/ansible.cfg | ||
ROLE_NAME ?= $(shell basename $$(pwd)) | ||
TEST_PLAYBOOK ?= test.yml | ||
VAGRANT_BOX ?= ubuntu/trusty64 | ||
PATH := $(PWD)/.venv_$(ANSIBLE_INSTALL_VERSION)/bin:$(shell printenv PATH) | ||
SHELL := env PATH=$(PATH) /bin/bash | ||
|
||
.DEFAULT_GOAL := help | ||
.PHONY: help | ||
|
||
export ANSIBLE_CONFIG | ||
export PATH | ||
export VAGRANT_BOX | ||
export TEST_PLAYBOOK | ||
|
||
all: test clean | ||
|
||
## Run tests on any file change | ||
watch: test_deps | ||
while sleep 1; do \ | ||
find defaults/ handlers/ meta/ tasks/ templates/ tests/test.yml \ | ||
| entr -d make lint vagrant; \ | ||
done | ||
|
||
## Run tests | ||
test: lint test_deps vagrant | ||
|
||
## Install test dependencies | ||
test_deps: .venv_$(ANSIBLE_INSTALL_VERSION) tests/roles | ||
|
||
tests/roles: | ||
mkdir -p tests/roles | ||
ln -s ../.. tests/roles/sansible.$(ROLE_NAME) | ||
ansible-galaxy install -p tests/roles -r tests/local_requirements.yml --ignore-errors | ||
|
||
## ! Executes Ansible tests using local connection | ||
# run it ONLY from within a test VM. | ||
# If you want to test this role, run `make test` instead. | ||
# Example: make test_ansible | ||
# make test_ansible TEST_PLAYBOOK=test-something-else.yml | ||
test_ansible: test_ansible_build test_ansible_configure | ||
cd tests && ansible-playbook \ | ||
--inventory inventory \ | ||
--connection local \ | ||
--tags assert \ | ||
$(TEST_PLAYBOOK) | ||
|
||
## ! Executes Ansible tests using local connection | ||
# run it ONLY from witinh a test VM. | ||
# Example: make test_ansible_build | ||
# make test_ansible_build TEST_PLAYBOOK=test-something-else.yml | ||
test_ansible_%: | ||
cd tests && ansible-playbook \ | ||
--inventory inventory \ | ||
--connection local \ | ||
--tags=$(subst test_ansible_,,$@) \ | ||
$(TEST_PLAYBOOK) | ||
cd tests && ansible-playbook \ | ||
--inventory inventory \ | ||
--connection local \ | ||
--tags=$(subst test_ansible_,,$@) \ | ||
$(TEST_PLAYBOOK) \ | ||
| grep -q 'changed=0.*failed=0' \ | ||
&& (echo 'Idempotence test: pass' && exit 0) \ | ||
|| (echo 'Idempotence test: fail' && exit 1) | ||
|
||
## Start and (re)provisiom Vagrant test box | ||
vagrant: | ||
cd tests && vagrant up --no-provision | ||
cd tests && vagrant provision | ||
@echo "- - - - - - - - - - - - - - - - - - - - - - -" | ||
@echo " Provisioning Successful" | ||
@echo "- - - - - - - - - - - - - - - - - - - - - - -" | ||
|
||
## Execute simple Vagrant command | ||
# Example: make vagrant_ssh | ||
# make vagrant_halt | ||
vagrant_%: | ||
cd tests && vagrant $(subst vagrant_,,$@) | ||
|
||
## Installs a virtual environment and all python dependencies | ||
.venv_%: | ||
virtualenv .venv_$(ANSIBLE_INSTALL_VERSION) | ||
.venv_$(ANSIBLE_INSTALL_VERSION)/bin/pip install -r requirements.txt --ignore-installed | ||
.venv_$(ANSIBLE_INSTALL_VERSION)/bin/pip install ansible==$(ANSIBLE_INSTALL_VERSION) | ||
virtualenv --relocatable .venv_$(ANSIBLE_INSTALL_VERSION) | ||
|
||
## lint Ansible files | ||
lint: .venv_$(ANSIBLE_INSTALL_VERSION) | ||
find defaults/ handlers/ meta/ tasks/ templates/ -name "*.yml" | xargs -I{} ansible-lint {} | ||
|
||
## Prints this help | ||
help: | ||
@awk -v skip=1 \ | ||
'/^##/ { sub(/^[#[:blank:]]*/, "", $$0); doc_h=$$0; doc=""; skip=0; next } \ | ||
skip { next } \ | ||
/^#/ { doc=doc "\n" substr($$0, 2); next } \ | ||
/:/ { sub(/:.*/, "", $$0); printf "\033[34m%-30s\033[0m\033[1m%s\033[0m %s\n\n", $$0, doc_h, doc; skip=1 }' \ | ||
$(MAKEFILE_LIST) | ||
|
||
## Removes all downloaded dependencies | ||
clean: | ||
rm -rf .venv_* | ||
rm -rf tests/roles | ||
cd tests && (vagrant destroy || echo "skipping vagrant destroy") | ||
|
||
.make: | ||
touch .make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,77 @@ | ||
# prometheus_cloudwatch_exporter | ||
|
||
Master: [![Build Status](https://travis-ci.org/sansible/prometheus_cloudwatch_exporter.svg?branch=master)](https://travis-ci.org/sansible/prometheus_cloudwatch_exporter) | ||
Develop: [![Build Status](https://travis-ci.org/sansible/prometheus_cloudwatch_exporter.svg?branch=develop)](https://travis-ci.org/sansible/prometheus_cloudwatch_exporter) | ||
|
||
* [ansible.cfg](#ansible-cfg) | ||
* [Installation and Dependencies](#installation-and-dependencies) | ||
* [Tags](#tags) | ||
* [Examples](#examples) | ||
|
||
This role installs Prometheus AWS CloudWatch Exporter. | ||
|
||
Prometheus AWS CloudWatch Exporter makes available AWS CloudWatch metrics for collection by Prometheus server. | ||
|
||
For more information about Prometheus AWS CloudWatch Exporter please visit: | ||
[http://github.com/prometheus/cloudwatch_exporter](https://github.com/prometheus/cloudwatch_exporter). | ||
|
||
For more information about Prometheus Server please visit: | ||
[https://prometheus.io](https://prometheus.io). | ||
|
||
|
||
## ansible.cfg | ||
|
||
This role is designed to work with merge "hash_behaviour". Make sure your | ||
ansible.cfg contains these settings | ||
|
||
```INI | ||
[defaults] | ||
hash_behaviour = merge | ||
``` | ||
|
||
## Installation and Dependencies | ||
|
||
This role will install `sansible.users_and_groups` for managing `prometheus_cloudwatch_exporter` user | ||
and `sansible.java` to install Java, which the Prometheus AWS CloudWatch Exporter requires to run. | ||
|
||
To install run `ansible-galaxy install sansible.prometheus_cloudwatch_exporter` or add this to your | ||
`roles.yml`. | ||
|
||
```YAWL | ||
- name: sansible.prometheus_cloudwatch_exporter | ||
version: v1.0 | ||
``` | ||
|
||
and run `ansible-galaxy install -p ./roles -r roles.yml` | ||
|
||
|
||
## Tags | ||
|
||
This role uses tags: **build** and **configure** | ||
|
||
* `build` - Installs Prometheus AWS CloudWatch Exporter and all it's dependencies. | ||
* `configure` - Configures Prometheus AWS CloudWatch Exporter. | ||
|
||
|
||
## Examples | ||
|
||
Simply include the role in your playbook. | ||
|
||
Default exporter port: 9106 | ||
|
||
```YAML | ||
- name: Install and configure prometheus_cloudwatch_exporter | ||
hosts: "somehost" | ||
|
||
roles: | ||
- role: sansible.prometheus_cloudwatch_exporter | ||
sansible_prometheus_cloudwatch_exporter: | ||
config: | ||
region: eu-west-1 | ||
metrics: | ||
- aws_namespace: AWS/ELB | ||
aws_metric_name: RequestCount | ||
aws_dimensions: [AvailabilityZone, LoadBalancerName] | ||
aws_dimension_select: | ||
LoadBalancerName: [myLB] | ||
aws_statistics: [Sum] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
|
||
sansible_prometheus_cloudwatch_exporter: | ||
checksum: sha256:3ac6c88e45815e84b400c70112f6d2b942d90ec08d4db19f23533e7667837571 | ||
config: | ||
region: eu-west-1 | ||
metrics: ~ | ||
download_url: "http://search.maven.org/remotecontent?filepath=io/prometheus/cloudwatch/cloudwatch_exporter/0.4/cloudwatch_exporter-0.4-jar-with-dependencies.jar" | ||
group: prometheus | ||
opts: 9106 cloudwatch.yml | ||
path: | ||
install: /home/prometheus | ||
log: /var/log/prometheus | ||
pid: /var/run/prometheus | ||
user: prometheus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
# | ||
# Script to enable the creation of log files with the correct ownership. | ||
# | ||
DAEMON="" | ||
DAEMON_ARGS="" | ||
LOG="" | ||
|
||
usage() { echo "Usage: $0 -c <command> [ -a \"<command_arguments>\" ] -l <log_file>" 1>&2; exit 1; } | ||
|
||
|
||
while getopts ":c:a:l:" opt; do | ||
case $opt in | ||
c) | ||
DAEMON=$OPTARG | ||
;; | ||
a) | ||
DAEMON_ARGS=$OPTARG | ||
;; | ||
l) | ||
LOG=$OPTARG | ||
;; | ||
\?) | ||
echo "Invalid option: -$OPTARG" >&2 | ||
exit 1 | ||
;; | ||
:) | ||
echo "Option -$OPTARG requires an argument." >&2 | ||
exit 1 | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac | ||
done | ||
if [ ! -z "$DAEMON" ] && [ ! -z "$LOG" ]; then | ||
exec $DAEMON $DAEMON_ARGS >"$LOG" 2>&1 | ||
else | ||
usage | ||
fi | ||
exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
|
||
- name: restart prometheus cloudwatch exporter | ||
become: yes | ||
service: | ||
name: prometheus-cloudwatch-exporter | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
|
||
galaxy_info: | ||
description: "Install Prometheus CloudWatch Exporter." | ||
license: MIT | ||
min_ansible_version: 2.0 | ||
platforms: | ||
- name: Ubuntu | ||
versions: | ||
- trusty | ||
categories: | ||
- development | ||
|
||
dependencies: | ||
- role: sansible.users_and_groups | ||
users_and_groups: | ||
groups: | ||
- name: "{{ sansible_prometheus_cloudwatch_exporter.group }}" | ||
users: | ||
- name: "{{ sansible_prometheus_cloudwatch_exporter.user }}" | ||
group: "{{ sansible_prometheus_cloudwatch_exporter.group }}" | ||
|
||
- role: sansible.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ansible-lint==3.* |
Oops, something went wrong.