add prometheus role
This commit is contained in:
8
roles/prometheus/molecule/default/converge.yml
Normal file
8
roles/prometheus/molecule/default/converge.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
|
||||
roles:
|
||||
- role: genlab.prometheus
|
||||
config_source_dir: prometheus
|
||||
alertrules_source_dir: prometheus/rules
|
||||
27
roles/prometheus/molecule/default/molecule.yml
Normal file
27
roles/prometheus/molecule/default/molecule.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
|
||||
driver:
|
||||
name: docker
|
||||
|
||||
platforms:
|
||||
- name: ubuntu
|
||||
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest
|
||||
pre_build_image: true
|
||||
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
cgroupns_mode: host
|
||||
privileged: true
|
||||
|
||||
provisioner:
|
||||
name: ansible
|
||||
|
||||
verifier:
|
||||
name: ansible
|
||||
|
||||
lint: |
|
||||
set -e
|
||||
yamllint .
|
||||
ansible-lint .
|
||||
14
roles/prometheus/molecule/default/prometheus/prometheus.yml
Normal file
14
roles/prometheus/molecule/default/prometheus/prometheus.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
global:
|
||||
scrape_interval: 15s
|
||||
evaluation_interval: 15s
|
||||
|
||||
rule_files:
|
||||
- /etc/prometheus/conf/alertules.yml
|
||||
# - "first.rules"
|
||||
# - "second.rules"
|
||||
|
||||
scrape_configs:
|
||||
- job_name: prometheus
|
||||
static_configs:
|
||||
- targets: ['localhost:9090']
|
||||
@@ -0,0 +1,13 @@
|
||||
groups:
|
||||
- name: example
|
||||
labels:
|
||||
team: myteam
|
||||
rules:
|
||||
- alert: HighRequestLatency
|
||||
expr: job:request_latency_seconds:mean5m{job="myjob"} > 0.5
|
||||
for: 10m
|
||||
keep_firing_for: 5m
|
||||
labels:
|
||||
severity: page
|
||||
annotations:
|
||||
summary: High request latency
|
||||
55
roles/prometheus/molecule/default/verify.yml
Normal file
55
roles/prometheus/molecule/default/verify.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
---
|
||||
- name: Verify
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
any_errors_fatal: true
|
||||
|
||||
tasks:
|
||||
|
||||
- name: "Include default vars"
|
||||
ansible.builtin.include_vars:
|
||||
dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/"
|
||||
extensions: [ 'yml' ]
|
||||
|
||||
- name: "Check if Prometheus is installed"
|
||||
changed_when: false
|
||||
ansible.builtin.command: "prometheus --version"
|
||||
register: prom_installed_version
|
||||
|
||||
- name: "Check Prometheus version"
|
||||
ansible.builtin.assert:
|
||||
that: "prom_installed_version.stdout is regex('{{ prometheus_version }}')"
|
||||
success_msg: "Prometheus version {{ prometheus_version }} is installed and working"
|
||||
fail_msg: "Prometheus version {{ prometheus_version }} is not installed or not working correctly"
|
||||
|
||||
# kics-scan ignore-block
|
||||
- name: "Check if Prometheus is reachable"
|
||||
ansible.builtin.uri:
|
||||
url: "http://localhost:9090/-/healthy"
|
||||
return_content: true
|
||||
status_code: 200
|
||||
method: GET
|
||||
body_format: json
|
||||
register: prom_health
|
||||
|
||||
- name: "Debug Prometheus health status"
|
||||
ansible.builtin.assert:
|
||||
that: "prom_health.content | trim == 'Prometheus Server is Healthy.'"
|
||||
success_msg: "Prometheus is healthy"
|
||||
fail_msg: "Prometheus is not healthy"
|
||||
|
||||
# kics-scan ignore-block
|
||||
- name: "Check if Prometheus is ready"
|
||||
ansible.builtin.uri:
|
||||
url: "http://localhost:9090/-/ready"
|
||||
return_content: true
|
||||
status_code: 200
|
||||
method: GET
|
||||
body_format: json
|
||||
register: prom_ready
|
||||
|
||||
- name: "Debug Prometheus readiness status"
|
||||
ansible.builtin.assert:
|
||||
that: "prom_ready.content | trim == 'Prometheus Server is Ready.'"
|
||||
success_msg: "Prometheus is ready"
|
||||
fail_msg: "Prometheus is not ready"
|
||||
Reference in New Issue
Block a user