add cloudflare exporter
This commit is contained in:
parent
17e1e50a48
commit
a7940658b1
@ -1,4 +1,8 @@
|
||||
---
|
||||
docker_compose_path: "/opt/docker-compose"
|
||||
|
||||
prometheus_docker_network: prometheus
|
||||
|
||||
prometheus_docker_pull: "no"
|
||||
|
||||
exporter_upgrade: ""
|
||||
|
46
tasks/exporter/_docker.yml
Normal file
46
tasks/exporter/_docker.yml
Normal file
@ -0,0 +1,46 @@
|
||||
---
|
||||
- name: '{{ exporter }} exporter | check if docker is installed'
|
||||
shell:
|
||||
cmd: {{ item }} --help
|
||||
register: result
|
||||
check_mode: false
|
||||
changed_when: false
|
||||
failed_when: result.rc != 0 and result.rc != 127
|
||||
with_items:
|
||||
- docker
|
||||
- docker-compose
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name: '{{ exporter }} exporter | create docker-compose directory'
|
||||
file:
|
||||
path: "{{ docker_compose_directory }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name: '{{ exporter }} exporter | copy docker-compose file'
|
||||
template:
|
||||
src: compose/{{ exporter }}.yml.j2
|
||||
dest: /opt/docker-compose/{{ exporter }}/docker-compose.yml
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify: "{{ exporter }}-restart"
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name: '{{ exporter }} exporter | systemd | install unit file'
|
||||
template:
|
||||
src: systemd/docker-compose.service.j2
|
||||
dest: /etc/systemd/system/docker-compose@{{ exporter }}.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0600
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name: '{{ exporter }} exporter | systemd | enable service'
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
name: docker-compose@{{ exporter }}
|
||||
enabled: true
|
||||
ignore_errors: '{{ ansible_check_mode }}'
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
9
tasks/exporter/cloudflare.yml
Normal file
9
tasks/exporter/cloudflare.yml
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: cloudflare | check vars are defined
|
||||
assert:
|
||||
that:
|
||||
- cloudflare_api_key is defined
|
||||
tags: ['prometheus_cloudflare_exporter']
|
||||
|
||||
- include_tasks: _docker.yml
|
||||
tags: ['prometheus_cloudflare_exporter']
|
@ -7,7 +7,7 @@
|
||||
|
||||
- name: 'prometheus | server | create docker network'
|
||||
docker_network:
|
||||
name: 'prometheus'
|
||||
name: '{{ prometheus_docker_network }}'
|
||||
tags: ['prometheus_server']
|
||||
|
||||
- name: 'prometheus | server | create docker volume data'
|
||||
@ -50,7 +50,7 @@
|
||||
- '--web.console.templates=/usr/share/prometheus/consoles'
|
||||
- '--web.enable-admin-api'
|
||||
networks:
|
||||
- { name: prometheus }
|
||||
- { name: {{ prometheus_docker_network }} }
|
||||
ports:
|
||||
- "9090:9090"
|
||||
log_driver: syslog
|
||||
|
17
templates/compose/cloudflare.yml.j2
Normal file
17
templates/compose/cloudflare.yml.j2
Normal file
@ -0,0 +1,17 @@
|
||||
version: '3.7'
|
||||
|
||||
networks:
|
||||
{{ prometheus_docker_network }}:
|
||||
external: true
|
||||
|
||||
services:
|
||||
cloudflare-exporter:
|
||||
container_name: cloudflare-exporter
|
||||
image: ghcr.io/lablabs/cloudflare_exporter:latest
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- CF_API_TOKEN={{ cloudflare_api_key }}
|
||||
ports:
|
||||
- 8082:8080
|
||||
networks:
|
||||
- {{ prometheus_docker_network }}
|
@ -371,3 +371,19 @@ scrape_configs:
|
||||
regex: '(.*):8080'
|
||||
replacement: '${1}'
|
||||
{% endif %}
|
||||
|
||||
{% if prometheus_cloudflare_exporter_targets is defined %}
|
||||
# cloudflare #
|
||||
- job_name: cloudflare
|
||||
scrape_interval: 30s
|
||||
static_configs:
|
||||
- targets:
|
||||
{% for target in prometheus_cloudflare_exporter_targets %}
|
||||
- {{ target }}:8082
|
||||
{% endfor %}
|
||||
relabel_configs:
|
||||
- source_labels: [ __address__ ]
|
||||
target_label: instance
|
||||
regex: '(.*):8082'
|
||||
replacement: '${1}'
|
||||
{% endif %}
|
||||
|
14
templates/systemd/docker-compose.service.j2
Normal file
14
templates/systemd/docker-compose.service.j2
Normal file
@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=%i service with docker compose
|
||||
PartOf=docker.service
|
||||
After=docker.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=true
|
||||
WorkingDirectory=/opt/docker-compose/{{ exporter }}
|
||||
ExecStart=/usr/bin/docker-compose up -d
|
||||
ExecStop=/usr/bin/docker-compose down
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
x
Reference in New Issue
Block a user