From 17958a7e812e4eb37c432c51d2b44b773aebe503 Mon Sep 17 00:00:00 2001 From: Ricardo Hernandez Date: Mon, 12 Dec 2016 17:45:30 +0000 Subject: [PATCH] Add haproxy_exporter --- prometheus/defaults.yaml | 7 +++ prometheus/exporters/haproxy.sls | 49 +++++++++++++++++++ .../files/default-haproxy_exporter.jinja | 5 ++ .../files/haproxy_exporter.systemd.jinja | 18 +++++++ .../files/haproxy_exporter.upstart.jinja | 30 ++++++++++++ 5 files changed, 109 insertions(+) create mode 100644 prometheus/exporters/haproxy.sls create mode 100644 prometheus/files/default-haproxy_exporter.jinja create mode 100644 prometheus/files/haproxy_exporter.systemd.jinja create mode 100644 prometheus/files/haproxy_exporter.upstart.jinja diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index 5bf8ae8..03fed6c 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -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' diff --git a/prometheus/exporters/haproxy.sls b/prometheus/exporters/haproxy.sls new file mode 100644 index 0000000..855fa50 --- /dev/null +++ b/prometheus/exporters/haproxy.sls @@ -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 diff --git a/prometheus/files/default-haproxy_exporter.jinja b/prometheus/files/default-haproxy_exporter.jinja new file mode 100644 index 0000000..4ede322 --- /dev/null +++ b/prometheus/files/default-haproxy_exporter.jinja @@ -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 \ No newline at end of file diff --git a/prometheus/files/haproxy_exporter.systemd.jinja b/prometheus/files/haproxy_exporter.systemd.jinja new file mode 100644 index 0000000..447d458 --- /dev/null +++ b/prometheus/files/haproxy_exporter.systemd.jinja @@ -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 diff --git a/prometheus/files/haproxy_exporter.upstart.jinja b/prometheus/files/haproxy_exporter.upstart.jinja new file mode 100644 index 0000000..a698a67 --- /dev/null +++ b/prometheus/files/haproxy_exporter.upstart.jinja @@ -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