Add collectd exporter.

This commit is contained in:
Michael Kutý 2017-05-13 20:51:26 +02:00
parent f79489cc95
commit edddd5a6ed
8 changed files with 142 additions and 1 deletions

View file

@ -0,0 +1,7 @@
applications:
- collect_exporter
parameters:
prometheus:
collectd_exporter:
enabled: true
push_path: 'collectd'

View file

@ -0,0 +1,56 @@
{% from "prometheus/map.jinja" import collectd_exporter with context %}
{%- if collectd_exporter.enabled %}
{%- if not (pillar.docker is defined and pillar.docker.host is defined) %}
include:
- prometheus.common
collectd_exporter_tarball:
archive.extracted:
- name: {{ collectd_exporter.dir.install }}
- source: {{ collectd_exporter.source }}
- source_hash: sha1={{ collectd_exporter.source_hash }}
- archive_format: tar
- if_missing: {{ collectd_exporter.dir.version_path }}
collectd_exporter_bin_link:
file.symlink:
- name: /usr/bin/collectd_exporter
- target: {{ collectd_exporter.dir.version_path }}/collectd_exporter
- require:
- archive: collectd_exporter_tarball
collectd_exporter_defaults:
file.managed:
- name: /etc/default/collectd_exporter
- source: salt://prometheus/files/default-collectd_exporter.jinja
- template: jinja
collectd_exporter_service_unit:
file.managed:
{%- if grains.get('init') == 'systemd' %}
- name: /etc/systemd/system/collectd_exporter.service
- source: salt://prometheus/files/collectd_exporter.systemd.jinja
{%- elif grains.get('init') == 'upstart' %}
- name: /etc/init/collectd_exporter.conf
- source: salt://prometheus/files/collectd_exporter.upstart.jinja
{%- endif %}
- watch:
- file: collectd_exporter_defaults
- require_in:
- file: collectd_exporter_service
collectd_exporter_service:
service.running:
- name: collectd_exporter
- enable: True
- reload: True
- watch:
- file: collectd_exporter_service_unit
- file: collectd_exporter_bin_link
{%- endif %}
{%- endif %}

View file

@ -0,0 +1,18 @@
[Unit]
Description="An exporter for collectd. It accepts collectd's binary network protocol as sent by collectd's network plugin and metrics in JSON format via HTTP POST as sent by collectd's write_http plugin, and transforms and exposes them for consumption by Prometheus."
Documentation=https://prometheus.io/docs/alerting/collectd_exporter/
Wants=basic.target
After=basic.target network.target
[Service]
User=prometheus
Group=prometheus
EnvironmentFile=/etc/default/collectd_exporter
ExecStart=/usr/bin/collectd_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 Alert Manager (Upstart unit)
description "An exporter for collectd. It accepts collectd's binary network protocol as sent by collectd's network plugin and metrics in JSON format via HTTP POST as sent by collectd's write_http plugin, and transforms and exposes them for consumption by Prometheus."
start on runlevel [2345]
stop on runlevel [06]
env ALERTMANAGER=/usr/bin/collectd_exporter
env USER=prometheus
env GROUP=prometheus
env DEFAULTS=/etc/default/collectd_exporter
env RUNDIR=/var/run/collectd_exporter
env PID_FILE=/var/run/collectd_exporter/collectd_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/collectd_exporter", if available.
[ -e $DEFAULTS ] && . $DEFAULTS
export GOMAXPROCS=${GOMAXPROCS:-2}
exec start-stop-daemon -c $USER -g $GROUP -p $PID_FILE -x $ALERTMANAGER -S -- $ARGS
end script
respawn
respawn limit 10 10
kill timeout 10

View file

@ -0,0 +1,3 @@
{%- from "prometheus/map.jinja" import collectd_exporter with context %}
# Set the command-line arguments to pass to the server.
ARGS="-collectd.listen-address {{ collectd_exporter.bind.address }}:{{ collectd_exporter.bind.port }} -web.collectd-push-path {{ collectd_exporter.push_path }} "

View file

@ -1,7 +1,7 @@
{%- from "prometheus/map.jinja" import server with context %}
# Set the command-line arguments to pass to the server.
ARGS="-config.file {{server.dir.config}}/prometheus.yml -storage.local.path {{server.dir.storage}} -web.console.libraries {{server.dir.version_path}}/console_libraries -web.console.templates {{ server.dir.version_path }}/consoles -alertmanager.url {%- if server.alertmanager is defined %}{{server.alertmanager.get('host', 'localhost')}}:{{server.alertmanager.get('port', 9093)}}{%- endif %}"
ARGS="-config.file {{server.dir.config}}/prometheus.yml -storage.local.path {{server.dir.storage}} -web.console.libraries {{server.dir.version_path}}/console_libraries -web.console.templates {{ server.dir.version_path }}/consoles {%- if server.alertmanager is defined %} -alertmanager.url {{server.alertmanager.get('protocol', 'http')}}://{{server.alertmanager.get('host', 'localhost')}}:{{server.alertmanager.get('port', 9093)}}{%- endif %}"
# Prometheus supports the following options:

View file

@ -68,3 +68,29 @@ Debian:
{%- endload %}
{%- set pushgateway = salt['grains.filter_by'](pushgateway_defaults, merge=salt['pillar.get']('prometheus:pushgateway')) %}
{%- set collectd_exporter_version = pillar.prometheus.get('collectd_exporter', {}).get('version', '0.3.1') %}
{%- load_yaml as collectd_exporter_defaults %}
{%- if pillar.docker is defined and pillar.docker.host is defined %}
Debian:
dir:
config: /srv/volumes/prometheus
{%- else %}
Debian:
dir:
config: /etc/prometheus
storage: /var/lib/prometheus-collectd_exporter/metrics
install: /opt
version_path: /opt/collectd_exporter-{{ collectd_exporter_version }}.linux-amd64
version: {{ collectd_exporter_version }}.linux-amd64
source: https://github.com/prometheus/collectd_exporter/releases/download/{{ collectd_exporter_version }}/collectd_exporter-{{ collectd_exporter_version }}.linux-amd64.tar.gz
source_hash: 6460a15dab512f7485d7974d115677e9406d53fd
bind:
address: ''
port: 25826
push_path: ''
{%- endif %}
{%- endload %}
{%- set collectd_exporter = salt['grains.filter_by'](collectd_exporter_defaults, merge=salt['pillar.get']('prometheus:collectd_exporter')) %}

View file

@ -61,6 +61,7 @@ prometheus_service:
- file: prometheus_service_unit
- file: {{server.dir.config}}/prometheus.yml
- file: prometheus_bin_link
- file: {{server.dir.config}}/alerts.yml
{%- endif %}