works, but needs to be cleaned up

This commit is contained in:
tchivert 2023-02-09 18:01:15 +01:00
parent 2c76251533
commit b49d299578
5 changed files with 203 additions and 52 deletions

View File

@ -64,3 +64,15 @@ prometheus_postgres_exporter_port: 5432
prometheus_redis_exporter_addr: "redis://localhost:6379" prometheus_redis_exporter_addr: "redis://localhost:6379"
prometheus_redis_exporter_user: "" prometheus_redis_exporter_user: ""
prometheus_redis_exporter_password: "" prometheus_redis_exporter_password: ""
## grafana
grafana_auth_anonymous_enabled: false
grafana_auth_anonymous_org_role: Editor # Viewer
grafana_auth_anonymous_org_name: 'Main Org.'
grafana_auth_disable_login_form: false
grafana_editors_can_admin: false
grafana_users_viewers_can_edit: false
grafana_log_level: error
grafana_router_logging: false
grafana_disable_sanitize_html: true

View File

@ -1,9 +1,10 @@
--- ---
- name: 'prometheus | server | restart container' - name: 'grafana-prometheus | server | restart container'
docker_container: systemd:
name: prometheus name: docker-compose@grafana-prometheus.service
restart: yes state: restarted
tags: ['prometheus'] enabled: yes
tags: ['grafana-prometheus']
- name: 'prometheus | node exporter | restart service' - name: 'prometheus | node exporter | restart service'
systemd: systemd:

View File

@ -32,33 +32,67 @@
mode: 0644 mode: 0644
tags: ['prometheus_server'] tags: ['prometheus_server']
notify: notify:
- 'prometheus | server | restart container' - 'grafana-prometheus | server | restart container'
- name: 'prometheus | server | deploy container' - name: "grafana-prometheus | create docker-compose directory"
docker_container: file:
name: prometheus path: /opt/docker-compose/grafana-prometheus
hostname: '{{ inventory_hostname }}' state: directory
image: prom/prometheus:{{ prometheus_server_version }} mode: '0755'
volumes: tags: [ 'grafana-prometheus', 'prometheus_server' ]
- /etc/prometheus/:/etc/prometheus/
- prometheus_data:/prometheus - name: "grafana-prometheus | copy docker-compose file"
command: template:
- '--config.file=/etc/prometheus/prometheus.yml' src: compose/grafana-prometheus.yml.j2
- '--storage.tsdb.path=/prometheus' dest: /opt/docker-compose/grafana-prometheus/docker-compose.yml
- '--storage.tsdb.retention.time={{ prometheus_retention_time }}' owner: root
- '--web.console.libraries=/usr/share/prometheus/console_libraries' group: root
- '--web.console.templates=/usr/share/prometheus/consoles' mode: 0644
- '--web.enable-admin-api' notify: "grafana-prometheus | server | restart container"
networks: tags: [ 'grafana-prometheus' ]
- name: '{{ prometheus_docker_network }}'
ports: - name: "grafana-prometheus | create grafana.ini file"
- "9090:9090" file:
log_driver: syslog path: /opt/docker-compose/grafana-prometheus/grafana.ini
log_options: owner: '1000'
tag: docker_prometheus group: '1000'
restart_policy: 'unless-stopped' mode: '0750'
pull: '{{ prometheus_docker_pull }}' state: touch
etc_hosts: '{{ prometheus_nodes_ip }}' notify: "grafana-prometheus | server | restart container"
tags: ['prometheus_server'] tags: [ 'grafana-prometheus' ]
notify: ignore_errors: '{{ ansible_check_mode }}'
- 'prometheus | server | restart container'
- name: "grafana-prometheus | import grafana provisioned datasources"
synchronize:
src: "{{ grafana_provisioned_datasources_path }}"
dest: /opt/docker-compose/grafana-prometheus/
when: grafana_provisioned_datasources_path is defined
notify: "grafana-prometheus | server | restart container"
tags: [ 'grafana-prometheus' ]
- name: "grafana-prometheus | import grafana provisioned dashboards"
synchronize:
src: "{{ grafana_provisioned_dashboards_path }}"
dest: /opt/docker-compose/grafana-prometheus/
when: grafana_provisioned_datasources_path is defined
notify: "grafana-prometheus | server | restart container"
tags: [ 'grafana-prometheus' ]
- name: "grafana-prometheus | install unit file to systemd"
vars:
exporter: "grafana-prometheus"
template:
src: systemd/docker-compose.service.j2
dest: /etc/systemd/system/docker-compose@grafana-prometheus.service
owner: root
group: root
mode: 0600
tags: [ 'grafana-prometheus' ]
- name: "grafana-prometheus | enable service"
systemd:
daemon_reload: yes
name: docker-compose@grafana-prometheus
enabled: true
ignore_errors: '{{ ansible_check_mode }}'
tags: [ 'grafana-prometheus' ]

View File

@ -0,0 +1,104 @@
version: "3"
networks:
grafana:
name: grafana
{% if grafana_traefik_enable is defined %}
traefik:
external: true
{% endif %}
volumes:
prometheus-data:
grafana-data:
services:
grafana:
image: grafana/grafana:{{ grafana_version | default('main') }}
container_name: grafana
user: "1000:1000"
restart: unless-stopped
volumes:
- grafana-data:/var/lib/grafana
- ./grafana.ini:/etc/grafana/grafana.ini
- ./dashboards:/etc/grafana/provisioning/dashboards/
- ./datasources:/etc/grafana/provisioning/datasources/
environment:
GF_AUTH_ANONYMOUS_ENABLED: "{{ grafana_auth_anonymous_enabled|string|lower }}"
GF_AUTH_ANONYMOUS_ORG_ROLE: "{{ grafana_auth_anonymous_org_role }}"
GF_AUTH_ANONYMOUS_ORG_NAME: "{{ grafana_auth_anonymous_org_name }}"
GF_AUTH_DISABLE_LOGIN_FORM: "{{ grafana_auth_disable_login_form|string|lower }}"
GF_AUTH_EDITORS_CAN_ADMIN: "{{ grafana_editors_can_admin|string|lower }}"
{% if grafana_admin_password is defined %}
GF_SECURITY_ADMIN_PASSWORD: "{{ grafana_admin_password }}"
{% endif %}
GF_USERS_VIEWERS_CAN_EDIT: "{{ grafana_users_viewers_can_edit|string|lower }}"
{% if grafana_admin_password is defined %}
GF_ROOT_URL: "{{ grafana_domain }}"
{% endif %}
GF_LOG_LEVEL: "{{ grafana_log_level|string }}"
GF_ROUTER_LOGGING: "{{ grafana_router_logging|string|lower }}"
GF_PANELS_DISABLE_SANITIZE_HTML: "{{ grafana_disable_sanitize_html|string|lower }}"
{% if grafana_install_plugins is defined %}
GF_INSTALL_PLUGINS: "{{ grafana_install_plugins|string|lower }}"
{% endif %}
{% if grafana_smtp_enabled is defined %}
GF_SMTP_ENABLED: "{{ grafana_smtp_enabled|string|lower }}"
GF_SMTP_HOST: "{{ grafana_smtp_host|string }}"
GF_SMTP_FROM_ADDRESS: "{{ grafana_smtp_from_address|string }}"
GF_SMTP_FROM_NAME: "{{ grafana_smtp_from_name|string }}"
GF_SMTP_SKIP_VERIFY: "{{ grafana_smtp_skip_verify|string|lower }}"
{% else %}
GF_SMTP_ENABLED: "false"
{% endif %}
networks:
- grafana
{% if grafana_traefik_enable is defined %}
- traefik
labels:
traefik.enable: true
traefik.docker.network: traefik
traefik.http.routers.grafana.rule: Host(`{{ grafana_domain|default(omit) }}`)
traefik.http.routers.grafana.tls: true
traefik.http.routers.grafana.tls.certresolver: letsencrypt
traefik.http.routers.grafana.entrypoints: websecure
traefik.http.services.grafana.loadbalancer.server.port: 3000
{% else %}
ports:
- "{{ grafana_port | default(3000) }}:3000"
{% endif %}
prometheus:
container_name: prometheus
image: prom/prometheus:{{ grafana_prometheus_version | default('latest') }}
volumes:
- /etc/prometheus/:/etc/prometheus/
- prometheus-data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time={{ prometheus_retention_time }}'
- '--web.enable-lifecycle'
networks:
- grafana
{% if grafana_traefik_enable is defined %}
- traefik
labels:
traefik.enable: true
traefik.docker.network: traefik
traefik.http.routers.prometheus.rule: Host(`{{ prometheus_domain|default(omit) }}`)
traefik.http.routers.prometheus.tls: true
traefik.http.routers.prometheus.tls.certresolver: letsencrypt
traefik.http.routers.prometheus.entrypoints: websecure
traefik.http.services.prometheus.loadbalancer.server.port: 9090
{% else %}
ports:
- "{{ prometheus_port | default(9090) }}:9090"
{% endif %}
{% if prometheus_nodes_ip is defined %}
extra_hosts:
{% for key, value in prometheus_nodes_ip.items() %}
- "{{ key }}:{{ value }}"
{% endfor %}
{% endif %}
restart: unless-stopped

View File

@ -46,8 +46,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):9100' regex: '(.*):9100'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_mysqld_exporter_targets is defined %} {% if prometheus_mysqld_exporter_targets is defined %}
# mysql exporter # # mysql exporter #
- job_name: mysql - job_name: mysql
@ -74,8 +74,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):9104' regex: '(.*):9104'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_mongodb_exporter_targets is defined %} {% if prometheus_mongodb_exporter_targets is defined %}
# mongoDB exporter # # mongoDB exporter #
- job_name: mongodb - job_name: mongodb
@ -97,8 +97,8 @@ scrape_configs:
- {{ target }}:9216 - {{ target }}:9216
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% endif %}
{% endif %}
{% if prometheus_postgres_exporter_targets is defined %} {% if prometheus_postgres_exporter_targets is defined %}
# postgresql exporter # # postgresql exporter #
- job_name: postgresql - job_name: postgresql
@ -120,8 +120,8 @@ scrape_configs:
- {{ target }}:9187 - {{ target }}:9187
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% endif %}
{% endif %}
{% if prometheus_phpfpm_exporter_targets is defined %} {% if prometheus_phpfpm_exporter_targets is defined %}
# PHP-FPM exporter # # PHP-FPM exporter #
- job_name: phpfpm - job_name: phpfpm
@ -137,8 +137,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):9253' regex: '(.*):9253'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_opcache_exporter_targets is defined %} {% if prometheus_opcache_exporter_targets is defined %}
# opcache exporter # # opcache exporter #
- job_name: opcache - job_name: opcache
@ -154,8 +154,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):9101' regex: '(.*):9101'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_apache_exporter_targets is defined %} {% if prometheus_apache_exporter_targets is defined %}
# apache exporter # # apache exporter #
- job_name: apache - job_name: apache
@ -171,8 +171,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):9117' regex: '(.*):9117'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_haproxy_exporter_targets is defined %} {% if prometheus_haproxy_exporter_targets is defined %}
# haproxy exporter # # haproxy exporter #
- job_name: haproxy - job_name: haproxy
@ -188,8 +188,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):8404' regex: '(.*):8404'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_varnish_exporter_targets is defined %} {% if prometheus_varnish_exporter_targets is defined %}
# Varnish exporter # # Varnish exporter #
- job_name: varnish - job_name: varnish
@ -205,8 +205,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):9131' regex: '(.*):9131'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_blackbox_exporter is defined %} {% if prometheus_blackbox_exporter is defined %}
# blackbox # # blackbox #
{% if prometheus_blackbox_exporter_http is defined %} {% if prometheus_blackbox_exporter_http is defined %}
@ -250,8 +250,8 @@ scrape_configs:
- target_label: __address__ - target_label: __address__
replacement: {{ prometheus_blackbox_exporter_host }}:9115 replacement: {{ prometheus_blackbox_exporter_host }}:9115
{% endif %} {% endif %}
{% endif %}
{% endif %}
{% if prometheus_redis_multi_instances_exporter_targets is defined %} {% if prometheus_redis_multi_instances_exporter_targets is defined %}
# Redis exporter # # Redis exporter #
- job_name: 'redis_exporter_targets' - job_name: 'redis_exporter_targets'
@ -270,8 +270,8 @@ scrape_configs:
target_label: __address__ target_label: __address__
regex: 'redis://(.*):63..' regex: 'redis://(.*):63..'
replacement: '${1}:9121' replacement: '${1}:9121'
{% endif %}
{% endif %}
{% if prometheus_redis_exporter_targets is defined %} {% if prometheus_redis_exporter_targets is defined %}
# Redis exporter # # Redis exporter #
- job_name: redis - job_name: redis
@ -287,8 +287,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):9121' regex: '(.*):9121'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_proxysql_exporter_targets is defined %} {% if prometheus_proxysql_exporter_targets is defined %}
# ProxySQL exporter # # ProxySQL exporter #
- job_name: proxysql - job_name: proxysql
@ -304,8 +304,8 @@ scrape_configs:
regex: '(.*):6070' regex: '(.*):6070'
replacement: '${1}' replacement: '${1}'
{% endfor %} {% endfor %}
{% endif %}
{% endif %}
{% if prometheus_kong_exporter_targets is defined %} {% if prometheus_kong_exporter_targets is defined %}
# Kong exporter # # Kong exporter #
- job_name: kong - job_name: kong
@ -320,8 +320,8 @@ scrape_configs:
{% for target in prometheus_kong_exporter_targets %} {% for target in prometheus_kong_exporter_targets %}
- {{ target }} - {{ target }}
{% endfor %} {% endfor %}
{% endif %}
{% endif %}
{% if prometheus_memcached_exporter_targets is defined %} {% if prometheus_memcached_exporter_targets is defined %}
# Memcached exporter # # Memcached exporter #
- job_name: memcached - job_name: memcached
@ -337,8 +337,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):9150' regex: '(.*):9150'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_docker_exporter_targets is defined %} {% if prometheus_docker_exporter_targets is defined %}
# Docker exporter # # Docker exporter #
- job_name: docker - job_name: docker
@ -354,8 +354,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):9323' regex: '(.*):9323'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_cadvisor_exporter_targets is defined %} {% if prometheus_cadvisor_exporter_targets is defined %}
# cadvisor # # cadvisor #
- job_name: cadvisor - job_name: cadvisor
@ -370,8 +370,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):8080' regex: '(.*):8080'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_cloudflare_exporter_targets is defined %} {% if prometheus_cloudflare_exporter_targets is defined %}
# cloudflare # # cloudflare #
- job_name: cloudflare - job_name: cloudflare
@ -386,8 +386,8 @@ scrape_configs:
target_label: instance target_label: instance
regex: '(.*):8082' regex: '(.*):8082'
replacement: '${1}' replacement: '${1}'
{% endif %}
{% endif %}
{% if prometheus_pve_exporter_targets is defined %} {% if prometheus_pve_exporter_targets is defined %}
# proxmox # # proxmox #
- job_name: pve - job_name: pve