forked from ISTI-ansible-roles/ansible-roles
Prometheus: first bits of a role.
This commit is contained in:
parent
844b9bd386
commit
c8769c3989
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
prometheus_install: True
|
||||||
|
prometheus_version: 2.0.0
|
||||||
|
prometheus_dir: 'prometheus-{{ prometheus_version }}.linux-amd64'
|
||||||
|
prometheus_file: '{{ prometheus_dir }}.tar.gz'
|
||||||
|
prometheus_download_url: 'https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/{{ prometheus_file }}'
|
||||||
|
prometheus_user: prometheus
|
||||||
|
prometheus_home: /opt/prometheus
|
||||||
|
prometheus_dist_dir: '{{ prometheus_home }}/dist'
|
||||||
|
prometheus_confdir: '/opt/prometheus/conf'
|
||||||
|
prometheus_cmd: '{{ prometheus_dist_dir }}/{{ prometheus_dir }}/prometheus'
|
||||||
|
prometheus_loglevel: info
|
||||||
|
prometheus_http_port: 9090
|
|
@ -0,0 +1,20 @@
|
||||||
|
description "Prometheus"
|
||||||
|
start on (local-filesystems and net-device-up IFACE!=lo)
|
||||||
|
stop on runlevel [016]
|
||||||
|
|
||||||
|
respawn
|
||||||
|
respawn limit 10 5
|
||||||
|
setuid prometheus
|
||||||
|
setgid prometheus
|
||||||
|
|
||||||
|
script
|
||||||
|
. /etc/default/prometheus
|
||||||
|
export GOMAXPROCS
|
||||||
|
export PROMETHEUS_CMD
|
||||||
|
export PROMETHEUS_LOGDIR
|
||||||
|
export PROMETHEUS_DATADIR
|
||||||
|
export PROMETHEUS_LOGLEVEL
|
||||||
|
export PROMETHEUS_CONF
|
||||||
|
exec $PROMETHEUS_CMD --config.file=$PROMETHEUS_CONF --storage.tsdb.path="$PROMETHEUS_DATADIR" --log.level=$PROMETHEUS_LOGLEVEL > $PROMETHEUS_LOGDIR/prometheus.log 2>&1
|
||||||
|
end script
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
- name: Restart prometheus
|
||||||
|
service: name=prometheus state=restarted
|
||||||
|
|
||||||
|
- name: Reload prometheus
|
||||||
|
service: name=prometheus state=reloaded
|
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
dependencies:
|
||||||
|
- role: '../../library/roles/nginx'
|
|
@ -0,0 +1,55 @@
|
||||||
|
---
|
||||||
|
- block:
|
||||||
|
- name: Create the user under prometheus will run
|
||||||
|
user: name={{ prometheus_user }} home={{ prometheus_home }} createhome=no shell=/usr/sbin/nologin system=yes
|
||||||
|
|
||||||
|
- name: Create the prometheus server base and conf directories
|
||||||
|
file: dest={{ item }} state=directory owner=root group=root
|
||||||
|
with_items:
|
||||||
|
- '{{ prometheus_home }}'
|
||||||
|
- '{{ prometheus_confdir }}'
|
||||||
|
- '{{ prometheus_dist_dir }}'
|
||||||
|
|
||||||
|
- name: Create the prometheus directory structure
|
||||||
|
file: dest={{ prometheus_home }}/{{ item }} state=directory owner={{ prometheus_user }} group={{ prometheus_user }}
|
||||||
|
with_items:
|
||||||
|
- data
|
||||||
|
- logs
|
||||||
|
|
||||||
|
- name: Download prometheus
|
||||||
|
get_url: url={{ prometheus_download_url }} dest=/srv/
|
||||||
|
|
||||||
|
- name: Unarchive the prometheus distribution
|
||||||
|
unarchive: src=/srv/{{ prometheus_file }} dest={{ prometheus_dist_dir }} remote_src=yes
|
||||||
|
args:
|
||||||
|
creates: '{{ prometheus_dist_dir }}/{{ prometheus_dir }}/prometheus'
|
||||||
|
notify: Restart prometheus
|
||||||
|
|
||||||
|
- name: Install the prometheus configuration
|
||||||
|
template: src=prometheus.yml.j2 dest={{ prometheus_confdir }}/prometheus.yml
|
||||||
|
notify: Reload prometheus
|
||||||
|
|
||||||
|
- name: Install the prometheus upstart script
|
||||||
|
copy: src=prometheus.upstart dest=/etc/init/prometheus.conf mode=0644 owner=root group=root
|
||||||
|
|
||||||
|
- name: Install the prometheus defaults
|
||||||
|
template: src=prometheus.default.j2 dest=/etc/default/prometheus mode=0644 owner=root group=root
|
||||||
|
|
||||||
|
- name: Ensure that prometheus is started and enabled
|
||||||
|
service: name=prometheus state=started enabled=yes
|
||||||
|
|
||||||
|
tags: prometheus
|
||||||
|
when: prometheus_install
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: Ensure that prometheus is stopped and disabled
|
||||||
|
service: name=prometheus state=stopped enabled=no
|
||||||
|
|
||||||
|
- name: Remove the prometheus init script
|
||||||
|
file: dest=/etc/init/prometheus.conf state=absent
|
||||||
|
|
||||||
|
- name: Remove all the prometheus files
|
||||||
|
file: dest={{ prometheus_home }} state=absent
|
||||||
|
|
||||||
|
tags: prometheus
|
||||||
|
when: not prometheus_install
|
|
@ -0,0 +1,8 @@
|
||||||
|
GOMAXPROCS={{ ansible_processor_vcpus }}
|
||||||
|
PROMETHEUS_CMD={{ prometheus_cmd }}
|
||||||
|
PROMETHEUS_LOGDIR={{ prometheus_home }}/logs
|
||||||
|
PROMETHEUS_DATADIR={{ prometheus_home }}/data
|
||||||
|
PROMETHEUS_LOGLEVEL={{ prometheus_loglevel }}
|
||||||
|
PROMETHEUS_CONF={{ prometheus_confdir }}/prometheus.yml
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
# my global config
|
||||||
|
global:
|
||||||
|
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
|
||||||
|
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
|
||||||
|
# scrape_timeout is set to the global default (10s).
|
||||||
|
|
||||||
|
# Alertmanager configuration
|
||||||
|
alerting:
|
||||||
|
alertmanagers:
|
||||||
|
- static_configs:
|
||||||
|
- targets:
|
||||||
|
# - alertmanager:9093
|
||||||
|
|
||||||
|
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
|
||||||
|
rule_files:
|
||||||
|
# - "first_rules.yml"
|
||||||
|
# - "second_rules.yml"
|
||||||
|
|
||||||
|
# A scrape configuration containing exactly one endpoint to scrape:
|
||||||
|
# Here it's Prometheus itself.
|
||||||
|
scrape_configs:
|
||||||
|
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
|
||||||
|
- job_name: 'prometheus'
|
||||||
|
|
||||||
|
# metrics_path defaults to '/metrics'
|
||||||
|
# scheme defaults to 'http'.
|
||||||
|
|
||||||
|
static_configs:
|
||||||
|
- targets: ['localhost:9090']
|
|
@ -0,0 +1,20 @@
|
||||||
|
---
|
||||||
|
nginx_letsencrypt_managed: True
|
||||||
|
nginx_use_common_virthost: True
|
||||||
|
nginx_virthosts:
|
||||||
|
- virthost_name: '{{ ansible_fqdn }}'
|
||||||
|
listen: '{{ http_port }}'
|
||||||
|
server_name: '{{ ansible_fqdn }}'
|
||||||
|
server_aliases: ''
|
||||||
|
index: index.html
|
||||||
|
ssl_enabled: True
|
||||||
|
ssl_only: True
|
||||||
|
ssl_letsencrypt_certs: '{{ nginx_letsencrypt_managed }}'
|
||||||
|
root: '{{ nginx_webroot }}'
|
||||||
|
server_tokens: 'off'
|
||||||
|
proxy_standard_setup: True
|
||||||
|
locations:
|
||||||
|
- location: /
|
||||||
|
target: http://localhost:{{ prometheus_http_port }}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue