diff --git a/docs/README.rst b/docs/README.rst index 17576e1..388f48e 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -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``. diff --git a/pillar.example b/pillar.example index e86bf40..f47caf2 100644 --- a/pillar.example +++ b/pillar.example @@ -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: {} diff --git a/prometheus/config/clean.sls b/prometheus/config/clean.sls index cf7559a..31b864c 100644 --- a/prometheus/config/clean.sls +++ b/prometheus/config/clean.sls @@ -5,3 +5,4 @@ include: - .file.clean - .args.clean - .users.clean + - .node_exporter.textfile_collectors.clean diff --git a/prometheus/config/init.sls b/prometheus/config/init.sls index 6923174..6eee8cd 100644 --- a/prometheus/config/init.sls +++ b/prometheus/config/init.sls @@ -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 %} diff --git a/prometheus/config/node_exporter/textfile_collectors/clean.sls b/prometheus/config/node_exporter/textfile_collectors/clean.sls new file mode 100644 index 0000000..9067c13 --- /dev/null +++ b/prometheus/config/node_exporter/textfile_collectors/clean.sls @@ -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 %} + diff --git a/prometheus/config/node_exporter/textfile_collectors/init.sls b/prometheus/config/node_exporter/textfile_collectors/init.sls new file mode 100644 index 0000000..d3f5538 --- /dev/null +++ b/prometheus/config/node_exporter/textfile_collectors/init.sls @@ -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 %} diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index dff19c5..81bc72d 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -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: {} diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index cce0227..b5243a8 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -18,6 +18,10 @@ Debian: service: node_exporter: name: prometheus-node-exporter + exporters: + node_exporter: + textfile_collectors_dependencies: + - cron RedHat: pkg: