Browse Source

Added role for prometheus sql exporter.

pull/11/head
Egon Rijpkema 2 years ago
parent
commit
eeafd85ffa
  1. 5
      prom_sql.yml
  2. 19
      roles/prom_sql/\
  3. 45
      roles/prom_sql/tasks/main.yml
  4. 19
      roles/prom_sql/templates/prom-sql.service
  5. 44
      roles/prom_sql/templates/queries.yml
  6. 16
      roles/prom_sql/templates/sql-agent.service

5
prom_sql.yml

@ -0,0 +1,5 @@
---
- hosts: scheduler
become: true
roles:
- prom_sql

19
roles/prom_sql/\

@ -0,0 +1,19 @@
[Unit]
Description=exposes Prometheus metrics for a SQL result set
After=sql-agent.service
Wants=sql-agent.service
[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker stop %n
ExecStartPre=-/usr/bin/docker rm %n
#Run daemon in the forground. systemd and docker do the daemonizing.
ExecStart=/usr/bin/docker run --rm --name %n \
--name prometheus-sql -p 9096:8080 \
-v ${PWD}/queries.yml:/queries.yml \
--link sql-agent.service:sqlagent \
dbhi/prometheus-sql
[Install]
WantedBy=multi-user.target

45
roles/prom_sql/tasks/main.yml

@ -0,0 +1,45 @@
---
- file:
path: /usr/local/prom-sql
state: directory
mode: 0755
- name: Copy the settings file.
copy:
src: templates/queries.yml
dest: /usr/local/prom-sql
mode: 0600
- name: Install service files.
template:
src: templates/{{item}}.service
dest: /etc/systemd/system/{{item}}.service
mode: 644
owner: root
group: root
with_items:
- prom-sql
- sql-agent
tags:
- service-files
- name: install service files
command: systemctl daemon-reload
- name: enable service at boot
systemd:
name: "{{ item }}.service"
enabled: yes
with_items:
- prom-sql
- sql-agent
- name: make sure servcies are started.
systemd:
name: "{{ item }}.service"
state: restarted
with_items:
- prom-sql
- sql-agent
tags:
- start-service

19
roles/prom_sql/templates/prom-sql.service

@ -0,0 +1,19 @@
[Unit]
Description=exposes Prometheus metrics for a SQL result set
After=sql-agent.service
Wants=sql-agent.service
[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker stop %n
ExecStartPre=-/usr/bin/docker rm %n
#Run daemon in the forground. systemd and docker do the daemonizing.
ExecStart=/usr/bin/docker run --rm --name %n \
-p 9096:8080 \
-v /usr/local/prom-sql/queries.yml:/queries.yml \
--link sql-agent.service:sqlagent \
dbhi/prometheus-sql
[Install]
WantedBy=multi-user.target

44
roles/prom_sql/templates/queries.yml

@ -0,0 +1,44 @@
- assoc_usage_day:
driver: mysql
connection:
host: gospel.service.rug.nl
port: 3306
user: slurmacc_pg
password: Go-kail3
database: slurm_pg_accounting
sql: >
select count(*) from peregrine_assoc_usage_day_table
interval: 10m
- assoc_usage_hour:
driver: mysql
connection:
host: gospel.service.rug.nl
port: 3306
user: slurmacc_pg
password: Go-kail3
database: slurm_pg_accounting
sql: >
select count(*) from peregrine_assoc_usage_day_table
interval: 10m
- assoc_usage_month:
driver: mysql
connection:
host: gospel.service.rug.nl
port: 3306
user: slurmacc_pg
password: Go-kail3
database: slurm_pg_accounting
sql: >
select count(*) from peregrine_assoc_usage_month_table
interval: 10m

16
roles/prom_sql/templates/sql-agent.service

@ -0,0 +1,16 @@
[Unit]
Description=Slurm database daemon
After=munge.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker stop %n
ExecStartPre=-/usr/bin/docker rm %n
# Run daemon in the forground. systemd and docker do the daemonizing,
ExecStart=/usr/bin/docker run --rm --name %n dbhi/sql-agent
[Install]
WantedBy=multi-user.target
Loading…
Cancel
Save