Compare commits

..

No commits in common. "v1.1.2" and "v1.1.1" have entirely different histories.

11 changed files with 76 additions and 209 deletions

View File

@ -2,8 +2,6 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [1.1.2](https://git.laurivan.com/Dev/ansible-role-grafana/compare/v1.1.1...v1.1.2) (2023-04-12)
### [1.1.1](https://git.laurivan.com/Dev/ansible-role-grafana/compare/v1.1.0...v1.1.1) (2023-04-03)

View File

@ -1,6 +1,6 @@
# laurivan.grafana
This role installs Grafana, InfluxDB and Prometheus via Docker.
This role installs Grafana via Docker.
## Requirements
@ -19,7 +19,6 @@ grafana_volume_base: "/mnt/data/grafana"
grafana_setup_path: "{{ grafana_volume_base }}/config"
grafana_volume_grafana: "{{ grafana_volume_base }}/grafana"
grafana_volume_influxdb: "{{ grafana_volume_base }}/influxdb"
grafana_volume_prometheus: "{{ grafana_volume_base }}/prometheus"
```
You can however define specific volumes for the individual items:
@ -27,7 +26,6 @@ You can however define specific volumes for the individual items:
- `grafana_setup_path` - where the Docker compose files are placed
- `grafana_volume_grafana` - volume for the grafana docker container
- `grafana_volume_influxdb` - volume for InfluxDB
- `grafana_volume_prometheus` - volume for Prometheus.io
### InfluxDB
@ -42,25 +40,6 @@ influxdb:
admin_token: change_me
```
### Prometheus
We define Prometheus variables:
```yml
prometheus_port: "9090"
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"
```
The targets are locations (ip address + port) where Prometheus polls for new data. This can be [cadvisor](https://github.com/google/cadvisor) or [node exporter](https://github.com/prometheus/node_exporter) for example.
**Note**: Prometheus should be an internal service (i.e., empty `prometheus_port`). Hence, it doesn't have any security in place.
### Grafana
We also define several variables for grafana

View File

@ -14,26 +14,10 @@ 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"
# 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"
grafana_uid:
grafana_gid:

View File

@ -16,7 +16,6 @@ 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:

View File

@ -1,96 +0,0 @@
---
- 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

View File

@ -1,7 +0,0 @@
---
- name: Ensure all requested components are running.
community.docker.docker_compose:
project_src: "{{ grafana_setup_path | expanduser | realpath }}"
build: false
become: true

View File

@ -1,14 +1,72 @@
---
# tasks file for grafana
- name: "GRAFANA | Configure"
import_tasks: config.yml
- 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:
- configure
- grafana
- configuration
become: true
- name: "GRAFANA | Install"
import_tasks: install.yml
- 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 }}"
tags:
- install
- grafana
- configuration
become: true
- 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"
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

View File

@ -1,21 +1,7 @@
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'
@ -28,7 +14,6 @@ services:
grafana:
image: grafana/grafana-oss:latest
container_name: monitoring_grafana
restart: always
ports:
- '{{ grafana.port }}:3000'
@ -37,11 +22,14 @@ 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: {}

View File

@ -1,4 +1,4 @@
---
lines (14 sloc) 345 Bytes
apiVersion: 1
datasources:
- name: InfluxDB

View File

@ -1,36 +0,0 @@
# 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 %}

View File

@ -1,2 +1,2 @@
---
# vars file for grafana
# vars file for grafana