Skip to content

Commit

Permalink
Merge pull request #37 from sozialinfo/feature/push-gateway-scraper
Browse files Browse the repository at this point in the history
Feature/push gateway scraper
  • Loading branch information
janikvonrotz authored Feb 5, 2025
2 parents 5066e7d + cb2d0fc commit 0688f7e
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 0 deletions.
12 changes: 12 additions & 0 deletions roles/prometheus/templates/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,17 @@ scrape_configs:
credentials: {{ prometheus_meilisearch_exporter_api_key }}
static_configs:
- targets: {{ prometheus_hosts | map('extract', hostvars) | json_query('[*].nginx_proxies[?exporter!=null && contains(exporter, `meilisearch`)].src_hostname') | flatten }}
{% endif %}
{% if pushgateway_proxy_basic_auth_username is defined %}
- job_name: pushgateway https
metrics_path: "/pushgateway/metrics"
scrape_interval: 15s
honor_labels: true
scheme: https
basic_auth:
username: {{ pushgateway_proxy_basic_auth_username }}
password: {{ pushgateway_proxy_basic_auth_password }}
static_configs:
- targets: {{ prometheus_hosts | map('extract', hostvars) | json_query('[*].nginx_proxies[?exporter!=null && contains(exporter, `pushgateway`)].src_hostname') | flatten }}
{% endif %}
{{ prometheus_custom_scrapers | indent(2) }}
61 changes: 61 additions & 0 deletions roles/pushgateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Prometheus role

Deploy Pushgateway container.

## Usage

Configure the role.

```yml
# https://hub.docker.com/r/prom/pushgateway
pushgateway_image: prom/pushgateway:v1.11.0
pushgateway_hostname: pushgw01
pushgateway_description: Pushgateway # default: Pushgateway
pushgateway_volume_name: pushgw_data01 # default: "{{ pushgateway_hostname }}"
pushgateway_data_dir: /usr/share/pushgw # default: "/usr/share/{{ pushgateway_hostname }}"
pushgateway_port: 127.0.0.1:9091 # default: 127.0.0.1:9091
pushgateway_etc_hosts: # defaults: {}
"server.example.com": 10.42.5.2
pushgateway_proxy_basic_auth_username: metric # default: pushgateway
pushgateway_proxy_basic_auth_password: # default: "{{ vault_pushgateway_proxy_basic_auth_password }}"
```
Ensure the nginx proxy includes the exporter config:
```yml
nginx_proxies:
- src_hostname: server.example.com
ssl: true
monitor: /
exporter: node,cadvsior,nextcloud,bigbluebutton,postgres,restic,mysqld,odoo
options: |
include /etc/nginx/conf.d/proxies/node-exporter.nginx;
include /etc/nginx/conf.d/proxies/cadvisor.nginx;
include /etc/nginx/conf.d/proxies/nextcloud-exporter.nginx;
include /etc/nginx/conf.d/proxies/bigbluebutton-exporter.nginx;
include /etc/nginx/conf.d/proxies/postgres-exporter.nginx;
include /etc/nginx/conf.d/proxies/mysqld-exporter.nginx;
include /etc/nginx/conf.d/proxies/odoo-exporter.nginx;
include /etc/nginx/conf.d/proxies/n8n-exporter.nginx;
```
And include it in your playbook.
```yml
- hosts: pushgateway
roles:
- role: pushgateway
```
## Docs
Pushgateway is used to monitor cronjobs
### Deploy Pushgateway container
Select multiple inventories when deploying.
```bash
ansible-playbook -i inventories/odoo -i inventories/nextcloud -i inventories/setup plays/setup.yml -l pushgateway -t pushgateway
```
17 changes: 17 additions & 0 deletions roles/pushgateway/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
pushgateway_port: 127.0.0.1:9091
pushgateway_description: Pushgateway
pushgateway_volume_name: "{{ pushgateway_hostname }}"
pushgateway_data_dir: /usr/share/{{ pushgateway_hostname }}
pushgateway_etc_hosts: {}
pushgateway_nginx_data_dir: "{{ nginx_data_dir }}/proxies"
pushgateway_requires_package: python3-passlib
pushgateway_proxy_basic_auth_username: pushgateway
pushgateway_proxy_basic_auth_password: "{{ vault_pushgateway_proxy_basic_auth_password}}"
pushgateway_hostname: pushgateway01
pushgateway_args:
- --web.listen-address={{ pushgateway_port }}
#- --web.external-url=
- --web.route-prefix="/pushgateway"
- --persistence.file=/pushgateway/state

6 changes: 6 additions & 0 deletions roles/pushgateway/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
dependencies: # noqa 701
- role: docker_network
tags:
- docker_network
- depends
13 changes: 13 additions & 0 deletions roles/pushgateway/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Include {{ role_name }} tasks
ansible.builtin.include_tasks: "{{ role_name }}.yml"
when: pushgateway_image is defined
tags:
- pushgateway

- name: Include {{ role_name }} nginx config tasks
ansible.builtin.include_tasks: "{{ role_name }}_nginx_config.yml"
when: pushgateway_image is defined
tags:
- pushgateway
- pushgateway_nginx_config
31 changes: 31 additions & 0 deletions roles/pushgateway/tasks/pushgateway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- name: Create {{ role_name }} volume
community.docker.docker_volume:
name: "{{ pushgateway_volume_name }}"

- name: Ensure {{ role_name }} data dir exists
ansible.builtin.file:
path: "{{ pushgateway_data_dir }}"
state: directory

- name: Start {{ role_name }} container {{ pushgateway_hostname }}
community.docker.docker_container:
name: "{{ pushgateway_hostname }}"
labels:
description: "{{ pushgateway_description }}"
image: "{{ pushgateway_image }}"
restart_policy: unless-stopped
command: "{{ pushgateway_args | join(' ') }}"
volumes:
- "{{ pushgateway_volume_name }}:/pushgateway"
ports:
- "{{ pushgateway_port }}:9091"
networks:
- name: "{{ docker_network_name }}"
network_mode: bridge
etc_hosts: "{{ pushgateway_etc_hosts }}"
log_driver: "{{ docker_log_driver }}"
log_options:
max-size: "{{ docker_log_max_size }}"
max-file: "{{ docker_log_max_file }}"
tag: "{{ pushgateway_hostname }}|{{ role_name }}"
26 changes: 26 additions & 0 deletions roles/pushgateway/tasks/pushgateway_nginx_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Ensure nginx data dir exists
ansible.builtin.file:
path: "{{ pushgateway_nginx_data_dir }}"
state: directory

- name: Gather package facts
ansible.builtin.package_facts:
manager: auto

- name: Fail if package {{ pushgateway_requires_package }} is not installed
ansible.builtin.assert:
that:
- pushgateway_requires_package in ansible_facts.packages
fail_msg: Package {{ pushgateway_requires_package }} is not installed!

- name: Configure user access for {{ role_name }}
community.general.htpasswd:
path: "{{ pushgateway_nginx_data_dir }}/pushgateway.htpasswd"
name: "{{ pushgateway_proxy_basic_auth_username }}"
password: "{{ pushgateway_proxy_basic_auth_password }}"

- name: Copy nginx {{ role_name }} conf
ansible.builtin.template:
src: pushgateway.nginx
dest: "{{ pushgateway_nginx_data_dir }}/pushgateway.nginx"
6 changes: 6 additions & 0 deletions roles/pushgateway/templates/pushgateway.nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
location /pushgateway/ {
auth_basic "{{ pushgateway_proxy_basic_auth_username }}";
auth_basic_user_file /etc/nginx/conf.d/proxies/pushgateway.htpasswd;
proxy_pass http://{{ pushgateway_hostname }}:9091;
include /etc/nginx/conf.d/proxy-params.conf;
}

0 comments on commit 0688f7e

Please sign in to comment.