Manage the prometheus exporter.
parent
cff54c6499
commit
a7434a7eee
@ -0,0 +1,80 @@
|
|||||||
|
---
|
||||||
|
- name: Mongodb exporter
|
||||||
|
block:
|
||||||
|
- name: Create the user under the mongodb exporter will run
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: '{{ mongodb_prometheus_exporter_user }}'
|
||||||
|
home: '{{ mongodb_prometheus_exporter_home }}'
|
||||||
|
createhome: no
|
||||||
|
shell: /usr/sbin/nologin
|
||||||
|
system: yes
|
||||||
|
|
||||||
|
- name: Create the prometheus mongodb exporter base directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
dest: '{{ item }}'
|
||||||
|
state: directory
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
loop:
|
||||||
|
- '{{ mongodb_prometheus_exporter_home }}'
|
||||||
|
- '{{ mongodb_prometheus_exporter_dist_dir }}'
|
||||||
|
|
||||||
|
- name: Download the prometheus mongodb exporter
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: '{{ mongodb_prometheus_exporter_download_url }}'
|
||||||
|
dest: /srv/
|
||||||
|
|
||||||
|
- name: Unarchive the prometheus distribution
|
||||||
|
ansible.builtin.unarchive:
|
||||||
|
src: '/srv/{{ mongodb_prometheus_exporter_file }}'
|
||||||
|
dest: '{{ mongodb_prometheus_exporter_dist_dir }}'
|
||||||
|
remote_src: yes
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
args:
|
||||||
|
creates: '{{ mongodb_prometheus_exporter_dist_dir }}/{{ mongodb_prometheus_exporter_dir }}/mongodb_exporter'
|
||||||
|
notify: Restart mongodb exporter
|
||||||
|
|
||||||
|
- name: Install the prometheus node exporter upstart script
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: mongodb_exporter.upstart.j2
|
||||||
|
dest: /etc/init/mongodb_exporter.conf
|
||||||
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
when: ansible_service_mgr != 'systemd'
|
||||||
|
notify: Restart mongodb exporter
|
||||||
|
|
||||||
|
- name: Install the prometheus mongodb exporter systemd unit
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: mongodb_exporter.service.j2
|
||||||
|
dest: /etc/systemd/system/mongodb_exporter.service
|
||||||
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
when: ansible_service_mgr == 'systemd'
|
||||||
|
notify:
|
||||||
|
- Reload the systemd data
|
||||||
|
- Restart mongodb exporter
|
||||||
|
|
||||||
|
- ansible.builtin.meta: flush_handlers
|
||||||
|
|
||||||
|
- name: Ensure that prometheus mongodb_exporter is started and enabled
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: mongodb_exporter
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
|
||||||
|
when: mongodb_prometheus_exporter_enabled
|
||||||
|
tags: [ 'mongodb', 'prometheus', 'mongodb_prometheus' ]
|
||||||
|
|
||||||
|
- name: No mongodb exporter
|
||||||
|
block:
|
||||||
|
- name: Ensure that prometheus mongodb_exporter is stopped and disabled
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: mongodb_exporter
|
||||||
|
state: stopped
|
||||||
|
enabled: no
|
||||||
|
|
||||||
|
when: not mongodb_prometheus_exporter_enabled
|
||||||
|
tags: [ 'mongodb', 'prometheus', 'mongodb_prometheus' ]
|
@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=mongodb_exporter - Prometheus exporter for mongodb.
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=on-failure
|
||||||
|
|
||||||
|
User={{ mongodb_prometheus_exporter_user }}
|
||||||
|
Group={{ mongodb_prometheus_exporter_user }}
|
||||||
|
|
||||||
|
ExecStart={{ mongodb_prometheus_exporter_cmd }} {{ mongodb_prometheus_exporter_opts }} {{ mongodb_prometheus_exporter_additional_opts }} {{ mongodb_prometheus_exporter_collect_opts }} {{ mongodb_prometheus_exporter_connection_opts }}
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -0,0 +1,12 @@
|
|||||||
|
description "Prometheus mongodb exporter"
|
||||||
|
start on (local-filesystems and net-device-up IFACE!=lo)
|
||||||
|
stop on runlevel [016]
|
||||||
|
|
||||||
|
respawn
|
||||||
|
respawn limit 10 5
|
||||||
|
setuid {{ mongodb_prometheus_exporter_user }}
|
||||||
|
setgid {{ mongodb_prometheus_exporter_user }}
|
||||||
|
|
||||||
|
script
|
||||||
|
exec {{ mongodb_prometheus_exporter_cmd }} {{ mongodb_prometheus_exporter_opts }} {{ mongodb_prometheus_exporter_connection_opts }} {{ mongodb_prometheus_exporter_additional_opts }} > {{ mongodb_prometheus_exporter_logdir }}/mongodb_exporter.log 2>&1
|
||||||
|
end script
|
Loading…
Reference in New Issue