Rewrote exporters to write systemd service
This commit is contained in:
parent
4b31e677ca
commit
4591d58fe4
2 changed files with 45 additions and 20 deletions
|
@ -1,25 +1,11 @@
|
|||
{% from "prometheus/map.jinja" import exporters with context %}
|
||||
{%- for exporter, parameters in exporters.iteritems() %}
|
||||
{%- if parameters.get('enabled', False) %}
|
||||
{%- if parameters.get('packages', False) %}
|
||||
{{ exporter }}_exporter_packages:
|
||||
pkg.installed:
|
||||
- names: {{ parameters.packages }}
|
||||
{%- else %}
|
||||
{{ exporter }}-exporter-bin-dir:
|
||||
file.directory:
|
||||
- name: /opt/prometheus/{{ exporter }}/bin
|
||||
- makedirs: True
|
||||
|
||||
{#
|
||||
{{ exporter }}-exporter-download:
|
||||
file.managed:
|
||||
- name: /tmp/prometheus_{{ exporter }}_{{ grains.osarch }}.tar.gz
|
||||
- source: {{ parameters.url }}
|
||||
- source_hash: {{ parameters.url_hash }}
|
||||
- unless: test -f /opt/prometheus/{{ exporter }}/bin/{{ parameters.check }}
|
||||
#}
|
||||
|
||||
{{ exporter }}_exporter_extracted:
|
||||
archive.extracted:
|
||||
- name: /opt/prometheus/{{ exporter }}/bin
|
||||
|
@ -30,7 +16,8 @@
|
|||
- user: root
|
||||
- group: root
|
||||
- if_missing: /opt/prometheus/{{ exporter }}/bin/{{ parameters.check }}
|
||||
{%- endif %}
|
||||
- require:
|
||||
- file: {{ exporter }}-exporter-bin-dir
|
||||
|
||||
{{ exporter }}_exporter_service:
|
||||
service.running:
|
||||
|
@ -46,9 +33,29 @@
|
|||
|
||||
{%- for svc, svc_parameters in parameters.get('services', {}).iteritems() %}
|
||||
{%- if svc_parameters.get('enabled', False) %}
|
||||
{%- if svc_parameters.template is defined %}
|
||||
{%- set jmxbind = svc_parameters.get('jmx_bind', {}) %}
|
||||
{{ exporter }}_{{ svc }}_exporter_config_file:
|
||||
|
||||
{{ exporter }}_{{ svc }}_exporter_systemd_unit:
|
||||
file.managed:
|
||||
- name: /etc/systemd/system/{{ svc }}.service
|
||||
- template: jinja
|
||||
- source:
|
||||
- salt://{{ svc_parameters.get('template', 'prometheus/files/exporter/service') }}
|
||||
- context:
|
||||
exporter: {{ exporter }}
|
||||
svc_name: {{ svc }}
|
||||
svc_args: {{ svc_parameters.args }}
|
||||
user: {{ svc_parameters.get('user', 'root') }}
|
||||
group: {{ svc_parameters.get('group', 'root') }}
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 0644
|
||||
- require:
|
||||
- archive: {{ exporter }}_exporter_extracted
|
||||
- watch_in:
|
||||
- service: {{ exporter }}_exporter_service
|
||||
|
||||
{#
|
||||
{{ _exporter_serviceorter }}_{{ svc }}_exporter_config_file:
|
||||
file.managed:
|
||||
- name: /etc/exporters/{{ exporter }}_{{ svc }}-running.yml
|
||||
- template: jinja
|
||||
|
@ -67,8 +74,8 @@
|
|||
{%- endif %}
|
||||
- watch_in:
|
||||
- service: {{ exporter }}_exporter_service
|
||||
{%- endif %}
|
||||
|
||||
#}
|
||||
{#
|
||||
{%- if parameters.template is defined %}
|
||||
{%- set template = parameters.template %}
|
||||
{%- set bind = svc_parameters.get('bind', {}) %}
|
||||
|
@ -89,6 +96,7 @@
|
|||
- watch_in:
|
||||
- service: {{ exporter }}_exporter_service
|
||||
{%- endif %}
|
||||
#}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
{%- endif %}
|
||||
|
|
17
prometheus/files/exporter/service
Normal file
17
prometheus/files/exporter/service
Normal file
|
@ -0,0 +1,17 @@
|
|||
[Unit]
|
||||
Description=Prometheus {{ exporter }} Exporter
|
||||
Documentation=https://prometheus.io/docs/introduction/overview/
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=-/etc/default/{{ svc }}
|
||||
User={{ user }}
|
||||
Group={{ user }}
|
||||
Restart=on-failure
|
||||
ExecStart=/opt/prometheus/{{ exporter }}/bin/{{ svc }} \
|
||||
{% if svc_args is string %}{{ svc_args }}{% else %}
|
||||
{% for svc_arg in svc_args %} {{ svc_arg }}{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in a new issue