Add haproxy_exporter

This commit is contained in:
Ricardo Hernandez 2016-12-12 17:45:30 +00:00
parent f9363e9e27
commit 17958a7e81
5 changed files with 109 additions and 0 deletions

View file

@ -30,3 +30,10 @@ prometheus:
source_hash: sha1=89ac98c062315ba35eda257ca88c8c4b43f38d47
args:
config_file: /etc/prometheus/blackbox_exporter.yml
haproxy:
version: 0.7.1.linux-amd64
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_hash: sha1=56849253e280db3db2aa80f1013ecfe242536d32
args:
scrape_uri: 'http://localhost/stats;csv'

View file

@ -0,0 +1,49 @@
{% from "prometheus/map.jinja" import prometheus with context %}
{%- set version_path = haproxy.exporters.haproxy.install_dir ~ "/haproxy_exporter-" ~ prometheus.exporters.haproxy.version %}
include:
- prometheus.user
haproxy_exporter_tarball:
archive.extracted:
- name: {{ prometheus.exporters.haproxy.install_dir }}
- source: {{ prometheus.exporters.haproxy.source }}
- source_hash: {{ prometheus.exporters.haproxy.source_hash }}
- archive_format: tar
- if_missing: {{ version_path }}
haproxy_exporter_bin_link:
file.symlink:
- name: /usr/bin/haproxy_exporter
- target: {{ version_path }}/haproxy_exporter
- require:
- archive: haproxy_exporter_tarball
haproxy_exporter_defaults:
file.managed:
- name: /etc/default/haproxy_exporter
- source: salt://prometheus/files/default-haproxy_exporter.jinja
- template: jinja
- defaults:
scrape_uri: {{ prometheus.exporters.haproxy.args.scrape_uri }}
haproxy_exporter_service_unit:
file.managed:
{%- if grains.get('init') == 'systemd' %}
- name: /etc/systemd/system/haproxy_exporter.service
- source: salt://prometheus/files/haproxy_exporter.systemd.jinja
{%- elif grains.get('init') == 'upstart' %}
- name: /etc/init/haproxy_exporter.conf
- source: salt://prometheus/files/haproxy_exporter.upstart.jinja
{%- endif %}
- require_in:
- file: haproxy_exporter_service
haproxy_exporter_service:
service.running:
- name: haproxy_exporter
- enable: True
- reload: True
- watch:
- file: haproxy_exporter_defaults
- file: haproxy_exporter_bin_link

View file

@ -0,0 +1,5 @@
# Set the command-line arguments to pass to the haproxy_exporter service.
ARGS='-haproxy.scrape-uri="{{scrape_uri}}"'
# Haproxy exporter supports the following options:
# -haproxy.scrape-uri string

View file

@ -0,0 +1,18 @@
[Unit]
Description=Prometheus haproxy exporter
Documentation=https://github.com/prometheus/haproxy_exporter
Wants=basic.target
After=basic.target network.target
[Service]
User=prometheus
Group=prometheus
EnvironmentFile=/etc/default/haproxy_exporter
ExecStart=/usr/bin/haproxy_exporter $ARGS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
RestartSec=42s
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,30 @@
# Prometheus Haproxy exporter (Upstart unit)
description "Prometheus Haproxy exporter"
start on runlevel [2345]
stop on runlevel [06]
env HAPROXY_EXPORTER=/usr/bin/haproxy_exporter
env USER=prometheus
env GROUP=prometheus
env DEFAULTS=/etc/default/haproxy_exporter
env RUNDIR=/var/run/haproxy_exporter
env PID_FILE=/var/run/haproxy_exporter/haproxy_exporter.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/haproxy_exporter", if available.
[ -e $DEFAULTS ] && . $DEFAULTS
export GOMAXPROCS=${GOMAXPROCS:-2}
exec start-stop-daemon -c $USER -g $GROUP -p $PID_FILE -x $HAPROXY_EXPORTER -S -- $ARGS
end script
respawn
respawn limit 10 10
kill timeout 10