add prometheus role

This commit is contained in:
Sergey Malyuk
2025-12-12 11:44:47 +03:00
parent b9e84279ce
commit cb4f2672ca
23 changed files with 407 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
roles:
- role: genlab.prometheus
config_source_dir: prometheus
alertrules_source_dir: prometheus/rules

View 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 .

View 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']

View File

@@ -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

View 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"