feat(textfile_collectors): added support for textfile collectors

This commit is contained in:
Alexander Weidinger 2019-10-04 01:16:27 +02:00 committed by alxwr
parent a0d8ad4c35
commit 930552d7ee
8 changed files with 103 additions and 0 deletions

View File

@ -123,3 +123,9 @@ This state will uninstall the prometheus linux alternatives for archives only.
^^^^^^^^^^^^^^^^^^^^^^^^^
This state will uninstall the prometheus upstream package repository only.
``prometheus.config.node_exporter.textfile_collectors``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This state will manage the node exporter's textfile collectors
according to Pillar ``prometheus:exporters:node_exporter:textfile_collectors``.

View File

@ -35,6 +35,7 @@ prometheus:
node_exporter:
args:
web.listen-address: ":9110"
# collector.textfile.directory: /var/tmp/node_exporter
tofs:
# The files_switch key serves as a selector for alternative
@ -164,3 +165,7 @@ prometheus:
# 'Alternatives system' priority: zero disables (default)
# yamllint disable-line rule:braces
altpriority: {{ range(1, 9100000) | random }}
exporters:
node_exporter:
textfile_collectors: {}

View File

@ -5,3 +5,4 @@ include:
- .file.clean
- .args.clean
- .users.clean
- .node_exporter.textfile_collectors.clean

View File

@ -1,7 +1,14 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
include:
- .users
- .args
- .file
{%- if 'node_exporter' in prometheus.wanted %}
- .node_exporter.textfile_collectors
{%- endif %}

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
prometheus-node_exporter-textfile_collectors-dir:
file.absent:
- name: {{ prometheus.dir.textfile_collectors }}
prometheus-node_exporter-textfile-dir:
file.absent:
- name: {{ prometheus.service.node_exporter.args.get('collector.textfile.directory') }}
{%- for collector, config in prometheus.get('exporters', {}).get('node_exporter', {}).get('textfile_collectors', {}).items() %}
include:
- .{{ collector }}.clean
{%- endfor %}

View File

@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
prometheus-node_exporter-textfile_collectors-dir:
file.directory:
- name: {{ prometheus.dir.textfile_collectors }}
- mode: 755
- user: node_exporter
- group: node_exporter
- makedirs: True
prometheus-node_exporter-textfile-dir:
file.directory:
- name: {{ prometheus.service.node_exporter.args.get('collector.textfile.directory') }}
- mode: 755
- user: node_exporter
- group: node_exporter
- makedirs: True
{%- set states = [] %}
{%- for collector, config in prometheus.get('exporters', {}).get('node_exporter', {}).get('textfile_collectors', {}).items() %}
{%- if config.get('enable', False) %}
{%- if config.get('remove', False) %}
{%- set state = ".{}.clean".format(collector) %}
{%- else %}
{%- set state = ".{}".format(collector) %}
{%- endif %}
{%- do states.append(state) %}
{%- endif %}
{%- endfor %}
{%- if states|length > 0 %}
prometheus-node_exporter-textfile-dependencies:
pkg.installed:
- pkgs: {{ prometheus.exporters.node_exporter.textfile_collectors_dependencies }}
- require_in:
{%- for state in states %}
- sls: prometheus.config.node_exporter.textfile_collectors{{ state }}
{%- endfor %}
include:
{%- for state in states %}
- {{ state }}
{% endfor %}
{%- endif %}

View File

@ -21,16 +21,21 @@ prometheus:
var: /var/lib/prometheus
args: /etc/default
service: /usr/lib/systemd/system
textfile_collectors: /opt/prometheus/textfile_collectors
service:
prometheus:
args:
web.listen-address: 0.0.0.0:9090
alertmanager: {}
node_exporter:
args:
collector.textfile.directory: /var/tmp/node_exporter
config:
prometheus: {}
alertmanager: {}
node_exporter: {}
pkg:
prometheus:
@ -113,3 +118,8 @@ prometheus:
linux:
altpriority: 0 ## 'Alternatives system' priority: zero disables (default)
exporters:
node_exporter:
textfile_collectors_dependencies: []
textfile_collectors: {}

View File

@ -18,6 +18,10 @@ Debian:
service:
node_exporter:
name: prometheus-node-exporter
exporters:
node_exporter:
textfile_collectors_dependencies:
- cron
RedHat:
pkg: