Multiple changes in preparation for the "ng" fork.

* Changed references to salt://prometheus-ng/...
* Added generic templates for exporters.
* Added variables passed on to templates.
This commit is contained in:
Eric Renfro 2019-05-08 16:09:25 -04:00
parent 5068a65cf5
commit ce7512d643
Signed by: psi-jack
GPG key ID: 14977F3A50D9A5BF
11 changed files with 129 additions and 40 deletions

View file

@ -28,7 +28,7 @@ alertmanager_config:
alertmanager_config: alertmanager_config:
file.managed: file.managed:
- name: {{ prometheus.alertmanager.args.config_file }} - name: {{ prometheus.alertmanager.args.config_file }}
- source: salt://prometheus/files/config.jinja - source: salt://prometheus-ng/files/config.jinja
- template: jinja - template: jinja
- user: {{ prometheus.user }} - user: {{ prometheus.user }}
- group: {{ prometheus.group }} - group: {{ prometheus.group }}
@ -39,7 +39,7 @@ alertmanager_config:
alertmanager_defaults: alertmanager_defaults:
file.managed: file.managed:
- name: /etc/default/alertmanager - name: /etc/default/alertmanager
- source: salt://prometheus/files/default-alertmanager.jinja - source: salt://prometheus-ng/files/default-alertmanager.jinja
- template: jinja - template: jinja
- defaults: - defaults:
config_file: {{ prometheus.alertmanager.args.config_file }} config_file: {{ prometheus.alertmanager.args.config_file }}
@ -58,10 +58,10 @@ alertmanager_service_unit:
file.managed: file.managed:
{%- if grains.get('init') == 'systemd' %} {%- if grains.get('init') == 'systemd' %}
- name: /etc/systemd/system/alertmanager.service - name: /etc/systemd/system/alertmanager.service
- source: salt://prometheus/files/alertmanager.systemd.jinja - source: salt://prometheus-ng/files/alertmanager.systemd.jinja
{%- elif grains.get('init') == 'upstart' %} {%- elif grains.get('init') == 'upstart' %}
- name: /etc/init/alertmanager.conf - name: /etc/init/alertmanager.conf
- source: salt://prometheus/files/alertmanager.upstart.jinja - source: salt://prometheus-ng/files/alertmanager.upstart.jinja
{%- endif %} {%- endif %}
- watch: - watch:
- file: alertmanager_defaults - file: alertmanager_defaults

View file

@ -2,41 +2,41 @@ prometheus:
user: prometheus user: prometheus
group: prometheus group: prometheus
server: server:
version: 1.4.1.linux-amd64 version: 2.5.0.linux-amd64
install_dir: /opt install_dir: /opt
source: https://github.com/prometheus/prometheus/releases/download/v1.4.1/prometheus-1.4.1.linux-amd64.tar.gz source: https://github.com/prometheus/prometheus/releases/download/v2.5.0/prometheus-2.5.0.linux-amd64.tar.gz
source_hash: sha1=3e78173e7d65623e79e0292da16e6155de947185 source_hash: https://github.com/prometheus/prometheus/releases/download/v2.5.0/sha256sums.txt
args: args:
config_file: /etc/prometheus/prometheus.yml config_file: /etc/prometheus/prometheus.yml
storage: storage:
local_path: /var/lib/prometheus/metrics local_path: /var/lib/prometheus/metrics
alertmanager: alertmanager:
version: 0.5.1.linux-amd64 version: 0.15.3.linux-amd64
install_dir: /opt install_dir: /opt
source: https://github.com/prometheus/alertmanager/releases/download/v0.5.1/alertmanager-0.5.1.linux-amd64.tar.gz source: https://github.com/prometheus/alertmanager/releases/download/v0.15.3/alertmanager-0.15.3.linux-amd64.tar.gz
source_hash: sha1=8f82ccc0db806991256084faee9335353d8e3f0d source_hash: https://github.com/prometheus/alertmanager/releases/download/v0.15.3/sha256sums.txt
args: args:
config_file: /etc/alertmanager/alertmanager.yml config_file: /etc/alertmanager/alertmanager.yml
storage: storage:
path: /var/lib/alertmanager path: /var/lib/alertmanager
exporter: exporter:
node: node:
version: 0.13.0.linux-amd64 version: 0.17.0.linux-amd64
install_dir: /opt install_dir: /opt
source: https://github.com/prometheus/node_exporter/releases/download/v0.13.0/node_exporter-0.13.0.linux-amd64.tar.gz source: https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
source_hash: sha1=84ca5f711962319f6f7823208b9d867ab1c0e3e7 source_hash: https://github.com/prometheus/node_exporter/releases/download/v0.17.0/sha256sums.txt
blackbox: blackbox:
version: 0.3.0.linux-amd64 version: 0.14.0.linux-amd64
install_dir: /opt install_dir: /opt
source: https://github.com/prometheus/blackbox_exporter/releases/download/v0.3.0/blackbox_exporter-0.3.0.linux-amd64.tar.gz source: https://github.com/prometheus/blackbox_exporter/releases/download/v0.14.0/blackbox_exporter-0.14.0.linux-amd64.tar.gz
source_hash: sha1=89ac98c062315ba35eda257ca88c8c4b43f38d47 source_hash: https://github.com/prometheus/blackbox_exporter/releases/download/v0.14.0/sha256sums.txt
args: args:
config_file: /etc/prometheus/blackbox_exporter.yml config_file: /etc/prometheus/blackbox_exporter.yml
haproxy: haproxy:
version: 0.7.1.linux-amd64 version: 0.10.0.linux-amd64
install_dir: /opt install_dir: /opt
source: https://github.com/prometheus/haproxy_exporter/releases/download/v0.7.1/haproxy_exporter-0.7.1.linux-amd64.tar.gz source: https://github.com/prometheus/haproxy_exporter/releases/download/v0.10.0/haproxy_exporter-0.10.0.linux-amd64.tar.gz
source_hash: sha1=56849253e280db3db2aa80f1013ecfe242536d32 source_hash: https://github.com/prometheus/haproxy_exporter/releases/download/v0.10.0/sha256sums.txt
args: args:
scrape_uri: 'unix:/run/haproxy/admin.sock' scrape_uri: 'unix:/run/haproxy/admin.sock'
rabbitmq: rabbitmq:

View file

@ -23,7 +23,7 @@ blackbox_exporter_bin_link:
blackbox_exporter_defaults: blackbox_exporter_defaults:
file.managed: file.managed:
- name: /etc/default/blackbox_exporter - name: /etc/default/blackbox_exporter
- source: salt://prometheus/files/default-blackbox_exporter.jinja - source: salt://prometheus-ng/files/default-blackbox_exporter.jinja
- template: jinja - template: jinja
- defaults: - defaults:
config_file: {{ prometheus.exporter.blackbox.args.config_file }} config_file: {{ prometheus.exporter.blackbox.args.config_file }}
@ -32,11 +32,17 @@ blackbox_exporter_service_unit:
file.managed: file.managed:
{%- if grains.get('init') == 'systemd' %} {%- if grains.get('init') == 'systemd' %}
- name: /etc/systemd/system/blackbox_exporter.service - name: /etc/systemd/system/blackbox_exporter.service
- source: salt://prometheus/files/blackbox_exporter.systemd.jinja - source: salt://prometheus-ng/files/exporter.systemd.jinja
{%- elif grains.get('init') == 'upstart' %} {%- elif grains.get('init') == 'upstart' %}
- name: /etc/init/blackbox_exporter.conf - name: /etc/init/blackbox_exporter.conf
- source: salt://prometheus/files/blackbox_exporter.upstart.jinja - source: salt://prometheus-ng/files/exporter.upstart.jinja
{%- endif %} {%- endif %}
- context:
svc: node_exporter
user: {{ prometheus.user }}
group: {{ prometheus.group }}
bin_path: {{ prometheus.exporter.node.version_path }}
args: {{ prometheus.exporter.get('args', []) }}
- require_in: - require_in:
- file: blackbox_exporter_service - file: blackbox_exporter_service

View file

@ -23,7 +23,7 @@ haproxy_exporter_bin_link:
haproxy_exporter_defaults: haproxy_exporter_defaults:
file.managed: file.managed:
- name: /etc/default/haproxy_exporter - name: /etc/default/haproxy_exporter
- source: salt://prometheus/files/default-haproxy_exporter.jinja - source: salt://prometheus-ng/files/default-haproxy_exporter.jinja
- template: jinja - template: jinja
- defaults: - defaults:
scrape_uri: {{ prometheus.exporter.haproxy.args.scrape_uri }} scrape_uri: {{ prometheus.exporter.haproxy.args.scrape_uri }}
@ -32,11 +32,17 @@ haproxy_exporter_service_unit:
file.managed: file.managed:
{%- if grains.get('init') == 'systemd' %} {%- if grains.get('init') == 'systemd' %}
- name: /etc/systemd/system/haproxy_exporter.service - name: /etc/systemd/system/haproxy_exporter.service
- source: salt://prometheus/files/haproxy_exporter.systemd.jinja - source: salt://prometheus-ng/files/exporter.systemd.jinja
{%- elif grains.get('init') == 'upstart' %} {%- elif grains.get('init') == 'upstart' %}
- name: /etc/init/haproxy_exporter.conf - name: /etc/init/haproxy_exporter.conf
- source: salt://prometheus/files/haproxy_exporter.upstart.jinja - source: salt://prometheus-ng/files/exporter.upstart.jinja
{%- endif %} {%- endif %}
- context:
svc: node_exporter
user: {{ prometheus.user }}
group: {{ prometheus.group }}
bin_path: {{ prometheus.exporter.node.version_path }}
args: {{ prometheus.exporter.get('args', []) }}
- require_in: - require_in:
- file: haproxy_exporter_service - file: haproxy_exporter_service

View file

@ -23,18 +23,24 @@ node_exporter_bin_link:
node_exporter_defaults: node_exporter_defaults:
file.managed: file.managed:
- name: /etc/default/node_exporter - name: /etc/default/node_exporter
- source: salt://prometheus/files/default-node_exporter.jinja - source: salt://prometheus-ng/files/default-node_exporter.jinja
- template: jinja - template: jinja
node_exporter_service_unit: node_exporter_service_unit:
file.managed: file.managed:
{%- if grains.get('init') == 'systemd' %} {%- if grains.get('init') == 'systemd' %}
- name: /etc/systemd/system/node_exporter.service - name: /etc/systemd/system/node_exporter.service
- source: salt://prometheus/files/node_exporter.systemd.jinja - source: salt://prometheus-ng/files/exporter.systemd.jinja
{%- elif grains.get('init') == 'upstart' %} {%- elif grains.get('init') == 'upstart' %}
- name: /etc/init/node_exporter.conf - name: /etc/init/node_exporter.conf
- source: salt://prometheus/files/node_exporter.upstart.jinja - source: salt://prometheus-ng/files/exporter.upstart.jinja
{%- endif %} {%- endif %}
- context:
svc: node_exporter
user: {{ prometheus.user }}
group: {{ prometheus.group }}
bin_path: {{ prometheus.exporter.node.version_path }}
args: {{ prometheus.exporter.get('args', []) }}
- require_in: - require_in:
- file: node_exporter_service - file: node_exporter_service

View file

@ -23,18 +23,24 @@ rabbitmq_exporter_bin_link:
rabbitmq_exporter_defaults: rabbitmq_exporter_defaults:
file.managed: file.managed:
- name: /etc/default/rabbitmq_exporter - name: /etc/default/rabbitmq_exporter
- source: salt://prometheus/files/default-rabbitmq_exporter.jinja - source: salt://prometheus-ng/files/default-rabbitmq_exporter.jinja
- template: jinja - template: jinja
rabbitmq_exporter_service_unit: rabbitmq_exporter_service_unit:
file.managed: file.managed:
{%- if grains.get('init') == 'systemd' %} {%- if grains.get('init') == 'systemd' %}
- name: /etc/systemd/system/rabbitmq_exporter.service - name: /etc/systemd/system/rabbitmq_exporter.service
- source: salt://prometheus/files/rabbitmq_exporter.systemd.jinja - source: salt://prometheus-ng/files/exporter.systemd.jinja
{%- elif grains.get('init') == 'upstart' %} {%- elif grains.get('init') == 'upstart' %}
- name: /etc/init/rabbitmq_exporter.conf - name: /etc/init/rabbitmq_exporter.conf
- source: salt://prometheus/files/rabbitmq_exporter.upstart.jinja - source: salt://prometheus-ng/files/exporter.upstart.jinja
{%- endif %} {%- endif %}
- context:
svc: node_exporter
user: {{ prometheus.user }}
group: {{ prometheus.group }}
bin_path: {{ prometheus.exporter.node.version_path }}
args: {{ prometheus.exporter.get('args', []) }}
- require_in: - require_in:
- file: rabbitmq_exporter_service - file: rabbitmq_exporter_service

View file

@ -0,0 +1,25 @@
[Unit]
Description=Prometheus {{ svc }} Exporter
{%- if url is string %}
Documentation={{ url }}
{%- endif %}
Wants=basic.target
After=basic.target network.target
[Service]
User={{ user }}
Group={{ group }}
EnvironmentFile=/etc/default/{{ svc }}
ExecStart={{ bin_path }}/{{ svc }} $ARGS
{%- if args is string %}} {{ args }}{% else %}
{%- for arg in args %}} \
{{ arg }}
{%- endfor %}
{%- endif %}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
RestartSec=42s
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,30 @@
# Prometheus {{ svc }} (Upstart unit)
description "Prometheus {{ svc }}"
start on runlevel [2345]
stop on runlevel [06]
env EXPORTER={{ bin_path }}/{{ svc }}
env USER={{ user }}
env GROUP={{ group }}
env DEFAULTS=/etc/default/{{ svc }}
env RUNDIR=/var/run/{{ svc }}
env PID_FILE=/var/run/{{ svc }}/{{ svc }}.pid
pre-start script
[ -e $DEFAULTS ] && . $DEFAULTS
mkdir -p $RUNDIR || true
chmod 0750 $RUNDIR || true
chown $USER:$GROUP $RUNDIR || true
end script
script
# read settings like GOMAXPROCS from "/etc/default/{{ svc }}", if available.
[ -e $DEFAULTS ] && . $DEFAULTS
export GOMAXPROCS=${GOMAXPROCS:-2}
exec start-stop-daemon -c $USER -g $GROUP -p $PID_FILE -x $EXPORTER -S -- $ARGS
end script
respawn
respawn limit 10 10
kill timeout 10

View file

@ -5,10 +5,15 @@ Wants=basic.target
After=basic.target network.target After=basic.target network.target
[Service] [Service]
User=prometheus User={{ user }}
Group=prometheus Group={{ group }}
EnvironmentFile=/etc/default/node_exporter EnvironmentFile=/etc/default/node_exporter
ExecStart=/usr/bin/node_exporter $ARGS ExecStart={{ bin_path }}/node_exporter $ARGS
{%- if args is string %}} {{ args }}{% else %}
{%- for arg in args %}} \
{{ arg }}
{%- endfor %}
{%- endif %}
ExecReload=/bin/kill -HUP $MAINPID ExecReload=/bin/kill -HUP $MAINPID
KillMode=process KillMode=process
Restart=always Restart=always

View file

@ -5,10 +5,10 @@ Wants=basic.target
After=basic.target network.target After=basic.target network.target
[Service] [Service]
User=prometheus User={{ user }}
Group=prometheus Group={{ user }}
EnvironmentFile=/etc/default/prometheus EnvironmentFile=/etc/default/prometheus
ExecStart=/usr/bin/prometheus $ARGS ExecStart={{ bin_path }}/prometheus $ARGS
ExecReload=/bin/kill -HUP $MAINPID ExecReload=/bin/kill -HUP $MAINPID
KillMode=process KillMode=process
Restart=always Restart=always

View file

@ -28,7 +28,7 @@ prometheus_server_config:
prometheus_defaults: prometheus_defaults:
file.managed: file.managed:
- name: /etc/default/prometheus - name: /etc/default/prometheus
- source: salt://prometheus/files/default-prometheus.jinja - source: salt://prometheus-ng/files/default-prometheus.jinja
- template: jinja - template: jinja
- defaults: - defaults:
config_file: {{ prometheus.server.args.config_file }} config_file: {{ prometheus.server.args.config_file }}
@ -51,11 +51,16 @@ prometheus_service_unit:
file.managed: file.managed:
{%- if grains.get('init') == 'systemd' %} {%- if grains.get('init') == 'systemd' %}
- name: /etc/systemd/system/prometheus.service - name: /etc/systemd/system/prometheus.service
- source: salt://prometheus/files/prometheus.systemd.jinja - source: salt://prometheus-ng/files/prometheus.systemd.jinja
{%- elif grains.get('init') == 'upstart' %} {%- elif grains.get('init') == 'upstart' %}
- name: /etc/init/prometheus.conf - name: /etc/init/prometheus.conf
- source: salt://prometheus/files/prometheus.upstart.jinja - source: salt://prometheus-ng/files/prometheus.upstart.jinja
{%- endif %} {%- endif %}
- context:
user: {{ prometheus.user }}
group: {{ prometheus.group }}
bin_path: {{ prometheus.exporter.node.version_path }}
args: {{ prometheus.exporter.get('args', []) }}
- watch: - watch:
- file: prometheus_defaults - file: prometheus_defaults
- require_in: - require_in: