feat! Add prometheus.
This commit is contained in:
parent
778efcd7ec
commit
f6ed84b8d6
@ -14,10 +14,26 @@ grafana:
|
||||
password: changeme
|
||||
port: "3001"
|
||||
|
||||
prometheus_port: "9090"
|
||||
|
||||
# Grafana and InfluxDB volumes
|
||||
#
|
||||
grafana_volume_base: "/mnt/grafana"
|
||||
grafana_setup_path: "{{ grafana_volume_base }}/config"
|
||||
grafana_volume_grafana: "{{ grafana_volume_base }}/grafana"
|
||||
grafana_volume_influxdb: "{{ grafana_volume_base }}/influxdb"
|
||||
|
||||
grafana_uid:
|
||||
grafana_gid:
|
||||
# Prometheus volumes
|
||||
#
|
||||
grafana_volume_prometheus: "{{ grafana_volume_base }}/prometheus"
|
||||
|
||||
grafana_prometheus_project: my-project
|
||||
grafana_prometheus_job_name: prometheus
|
||||
grafana_prometheus_scrape_interval: '120s'
|
||||
grafana_prometheus_targets:
|
||||
- "10.0.0.35:9100"
|
||||
- "10.0.0.35:8080"
|
||||
|
||||
|
||||
grafana_uid: "472"
|
||||
grafana_gid: "0"
|
||||
|
@ -16,6 +16,7 @@ platforms:
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
- /var/run/docker.sock:/tmp/docker_mounted.sock
|
||||
- /mnt:/mnt
|
||||
privileged: true
|
||||
pre_build_image: true
|
||||
provisioner:
|
||||
|
96
tasks/config.yml
Normal file
96
tasks/config.yml
Normal file
@ -0,0 +1,96 @@
|
||||
---
|
||||
|
||||
- name: GRAFANA | Set up main directory
|
||||
ansible.builtin.file:
|
||||
state: directory
|
||||
path: "{{ item }}"
|
||||
owner: "{{ ansible_effective_user_id }}"
|
||||
group: "{{ ansible_effective_group_id }}"
|
||||
mode: "0750"
|
||||
with_items:
|
||||
- "{{ grafana_setup_path | expanduser | realpath }}/grafana-provisioning/"
|
||||
- "{{ grafana_setup_path | expanduser | realpath }}/grafana-provisioning/datasources/"
|
||||
tags:
|
||||
- configuration
|
||||
become: true
|
||||
|
||||
- name: GRAFANA | Set up prometheus configuration directory
|
||||
ansible.builtin.file:
|
||||
state: directory
|
||||
path: "{{ item }}"
|
||||
owner: "{{ ansible_effective_user_id }}"
|
||||
group: "{{ ansible_effective_group_id }}"
|
||||
mode: "0755"
|
||||
with_items:
|
||||
- "{{ grafana_setup_path | expanduser | realpath }}/prometheus/"
|
||||
tags:
|
||||
- configuration
|
||||
become: true
|
||||
|
||||
- name: GRAFANA | Set up prometheus data directory
|
||||
ansible.builtin.file:
|
||||
state: directory
|
||||
path: "{{ item }}"
|
||||
owner: "{{ ansible_effective_user_id }}"
|
||||
group: "{{ ansible_effective_group_id }}"
|
||||
mode: "0777"
|
||||
with_items:
|
||||
- "{{ grafana_volume_prometheus | expanduser | realpath }}"
|
||||
tags:
|
||||
- configuration
|
||||
become: true
|
||||
|
||||
- name: GRAFANA | Set up influxdb mount point
|
||||
ansible.builtin.file:
|
||||
state: directory
|
||||
path: "{{ item }}"
|
||||
mode: "0750"
|
||||
with_items:
|
||||
- "{{ grafana_volume_influxdb | expanduser | realpath }}"
|
||||
tags:
|
||||
- configuration
|
||||
become: true
|
||||
|
||||
- name: GRAFANA | Set up grafana mount point
|
||||
ansible.builtin.file:
|
||||
state: directory
|
||||
path: "{{ item }}"
|
||||
owner: "{% if grafana_uid %}{{ grafana_uid }}{% else %}{{ ansible_effective_user_id }}{% endif %}"
|
||||
group: "{% if grafana_gid %}{{ grafana_gid }}{% else %}{{ ansible_effective_group_id }}{% endif %}"
|
||||
mode: "0777"
|
||||
with_items:
|
||||
- "{{ grafana_volume_grafana | expanduser | realpath }}"
|
||||
- "{{ grafana_volume_grafana | expanduser | realpath }}/plugins"
|
||||
tags:
|
||||
- configuration
|
||||
become: true
|
||||
|
||||
- name: GRAFANA | Write docker-compose configuration files
|
||||
ansible.builtin.template:
|
||||
src: "{{ item }}.j2"
|
||||
dest: "{{ grafana_setup_path | expanduser | realpath }}/{{ item }}"
|
||||
mode: '0640'
|
||||
loop:
|
||||
- "docker-compose.yml"
|
||||
- "env.grafana.conf"
|
||||
- "env.influxdb.conf"
|
||||
tags:
|
||||
- configuration
|
||||
|
||||
- name: GRAFANA | Write InfluxDB provisioning files
|
||||
ansible.builtin.template:
|
||||
src: "grafana-provisioning/datasources/{{ item }}.j2"
|
||||
dest: "{{ grafana_setup_path | expanduser | realpath }}/grafana-provisioning/datasources/{{ item }}"
|
||||
mode: '0640'
|
||||
loop:
|
||||
- "datasource.yml"
|
||||
tags:
|
||||
- configuration
|
||||
|
||||
- name: GRAFANA | Write Prometheus configuration
|
||||
ansible.builtin.template:
|
||||
src: "prometheus-provisioning/prometheus.yml.j2"
|
||||
dest: "{{ grafana_setup_path | expanduser | realpath }}/prometheus/prometheus.yml"
|
||||
mode: '0644'
|
||||
tags:
|
||||
- configuration
|
7
tasks/install.yml
Normal file
7
tasks/install.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
- name: Ensure all requested components are running.
|
||||
community.docker.docker_compose:
|
||||
project_src: "{{ grafana_setup_path | expanduser | realpath }}"
|
||||
build: false
|
||||
become: true
|
@ -1,72 +1,14 @@
|
||||
---
|
||||
# tasks file for grafana
|
||||
- name: Set up main directory
|
||||
ansible.builtin.file:
|
||||
state: directory
|
||||
path: "{{ item }}"
|
||||
owner: "{{ ansible_effective_user_id }}"
|
||||
group: "{{ ansible_effective_group_id }}"
|
||||
mode: "0750"
|
||||
with_items:
|
||||
- "{{ grafana_setup_path | expanduser | realpath }}/grafana-provisioning/"
|
||||
- "{{ grafana_setup_path | expanduser | realpath }}/grafana-provisioning/datasources/"
|
||||
tags:
|
||||
- configuration
|
||||
become: true
|
||||
|
||||
- name: Set up influxdb mount point
|
||||
ansible.builtin.file:
|
||||
state: directory
|
||||
path: "{{ item }}"
|
||||
owner: "{% if grafana_uid %}{{ grafana_uid }}{% else %}{{ ansible_effective_user_id }}{% endif %}"
|
||||
group: "{% if grafana_gid %}{{ grafana_gid }}{% else %}{{ ansible_effective_group_id }}{% endif %}"
|
||||
mode: "0750"
|
||||
with_items:
|
||||
- "{{ grafana_volume_influxdb | expanduser | realpath }}"
|
||||
- name: "GRAFANA | Configure"
|
||||
import_tasks: config.yml
|
||||
tags:
|
||||
- configuration
|
||||
become: true
|
||||
- configure
|
||||
- grafana
|
||||
|
||||
- name: Set up grafana mount point
|
||||
ansible.builtin.file:
|
||||
state: directory
|
||||
path: "{{ item }}"
|
||||
# owner: "{% if grafana_uid %}{{ grafana_uid }}{% else %}{{ ansible_effective_user_id }}{% endif %}"
|
||||
# group: "{% if grafana_gid %}{{ grafana_gid }}{% else %}{{ ansible_effective_group_id }}{% endif %}"
|
||||
owner: "472"
|
||||
group: "0"
|
||||
mode: "0777"
|
||||
with_items:
|
||||
- "{{ grafana_volume_grafana | expanduser | realpath }}"
|
||||
- "{{ grafana_volume_grafana | expanduser | realpath }}/plugins"
|
||||
- name: "GRAFANA | Install"
|
||||
import_tasks: install.yml
|
||||
tags:
|
||||
- configuration
|
||||
become: true
|
||||
|
||||
- name: Write configuration files
|
||||
ansible.builtin.template:
|
||||
src: "{{ item }}.j2"
|
||||
dest: "{{ grafana_setup_path | expanduser | realpath }}/{{ item }}"
|
||||
mode: '0640'
|
||||
loop:
|
||||
- "docker-compose.yml"
|
||||
- "env.grafana.conf"
|
||||
- "env.influxdb.conf"
|
||||
tags:
|
||||
- configuration
|
||||
|
||||
- name: Write datasource provisioning files
|
||||
ansible.builtin.template:
|
||||
src: "grafana-provisioning/datasources/{{ item }}.j2"
|
||||
dest: "{{ grafana_setup_path | expanduser | realpath }}/grafana-provisioning/datasources/{{ item }}"
|
||||
mode: '0640'
|
||||
loop:
|
||||
- "datasource.yml"
|
||||
tags:
|
||||
- configuration
|
||||
|
||||
- name: Ensure all requested components are running.
|
||||
community.docker.docker_compose:
|
||||
project_src: "{{ grafana_setup_path | expanduser | realpath }}"
|
||||
build: false
|
||||
become: true
|
||||
- install
|
||||
- grafana
|
||||
|
@ -1,7 +1,21 @@
|
||||
version: '3.9'
|
||||
services:
|
||||
prometheus:
|
||||
image: prom/prometheus:latest
|
||||
container_name: monitoring_prometheus
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- '{{ grafana_setup_path | expanduser | realpath }}/prometheus:/etc/prometheus'
|
||||
- '{{ grafana_volume_prometheus | expanduser | realpath }}:/prometheus'
|
||||
ports:
|
||||
{% if prometheus_port is defined %}- "{{ prometheus_port }}:9090"{% endif %}
|
||||
|
||||
networks:
|
||||
- grafana
|
||||
|
||||
influxdb:
|
||||
image: influxdb:latest
|
||||
container_name: monitoring_influxdb
|
||||
restart: always
|
||||
ports:
|
||||
- '{{ influxdb.port }}:8086'
|
||||
@ -14,6 +28,7 @@ services:
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana-oss:latest
|
||||
container_name: monitoring_grafana
|
||||
restart: always
|
||||
ports:
|
||||
- '{{ grafana.port }}:3000'
|
||||
@ -22,14 +37,11 @@ services:
|
||||
- "{{ grafana_setup_path | expanduser | realpath }}/grafana-provisioning/:/etc/grafana/provisioning/"
|
||||
depends_on:
|
||||
- influxdb
|
||||
- prometheus
|
||||
env_file:
|
||||
- "{{ grafana_setup_path | expanduser | realpath }}/env.grafana.conf"
|
||||
networks:
|
||||
- grafana
|
||||
|
||||
# Run as user:
|
||||
# owner: "{% if grafana_uid %}{{ grafana_uid }}{% else %}{{ ansible_effective_user_id }}{% endif %}"
|
||||
# group: "{% if grafana_gid %}{{ grafana_gid }}{% else %}{{ ansible_effective_group_id }}{% endif %}"
|
||||
|
||||
networks:
|
||||
grafana: {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
lines (14 sloc) 345 Bytes
|
||||
---
|
||||
apiVersion: 1
|
||||
datasources:
|
||||
- name: InfluxDB
|
||||
|
36
templates/prometheus-provisioning/prometheus.yml.j2
Normal file
36
templates/prometheus-provisioning/prometheus.yml.j2
Normal file
@ -0,0 +1,36 @@
|
||||
# my global config
|
||||
global:
|
||||
scrape_interval: 120s # By default, scrape targets every 15 seconds.
|
||||
evaluation_interval: 120s # By default, scrape targets every 15 seconds.
|
||||
# scrape_timeout is set to the global default (10s).
|
||||
|
||||
# Attach these labels to any time series or alerts when communicating with
|
||||
# external systems (federation, remote storage, Alertmanager).
|
||||
external_labels:
|
||||
monitor: "{{ grafana_prometheus_project }}"
|
||||
|
||||
# Load and evaluate rules in this file every 'evaluation_interval' seconds.
|
||||
rule_files:
|
||||
# - "alert.rules"
|
||||
# - "first.rules"
|
||||
# - "second.rules"
|
||||
|
||||
# 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: "{{ grafana_prometheus_job_name }}"
|
||||
|
||||
# Override the global default and scrape targets from this job every 5 seconds.
|
||||
scrape_interval: "{{ grafana_prometheus_scrape_interval }}"
|
||||
|
||||
# metrics_path defaults to '/metrics'
|
||||
# scheme defaults to 'http'.
|
||||
|
||||
static_configs:
|
||||
- targets:
|
||||
- 'localhost:9090'
|
||||
{% for target in grafana_prometheus_targets %}
|
||||
- "{{ target }}""
|
||||
{% endfor %}
|
||||
|
@ -1,2 +1,2 @@
|
||||
---
|
||||
# vars file for grafana
|
||||
# vars file for grafana
|
||||
|
Loading…
Reference in New Issue
Block a user