Compare commits

...

23 Commits

Author SHA1 Message Date
Andrea Dell'Amico ea9717084b
New default version for the prometheus exporter. 2023-10-11 17:43:23 +02:00
Andrea Dell'Amico 9277576d8b
Undefine mongodb_allowed_hosts 2023-09-27 16:39:38 +02:00
Roberto Cirillo f7b220bbeb mongodb oplog property parameterized in conf 3.6 2023-09-27 14:39:20 +02:00
Andrea Dell'Amico 91b925a0e8
Use the upstart commands on old ubuntu. 2022-09-13 13:27:08 +02:00
Andrea Dell'Amico 84b92decb4
Do not restart when the certificate did not change. 2022-06-10 15:56:05 +02:00
Andrea Dell'Amico 1fa3343662
Remove the task that stops the exporter. 2022-03-07 17:03:03 +01:00
Andrea Dell'Amico f3b048a8b2 Merge pull request 'set MajorityReadConcern to false to mongodb 3.6' (!3) from feauture/20970 into master
Reviewed-on: #3
2022-02-24 14:05:34 +01:00
Roberto Cirillo f6cf0e12dd set MajorityReadConcern to false to mongodb 3.6 2022-02-24 13:40:25 +01:00
Andrea Dell'Amico 3522814504
Add a missing newline. 2022-01-17 19:03:10 +01:00
Andrea Dell'Amico ed7016455d
New parameters. 2022-01-17 18:57:30 +01:00
Andrea Dell'Amico 12a13f613d
No compatibility mode by default. 2022-01-17 16:28:24 +01:00
Andrea Dell'Amico d3f768ff7c
Add mongodb_prometheus_exporter_collect_opts to the upstart file. 2022-01-17 16:21:44 +01:00
Andrea Dell'Amico 0482e212b7
Fix a typo. 2022-01-17 12:56:48 +01:00
Andrea Dell'Amico 4736952a73
Fix a wrong variable, enable compatible mode. 2022-01-17 12:50:38 +01:00
Andrea Dell'Amico 7f5370cffb
Fix the upstart script. 2022-01-17 12:33:12 +01:00
Andrea Dell'Amico 5562401363
Fix a wrongly named variable. 2022-01-17 12:17:28 +01:00
Andrea Dell'Amico a7434a7eee
Manage the prometheus exporter. 2022-01-14 16:48:03 +01:00
Andrea Dell'Amico cff54c6499
Use links. 2021-10-13 17:03:53 +02:00
Andrea Dell'Amico bdcdef09c9
Fix the handler when using mongodb-org. 2021-10-13 17:03:26 +02:00
Andrea Dell'Amico c818b8ac05
Fix the path to the keyfile. 2021-10-13 16:56:14 +02:00
Tommaso Piccioli f24f281dc6 Merge pull request 'Update 'tasks/mongodb.yml'' (!2) from tommaso.piccioli-patch-2 into master
Reviewed-on: #2
2021-10-13 15:57:42 +02:00
Tommaso Piccioli 60d5cfde58 Update 'tasks/mongodb.yml' 2021-10-13 15:57:35 +02:00
Tommaso Piccioli abd318b3c6 Merge pull request 'Upload files to 'templates'' (!1) from tommaso.piccioli-patch-1 into master
Reviewed-on: #1
2021-10-13 15:51:47 +02:00
12 changed files with 161 additions and 121 deletions

View File

@ -49,9 +49,9 @@ mongodb_directoryperdb: 'false'
mongodb_conf_file: /etc/mongod.conf
mongodb_daemon: /usr/bin/mongod
mongod_additional_options: ""
mongodb_allowed_hosts:
- 127.0.0.1/8
- '{{ ansible_default_ipv4.address }}/32'
# mongodb_allowed_hosts:
# - 127.0.0.1/8
# - '{{ ansible_default_ipv4.address }}/32'
mongodb_storage_engine: wiredTiger
@ -81,6 +81,28 @@ mongodb_cluster_enabled: False
mongodb_authorization_enabled: False
mongodb_replicaset: storagedev
mongodb_replica_keyfile: '{{ mongodb_dbpath }}/replica_keyfile'
mongodb_oplog_size: 2000
# User and password are stored in the variables mongo_monitoring_u and mongo_monitoring_pwd
# Prometheus metrics
mongodb_prometheus_exporter_enabled: false
mongodb_prometheus_exporter_version: '0.39.0'
mongodb_prometheus_exporter_dir: 'mongodb_exporter-{{ mongodb_prometheus_exporter_version }}.linux-amd64'
mongodb_prometheus_exporter_file: '{{ mongodb_prometheus_exporter_dir }}.tar.gz'
mongodb_prometheus_exporter_download_url: 'https://github.com/percona/mongodb_exporter/releases/download/v{{ mongodb_prometheus_exporter_version }}/{{ mongodb_prometheus_exporter_file }}'
mongodb_prometheus_exporter_port: 9216
mongodb_prometheus_exporter_loglevel: error
mongodb_prometheus_exporter_collstat_limit: '20'
mongodb_prometheus_exporter_opts: '--web.listen-address=":{{ mongodb_prometheus_exporter_port }}" --log.level={{ mongodb_prometheus_exporter_loglevel }}'
mongodb_prometheus_exporter_connection_opts: '--mongodb.uri="mongodb://{{ mongodb_prometheus_exporter_connection_user }}:{{ mongodb_prometheus_exporter_connection_password }}@{{ mongodb_prometheus_exporter_connection_host }}/{{ mongodb_prometheus_exporter_connection_params }}"'
mongodb_prometheus_exporter_collect_opts: '--mongodb.global-conn-pool --mongodb.direct-connect=true --collector.topmetrics --discovering-mode --collector.dbstats --collector.collstats-limit={{ mongodb_prometheus_exporter_collstat_limit }}'
mongodb_prometheus_exporter_enable_compatible_mode: False
# List the additional options here
mongodb_prometheus_exporter_additional_opts: ''
mongodb_prometheus_exporter_user: prometheus_mongodb
mongodb_prometheus_exporter_home: '/opt/{{ mongodb_prometheus_exporter_user }}'
mongodb_prometheus_exporter_dist_dir: '{{ mongodb_prometheus_exporter_home }}/dist'
mongodb_prometheus_exporter_cmd: '{{ mongodb_prometheus_exporter_dist_dir }}/{{ mongodb_prometheus_exporter_dir }}/mongodb_exporter'
mongodb_prometheus_exporter_connection_host: 'localhost:27017'
mongodb_prometheus_exporter_connection_user: monitor
#mongodb_prometheus_exporter_connection_password: 'use a vault'
mongodb_prometheus_exporter_connection_params: 'admin?ssl=true'

View File

@ -7,3 +7,11 @@
service: name=mongodb state=restarted
when: "'{{ mongodb_start_server }}' == 'yes'"
- name: Restart mongodb exporter
ansible.builtin.service:
name: mongodb_exporter
state: restarted
- name: Reload the systemd data
systemd:
daemon_reload: yes

View File

@ -2,3 +2,4 @@
- import_tasks: mongodb.yml
- import_tasks: mongodb-letsencrypt-acmetool.yml
when: mongodb_ssl_letsencrypt_managed
- import_tasks: mongodb-prometheus-exporter.yml

View File

@ -0,0 +1,70 @@
---
- 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' ]

View File

@ -36,7 +36,7 @@
- name: Install/Update the mongodb-org configuration
template: src=mongod-{{ mongodb_version }}.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0444 backup=yes
when: mongodb_install_conf
notify: Restart mongodb
notify: Restart mongod
tags: [ 'mongodb', 'mongodb_update_conf', 'mongodb_keyfile' ]
when:
@ -75,7 +75,7 @@
- name: Install/Update the mongodb configuration
template: src=mongod-{{ mongodb_version }}.conf.j2 dest=/etc/mongodb.conf owner=root group=root mode=0444 backup=yes
when: mongodb_install_conf
notify: Restart mongod
notify: Restart mongodb
tags: [ 'mongodb', 'mongodb_update_conf' ]
when:

View File

@ -43,7 +43,7 @@ net:
{%if mongodb_cluster_enabled %}
security:
keyFile: /data/mongo_home/dev-d4science-keyfile
keyFile: {{ mongodb_replica_keyfile }}
replication:
oplogSizeMB: 2000

View File

@ -1,54 +0,0 @@
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: {{ mongodb_dbpath }}
journal:
enabled: true
directoryPerDB: {{ mongodb_directoryperdb }}
engine: {{ mongodb_storage_engine }}
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: {{ mongodb_systemlog_destination }}
path: {{ mongodb_logpath }}
{% if not mongodb_systemlog_external_logrotate %}
logRotate: rename
logAppend: false
{% else %}
logRotate: reopen
logAppend: true
{% endif %}
# network interfaces
net:
port: {{ mongodb_tcp_port }}
bindIp: {{ mongo_bind_ip }}
http:
enabled: {{ mongodb_http_interface }}
JSONPEnabled: {{ mongodb_http_interface }}
RESTInterfaceEnabled: {{ mongodb_http_interface }}
{% if mongodb_ssl_enabled %}
ssl:
mode: {{ mongodb_ssl_mode }}
PEMKeyFile: '{{ mongodb_ssl_certkey_file }}'
CAFile: '{{ mongodb_ssl_CA_file }}'
{% endif %}
#processManagement:
{%if mongodb_cluster_enabled %}
security:
keyFile: /data/mongo_home/dev-d4science-keyfile
replication:
oplogSizeMB: 2000
replSetName: {{ mongodb_replicaset }}
{% endif %}
#sharding:

View File

@ -0,0 +1 @@
mongod-3.0.conf.j2

View File

@ -1,52 +0,0 @@
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: {{ mongodb_dbpath }}
journal:
enabled: true
directoryPerDB: {{ mongodb_directoryperdb }}
engine: {{ mongodb_storage_engine }}
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: {{ mongodb_systemlog_destination }}
path: {{ mongodb_logpath }}
{% if not mongodb_systemlog_external_logrotate %}
logRotate: rename
logAppend: false
{% else %}
logRotate: reopen
logAppend: true
{% endif %}
# network interfaces
net:
port: {{ mongodb_tcp_port }}
bindIp: {{ mongo_bind_ip }}
{% if mongodb_ssl_enabled %}
ssl:
mode: {{ mongodb_ssl_mode }}
PEMKeyFile: '{{ mongodb_ssl_certkey_file }}'
CAFile: '{{ mongodb_ssl_CA_file }}'
disabledProtocols: {{ mongodb_ssl_disabled_protocols }}
allowConnectionsWithoutCertificates: {{ mongodb_ssl_allowConnectionsWithoutCertificates }}
{% endif %}
#processManagement:
{%if mongodb_cluster_enabled %}
security:
keyFile: /data/mongo_home/dev-d4science-keyfile
replication:
oplogSizeMB: 2000
replSetName: {{ mongodb_replicaset }}
{% endif %}
#sharding:

View File

@ -0,0 +1 @@
mongod-3.6.conf.j2

View File

@ -41,11 +41,12 @@ net:
{%if mongodb_cluster_enabled %}
security:
keyFile: /data/mongo_home/dev-d4science-keyfile
keyFile: {{ mongodb_replica_keyfile }}
replication:
oplogSizeMB: 2000
oplogSizeMB: {{ mongodb_oplog_size }}
replSetName: {{ mongodb_replicaset }}
enableMajorityReadConcern: false
{% endif %}
#sharding:

View File

@ -12,17 +12,31 @@ echo "$DATE" > $LE_LOG_DIR/mongodb.log
[ ! -d $MONGODB_CERTDIR ] && mkdir $MONGODB_CERTDIR
cat ${LE_CERTS_DIR}/{cert,privkey} > ${MONGODB_CERTFILE}.new
cmp ${MONGODB_CERTFILE}.new ${MONGODB_CERTFILE} 2>/dev/null
if [ $? -eq 0 ] ; then
echo "The certificate is up to date" >> $LE_LOG_DIR/mongodb.log
rm -f ${MONGODB_CERTFILE}.new
exit 0
fi
echo "Building the new certificate file" >> $LE_LOG_DIR/mongodb.log
cat ${LE_CERTS_DIR}/{cert,privkey} > ${MONGODB_CERTFILE}
/bin/mv -f ${MONGODB_CERTFILE}.new ${MONGODB_CERTFILE}
chmod 440 ${MONGODB_CERTFILE}
chgrp mongodb ${MONGODB_CERTFILE}
{% if mongodb_ssl_enabled %}
echo "Reload the mongod service" >> "$LE_LOG_DIR/mongodb.log"
echo "Restart the mongod service, reload is not supported" >> "$LE_LOG_DIR/mongodb.log"
{% if mongodb_install_from_external_repo %}
service mongod stop >> "$LE_LOG_DIR/mongodb.log" 2>&1
sleep 10
service mongod start >> "$LE_LOG_DIR/mongodb.log" 2>&1
if [ -x /sbin/stop ] && [ -f /etc/init/mongod.conf ] ; then
/sbin/stop mongod >> "$LE_LOG_DIR/mongodb.log" 2>&1
sleep 10
/sbin/start mongod >> "$LE_LOG_DIR/mongodb.log" 2>&1
else
service mongod stop >> "$LE_LOG_DIR/mongodb.log" 2>&1
sleep 10
service mongod start >> "$LE_LOG_DIR/mongodb.log" 2>&1
fi
{% else %}
systemctl stop mongodb >> "$LE_LOG_DIR/mongodb.log" 2>&1
sleep 10

View File

@ -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 }}{% if mongodb_prometheus_exporter_enable_compatible_mode %} --compatible-mode{% endif %}
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,13 @@
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_collect_opts }} {{ mongodb_prometheus_exporter_additional_opts }}{% if mongodb_prometheus_exporter_enable_compatible_mode %} --compatible-mode{% endif %}
end script