Skip to content

Commit f2784b5

Browse files
author
Mesaguy
committed
Initial Commit
0 parents  commit f2784b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2860
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.retry

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## 0.1.0
8+
9+
### Added
10+
11+
- Initial release

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Mesaguy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+581
Large diffs are not rendered by default.

defaults/main.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
# defaults file for mesaguy.prometheus
3+
4+
# General global configuration
5+
prometheus_link_etc: true
6+
prometheus_link_etc_force: false
7+
prometheus_purge_orphans: false
8+
prometheus_root_dir: '/opt/prometheus'
9+
prometheus_test_service_port: true
10+
11+
# User management
12+
prometheus_manage_group: true
13+
prometheus_manage_user: true
14+
prometheus_group: prometheus
15+
prometheus_user: prometheus
16+
17+
# When performing installations
18+
prometheus_default_unarchive_opts:
19+
- '--strip-components=1'
20+
prometheus_fallback_to_build: true
21+
prometheus_go_version: 1.10.3
22+
prometheus_software_make_command: 'go get -d && go build'
23+
prometheus_software_makefile_make_command: 'make'
24+
prometheus_software_setup_pkg_mgrs:
25+
- 'Alpine'
26+
- 'Archlinux'
27+
- 'Gentoo'
28+
29+
# When testing
30+
prometheus_software_service_test: true
31+
prometheus_always_build_from_source: false
32+
33+
# Base directories
34+
prometheus_etc_dir: '{{ prometheus_root_dir }}/etc'
35+
prometheus_exporters_dir: '{{ prometheus_root_dir }}/exporters'
36+
prometheus_go_dir: '{{ prometheus_root_dir }}/go'
37+
prometheus_log_dir: '/var/log/prometheus'
38+
prometheus_tmp_dir: '{{ prometheus_root_dir }}/tmp'
39+
prometheus_var_dir: '{{ prometheus_root_dir }}/var'

files/defaults/alertmanager.yml

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
global:
3+
# The smarthost and SMTP sender used for mail notifications.
4+
smtp_smarthost: 'localhost:25'
5+
smtp_from: '[email protected]'
6+
7+
# The root route on which each incoming alert enters.
8+
route:
9+
# The root route must not have any matchers as it is the entry point for
10+
# all alerts. It needs to have a receiver configured so alerts that do not
11+
# match any of the sub-routes are sent to someone.
12+
receiver: 'team-X-mails'
13+
14+
# The labels by which incoming alerts are grouped together. For example,
15+
# multiple alerts coming in for cluster=A and alertname=LatencyHigh would
16+
# be batched into a single group.
17+
group_by: ['alertname', 'cluster']
18+
19+
# When a new group of alerts is created by an incoming alert, wait at
20+
# least 'group_wait' to send the initial notification.
21+
# This way ensures that you get multiple alerts for the same group that start
22+
# firing shortly after another are batched together on the first
23+
# notification.
24+
group_wait: 30s
25+
26+
# When the first notification was sent, wait 'group_interval' to send a batch
27+
# of new alerts that started firing for that group.
28+
group_interval: 5m
29+
30+
# If an alert has successfully been sent, wait 'repeat_interval' to
31+
# resend them.
32+
repeat_interval: 3h
33+
34+
# All the above attributes are inherited by all child routes and can
35+
# overwritten on each.
36+
37+
# The child route trees.
38+
routes:
39+
# This routes performs a regular expression match on alert labels to
40+
# catch alerts that are related to a list of services.
41+
- match_re:
42+
service: ^(foo1|foo2|baz)$
43+
receiver: team-X-mails
44+
45+
# The service has a sub-route for critical alerts, any alerts
46+
# that do not match, i.e. severity != critical, fall-back to the
47+
# parent node and are sent to 'team-X-mails'
48+
routes:
49+
- match:
50+
severity: critical
51+
receiver: team-X-pager
52+
53+
- match:
54+
service: files
55+
receiver: team-Y-mails
56+
57+
routes:
58+
- match:
59+
severity: critical
60+
receiver: team-Y-pager
61+
62+
# This route handles all alerts coming from a database service. If there's
63+
# no team to handle it, it defaults to the DB team.
64+
- match:
65+
service: database
66+
67+
receiver: team-DB-pager
68+
# Also group alerts by affected database.
69+
group_by: [alertname, cluster, database]
70+
71+
routes:
72+
- match:
73+
owner: team-X
74+
receiver: team-X-pager
75+
76+
- match:
77+
owner: team-Y
78+
receiver: team-Y-pager
79+
80+
81+
# Inhibition rules allow to mute a set of alerts given that another alert is
82+
# firing.
83+
# We use this to mute any warning-level notifications if the same alert is
84+
# already critical.
85+
inhibit_rules:
86+
- source_match:
87+
severity: 'critical'
88+
target_match:
89+
severity: 'warning'
90+
# Apply inhibition if the alertname is the same.
91+
equal: ['alertname']
92+
93+
94+
receivers:
95+
- name: 'team-X-mails'
96+
email_configs:
97+
98+
99+
- name: 'team-X-pager'
100+
email_configs:
101+
102+
pagerduty_configs:
103+
- routing_key: <team-X-key>
104+
105+
- name: 'team-Y-mails'
106+
email_configs:
107+
108+
109+
- name: 'team-Y-pager'
110+
pagerduty_configs:
111+
- routing_key: <team-Y-key>
112+
113+
- name: 'team-DB-pager'
114+
pagerduty_configs:
115+
- routing_key: <team-DB-key>

files/defaults/jmx_exporter.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
hostPort: localhost:5555
3+
username:
4+
password:
5+
6+
rules:
7+
- pattern: ".*"

files/defaults/prometheus.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
global:
3+
scrape_interval: 15s
4+
5+
# Attach these labels to any time series or alerts when communicating with
6+
# external systems (federation, remote storage, Alertmanager).
7+
external_labels:
8+
monitor: 'codelab-monitor'
9+
10+
# A scrape configuration containing exactly one endpoint to scrape:
11+
# Here it's Prometheus itself.
12+
scrape_configs:
13+
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
14+
- job_name: 'prometheus'
15+
16+
# Override the global default and scrape targets from this job every 5 seconds.
17+
scrape_interval: 5s
18+
19+
static_configs:
20+
- targets: ['localhost:9090']

handlers/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# handlers file for mesaguy.prometheus

meta/main.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
galaxy_info:
3+
author: Mesaguy
4+
description: Installs and manages Prometheus and Prometheus exporters
5+
6+
# If the issue tracker for your role is not on github, uncomment the
7+
# next line and provide a value
8+
# issue_tracker_url: http://example.com/issue/tracker
9+
10+
license: MIT
11+
12+
min_ansible_version: 2.6.2
13+
14+
# If this a Container Enabled role, provide the minimum Ansible Container version.
15+
# min_ansible_container_version:
16+
17+
platforms:
18+
- name: Alpine
19+
versions:
20+
- all
21+
- name: ArchLinux
22+
versions:
23+
- all
24+
- name: EL
25+
versions:
26+
- 6
27+
- 7
28+
- name: Fedora
29+
versions:
30+
- 25
31+
- 26
32+
- 27
33+
- 28
34+
- name: Gentoo
35+
versions:
36+
- all
37+
- name: Ubuntu
38+
versions:
39+
- trusty
40+
- xenial
41+
- artful
42+
- bionic
43+
- cuttlefish
44+
45+
galaxy_tags:
46+
- monitoring
47+
- prometheus
48+
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
49+
# Maximum 20 tags per role.
50+
51+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
52+
# if you add dependencies to this list.
53+
dependencies: []

tasks/_build_go_source.yml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
- name: 'Make directories for {{ prometheus_software_name_version }} build'
3+
become: true
4+
file:
5+
owner: '{{ prometheus_user }}'
6+
group: '{{ prometheus_group }}'
7+
mode: 0750
8+
path: '{{ prometheus_build_directory }}'
9+
state: directory
10+
with_items:
11+
- '{{ prometheus_software_src_dir }}'
12+
- '{{ prometheus_software_build_dir }}'
13+
loop_control:
14+
loop_var: prometheus_build_directory
15+
16+
- name: 'Download and extract the {{ prometheus_software_name_version }} project source to {{ prometheus_software_build_dir }}'
17+
become: true
18+
# Certain versions of ansible break 'become_user' for 'archive' and 'get_url', supposedly fixed in 2.6.3:
19+
# become_user: '{% if ansible_version.full is version_compare("2.6.0", ">=") and ansible_version.full is version_compare("2.6.2", "<") %}root{% else %}{{ prometheus_user }}{% endif %}'
20+
# become_user: '{{ prometheus_user }}'
21+
unarchive:
22+
extra_opts: ['--strip-components=1']
23+
creates: '{{ prometheus_software_src_dir }}/*'
24+
dest: '{{ prometheus_software_src_dir }}'
25+
owner: '{{ prometheus_user }}'
26+
group: '{{ prometheus_group }}'
27+
src: '{{ prometheus_software_src_url }}'
28+
remote_src: true
29+
when: prometheus_software_src_url is match('.*(tar.gz|zip)$')
30+
31+
- name: 'Clone the {{ prometheus_software_name_version }} project source from {{ prometheus_software_src_url }} to {{ prometheus_software_src_dir }}'
32+
become: true
33+
become_user: '{{ prometheus_user }}'
34+
git:
35+
repo: '{{ prometheus_software_src_url }}'
36+
dest: '{{ prometheus_software_src_dir }}'
37+
version: '{% if prometheus_software_src_version is defined and prometheus_software_src_version %}{{ prometheus_software_src_version }}{% else %}{{ prometheus_software_version }}{% endif %}'
38+
when: prometheus_software_src_url is not match('.*(tar.gz|zip)$')
39+
40+
- name: 'Gather statistics on the file {{ prometheus_software_src_dir }}/Makefile'
41+
become: true
42+
# become_user: '{{ prometheus_user }}'
43+
stat:
44+
path: '{{ prometheus_software_src_dir }}/Makefile'
45+
register: makefile
46+
47+
- name: 'Build {{ prometheus_software_name_version }} source code with Makefile'
48+
become: true
49+
# become_user: '{{ prometheus_user }}'
50+
shell: '{{ prometheus_software_makefile_make_command }}'
51+
args:
52+
chdir: '{{ prometheus_software_src_dir }}'
53+
creates: '{{ prometheus_software_name }}'
54+
environment:
55+
GOPATH: '{{ prometheus_software_build_dir }}'
56+
GOROOT: '{{ prometheus_go_dir }}/{{ prometheus_go_version }}'
57+
PATH: '{{ ansible_env.PATH }}:{{ prometheus_go_dir }}/{{ prometheus_go_version }}/bin:{{ prometheus_software_build_dir }}/bin'
58+
when: makefile.stat.exists == True
59+
60+
- name: 'Build {{ prometheus_software_name_version }} source code without Makefile'
61+
become: true
62+
# become_user: '{{ prometheus_user }}'
63+
shell: '{{ prometheus_software_make_command }}'
64+
args:
65+
chdir: '{{ prometheus_software_src_dir }}'
66+
creates: '{{ prometheus_software_name }}'
67+
environment:
68+
GOPATH: '{{ prometheus_software_build_dir }}'
69+
GOROOT: '{{ prometheus_go_dir }}/{{ prometheus_go_version }}'
70+
PATH: '{{ ansible_env.PATH }}:{{ prometheus_go_dir }}/{{ prometheus_go_version }}/bin:{{ prometheus_software_build_dir }}/bin'
71+
when: makefile.stat.exists == False
72+
73+
- name: 'Copy {{ prometheus_software_name_version }} to {{ prometheus_software_install_dir }}'
74+
become: true
75+
copy:
76+
remote_src: true
77+
src: '{{ prometheus_software_src_dir }}/{{ prometheus_built_file }}'
78+
dest: '{{ prometheus_software_install_dir }}'
79+
mode: 0555
80+
with_items: '{% if prometheus_software_files is defined and prometheus_software_files %}{{ prometheus_software_files }}{% else %}{% set binaries = [prometheus_software_name] %}{{ binaries }}{% endif %}'
81+
loop_control:
82+
loop_var: prometheus_built_file
83+
register: prometheus_software_installation
84+
85+
- name: 'Cleanup {{ prometheus_software_build_dir }} directory from {{ prometheus_software_name_version }} build'
86+
become: true
87+
file:
88+
path: '{{ prometheus_software_build_dir }}'
89+
state: absent

0 commit comments

Comments
 (0)