add prometheus role

This commit is contained in:
2022-08-30 07:49:57 -05:00
parent ec17840809
commit 749934f9e1
13 changed files with 387 additions and 0 deletions

View File

@ -0,0 +1,79 @@
# {{ ansible_managed }}
upstream prometheus_backend {
server 127.0.0.1:{{ prometheus_port }};
}
upstream alertmanager_backend {
server 127.0.0.1:{{ alertmanager_port }};
}
upstream karma_backend {
server 127.0.0.1:{{ karma_port }};
}
server {
listen 80;
{% if ansible_all_ipv6_addresses | length %}
listen [::]:80;
{% endif %}
server_name {{ prometheus_hostname }};
access_log /var/log/nginx/prometheus.access.log main;
error_log /var/log/nginx/prometheus.error.log warn;
location /.well-known/acme-challenge/ {
root /var/www/html;
try_files $uri =404;
}
{% if prometheus_ssl_enabled is defined and
prometheus_ssl_enabled %}
location / {
return 301 https://$server_name$request_uri;
}
{% endif %}
}
{% if prometheus_ssl_enabled is defined and
prometheus_ssl_enabled %}
server {
listen 443 ssl http2;
{% if ansible_all_ipv6_addresses | length %}
listen [::]:443 ssl http2;
{% endif %}
server_name {{ prometheus_hostname }};
auth_basic "Prometheus";
auth_basic_user_file {{ prometheus_htpasswd_path }};
access_log /var/log/nginx/prometheus.access.log main;
error_log /var/log/nginx/prometheus.error.log warn;
{% if prometheus_ssl_certificate is defined %}
ssl_certificate {{ prometheus_ssl_certificate }};
{% endif %}
{% if prometheus_ssl_certificate_key is defined %}
ssl_certificate_key {{ prometheus_ssl_certificate_key }};
{% endif %}
{% if prometheus_ssl_dhparam is defined %}
ssl_dhparam {{ prometheus_ssl_dhparam }};
{% endif %}
location /prometheus/ {
proxy_pass http://prometheus_backend/;
}
location /alertmanager/ {
proxy_pass http://alertmanager_backend/;
}
location /karma/ {
proxy_pass http://karma_backend/;
}
location / {
return 301 /prometheus/;
}
}
{% endif %}

View File

@ -0,0 +1,35 @@
{{ ansible_managed | comment }}
[Unit]
Description=Prometheus
After=network-online.target
[Service]
Type=simple
User={{ prometheus_user }}
Group={{ prometheus_group }}
ExecReload=/bin/kill -HUP $MAINPID
ExecStart={{ prometheus_bin_path }}/prometheus \
--config.file={{ prometheus_etc_path }}/prometheus.yaml \
--storage.tsdb.path={{ prometheus_var_path }} \
{% if prometheus_web_external_url %}
--web.external-url={{ prometheus_web_external_url }} \
{% endif %}
{% if prometheus_web_route_prefix %}
--web.route-prefix={{ prometheus_web_route_prefix }} \
{% endif %}
{% if prometheus_web_listen_address %}
--web.listen-address={{ prometheus_web_listen_address }} \
{% endif %}
{% if prometheus_web_enable_lifecycle %}
--web.enable-lifecycle \
{% endif %}
{% if prometheus_storage_tsdb_min_block_duration %}
--storage.tsdb.min-block-duration={{ prometheus_storage_tsdb_min_block_duration }} \
{% endif %}
{% if prometheus_storage_tsdb_max_block_duration %}
--storage.tsdb.max-block-duration={{ prometheus_storage_tsdb_max_block_duration }} \
{% endif %}
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1 @@
---