From 731198dd4d0447b01529467873d495f7a67fb31e Mon Sep 17 00:00:00 2001 From: N Date: Thu, 20 Jun 2019 01:36:58 +0100 Subject: [PATCH] test(centos): verified on CentosOS --- pillar.example | 161 +++++++++++++----- prometheus/archive/alternatives/clean.sls | 33 ++-- prometheus/archive/alternatives/install.sls | 59 ++++--- prometheus/archive/clean.sls | 37 ++-- prometheus/archive/defaults.yaml | 89 ---------- prometheus/archive/init.sls | 2 +- prometheus/archive/install.sls | 95 ++++++----- prometheus/config/args.sls | 54 ------ prometheus/config/args/clean.sls | 57 +++++++ prometheus/config/args/init.sls | 5 + prometheus/config/args/install.sls | 86 ++++++++++ prometheus/config/clean.sls | 16 +- prometheus/config/environ.sls | 29 ---- prometheus/config/file.sls | 36 ---- prometheus/config/file/clean.sls | 21 +++ prometheus/config/file/init.sls | 5 + prometheus/config/file/install.sls | 35 ++++ prometheus/config/init.sls | 5 - prometheus/defaults.yaml | 115 +++++++++++-- prometheus/exporters/init.sls | 14 -- prometheus/exporters/node/clean.sls | 28 --- prometheus/exporters/node/init.sls | 64 ------- ...{prometheus.yml.jinja => config.yml.jinja} | 0 .../{prometheus.sh.jinja => default.sh.jinja} | 4 +- prometheus/files/default/systemd.ini.jinja | 5 +- prometheus/init.sls | 2 +- prometheus/map.jinja | 14 +- prometheus/osfamilymap.yaml | 160 ++++++++++------- prometheus/osfingermap.yaml | 14 -- prometheus/osmap.yaml | 25 --- prometheus/package/clean.sls | 16 +- prometheus/package/install.sls | 8 +- prometheus/service/clean.sls | 13 +- prometheus/service/running.sls | 47 +++-- prometheus/systemd.sls | 0 35 files changed, 699 insertions(+), 655 deletions(-) delete mode 100644 prometheus/archive/defaults.yaml delete mode 100644 prometheus/config/args.sls create mode 100644 prometheus/config/args/clean.sls create mode 100644 prometheus/config/args/init.sls create mode 100644 prometheus/config/args/install.sls delete mode 100644 prometheus/config/environ.sls delete mode 100644 prometheus/config/file.sls create mode 100644 prometheus/config/file/clean.sls create mode 100644 prometheus/config/file/init.sls create mode 100644 prometheus/config/file/install.sls delete mode 100644 prometheus/exporters/init.sls delete mode 100644 prometheus/exporters/node/clean.sls delete mode 100644 prometheus/exporters/node/init.sls rename prometheus/files/default/{prometheus.yml.jinja => config.yml.jinja} (100%) rename prometheus/files/default/{prometheus.sh.jinja => default.sh.jinja} (78%) delete mode 100644 prometheus/osfingermap.yaml delete mode 100644 prometheus/osmap.yaml delete mode 100644 prometheus/systemd.sls diff --git a/pillar.example b/pillar.example index 3b01a01..9608538 100644 --- a/pillar.example +++ b/pillar.example @@ -2,24 +2,31 @@ # vim: ft=yaml --- prometheus: - pkg: - name: prometheus - use_upstream_archive: False - archive: - source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz - source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 - archive_format: tar - enforce_toplevel: False - config_file: /etc/prometheus/prometheus.yml - environ_file: /etc/default/prometheus.sh - service: - name: prometheus - args: - web.listen-address: 0.0.0.0:9090 + wanted: + - prometheus + - pushgateway + - node_explorer - linux: - #'Alternatives system' priority: zero disables (default) - altpriority: 0 + use_upstream_archive: True + pkg: + prometheus: + archive_version: 2.10.0 + archive_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 + alertmanager: + archive_version: '0.17.0' + archive_hash: ec171b13976baceace193461f8a1e61021ab9657df5ba45157cd0095aee7d569 + + service: + prometheus + args: + web.listen-address: 0.0.0.0:9090 + pushgateway: + args: + web.listen-address: ":9091" + web.telemetry-path: "/metrics" + node_exporter: + args: + web.listen-address: ":9110" tofs: # The files_switch key serves as a selector for alternative @@ -45,40 +52,100 @@ prometheus: # - 'example_alt.tmpl.jinja' # Pillar-based config - environ: - - 'export PATH=${PATH}:/opt/prometheus-2.10.0.linux-amd64' config: - # my global config - global: - scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. - evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. - # scrape_timeout is set to the global default (10s). + prometheus: + # ref https://raw.githubusercontent.com/prometheus/prometheus/release-2.10/config/testdata/conf.good.yml + # my global config + global: + scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. + evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. + # scrape_timeout is set to the global default (10s). - # Alertmanager configuration - alerting: - alertmanagers: - - static_configs: - - targets: - # - alertmanager:9093 + # Alertmanager configuration + alerting: + alertmanagers: + - static_configs: + - targets: + # - alertmanager:9093 - # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. - rule_files: - # - "first_rules.yml" - # - "second_rules.yml" + # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. + rule_files: + # - "first_rules.yml" + # - "second_rules.yml" - # A scrape configuration containing exactly one endpoint to scrape: - # Here it's Prometheus itself. - scrape_configs: - # The job name is added as a label `job=` to any timeseries scraped from this config. - - job_name: 'prometheus' + # A scrape configuration containing exactly one endpoint to scrape: + scrape_configs: + # The job name is added as a label `job=` to any timeseries scraped from this config. + - job_name: 'prometheus' + # metrics_path defaults to '/metrics' + # scheme defaults to 'http'. + static_configs: + - targets: ['localhost:9090'] - # metrics_path defaults to '/metrics' - # scheme defaults to 'http'. + - job_name: pushgateway + scrape_interval: 5s + honor_labels: true + static_configs: + - targets: ['pushgateway:9091'] - static_configs: - - targets: ['localhost:9090'] + - job_name: 'blackbox' + # ref https://github.com/prometheus/blackbox_exporter#prometheus-configuration + metrics_path: /probe + params: + module: [http_2xx] # Look for a HTTP 200 response. + static_configs: + - targets: + - http://prometheus.io # Target to probe with http. + - https://prometheus.io # Target to probe with https. + - http://example.com:8080 # Target to probe with http on port 8080. + relabel_configs: + - source_labels: [__address__] + target_label: __param_target + - source_labels: [__param_target] + target_label: instance + - target_label: __address__ + replacement: 127.0.0.1:9115 # The blackbox exporter's real hostname:port. + + alertmanager: + # ref https://github.com/prometheus/alertmanager/blob/master/config/testdata/conf.good.yml + global: + smtp_smarthost: 'localhost:25' + smtp_from: 'alertmanager@example.org' + smtp_auth_username: 'alertmanager' + smtp_auth_password: "multiline\nmysecret" + smtp_hello: "host.example.org" + slack_api_url: "http://mysecret.example.com/" + http_config: + proxy_url: 'http://127.0.0.1:1025' + route: + group_by: ['alertname', 'cluster', 'service'] + group_wait: 30s + group_interval: 5m + repeat_interval: 3h + receiver: team-X-mails + routes: + - match_re: + service: ^(foo1|foo2|baz)$ + receiver: team-X-mails + routes: + - match: + severity: critical + receiver: team-X-mails + receivers: + - name: 'team-X-mails' + email_configs: + - to: 'team-X+alerts@example.org' + + inhibit_rules: + - name: opsGenie-receiver + opsgenie_configs: + - api_key: mysecret + - name: slack-receiver + slack_configs: + - channel: '#my-channel' + image_url: 'http://some.img.com/img.png' + + linux: + #'Alternatives system' priority: zero disables (default) + altpriority: 0 - exporters: - node: - args: - web.listen-address: ":9110" diff --git a/prometheus/archive/alternatives/clean.sls b/prometheus/archive/alternatives/clean.sls index 243a3e7..99aec88 100644 --- a/prometheus/archive/alternatives/clean.sls +++ b/prometheus/archive/alternatives/clean.sls @@ -4,33 +4,26 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} -{%- set sls_archive_clean = tplroot ~ '.archive.clean' %} {%- if grains.kernel|lower == 'linux' and p.linux.altpriority|int > 0 %} -include: - - {{ sls_archive_clean }} + {%- for name in p.wanted %} + {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} - {%- for k in p.archive.wanted %} - {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} - -prometheus-archive-remove-{{ k }}-home-alternatives-remove: +prometheus-archive-remove-{{ name }}-home-alternatives-remove: alternatives.remove: - - name: prometheus-{{ k }}-home - - path: {{ dir }} - - onlyif: update-alternatives --get-selections |grep ^prometheus-{{ k }}-home - - require: - - sls: {{ sls_archive_clean }} + - name: prometheus-{{ name }}-home + - path: {{ p.dir.basedir }}/{{ bundle }} + - onlyif: update-alternatives --get-selections |grep ^prometheus-{{ name }}-home - {% for i in p.archive.binaries[k] %} -prometheus-archive-remove-{{ k }}-alternatives-remove-{{ i }}: + {% for b in p.pkg[name]['binaries'] %} + +prometheus-archive-remove-{{ name }}-alternatives-remove-{{ b }}: alternatives.remove: - - name: prometheus-{{ k }}-{{ i }} - - path: {{ dir }}/{{ i }} - - onlyif: update-alternatives --get-selections |grep ^prometheus-{{ k }}-{{ i }} - - require: - - sls: {{ sls_archive_clean }} + - name: prometheus-{{ name }}-{{ b }} + - path: {{ p.dir.basedir }}/{{ bundle }}/{{ b }} + - onlyif: update-alternatives --get-selections |grep ^prometheus-{{ name }}-{{ b }} + {% endfor %} - {% endfor %} {%- endif %} diff --git a/prometheus/archive/alternatives/install.sls b/prometheus/archive/alternatives/install.sls index 191ae23..b6b17e5 100644 --- a/prometheus/archive/alternatives/install.sls +++ b/prometheus/archive/alternatives/install.sls @@ -12,67 +12,66 @@ include: - {{ sls_archive_install }} - {%- for k in p.archive.wanted %} - {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} + {%- for name in p.wanted %} + {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} -prometheus-archive-alternatives-install-{{ k }}-home-cmd-run: +prometheus-archive-alternatives-install-{{ name }}-home-cmd-run: cmd.run: - onlyif: {{ grains.os_family in ('Suse',) }} - - name: update-alternatives --install {{ dir }} prometheus-{{ k }}-home {{ dir }} {{p.linux.altpriority}} + - name: update-alternatives --install {{ p.dir.basedir }}/{{ bundle }} prometheus-{{ name }}-home {{ p.dir.basedir }}/{{ bundle }} {{p.linux.altpriority}} - watch: - - archive: prometheus-archive-install-{{ k }}-archive-extracted + - archive: prometheus-archive-install-{{ name }}-archive-extracted - require: - sls: {{ sls_archive_install }} -prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install: +prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install: alternatives.install: - - name: prometheus-{{ k }}-home - - link: {{ p.archive.dir.opt }}/{{ k }} - - path: {{ dir }} + - name: prometheus-{{ name }}-home + - link: {{ p.dir.basedir }}/{{ name }} + - path: {{ p.dir.basedir }}/{{ bundle }} - priority: {{ p.linux.altpriority }} - order: 10 - watch: - - archive: prometheus-archive-install-{{ k }}-archive-extracted + - archive: prometheus-archive-install-{{ name }}-archive-extracted - require: - sls: {{ sls_archive_install }} - onlyif: {{ grains.os_family not in ('Suse',) }} -prometheus-archive-alternatives-install-{{ k }}-home-alternatives-set: +prometheus-archive-alternatives-install-{{ name }}-home-alternatives-set: alternatives.set: - - name: prometheus-{{ k }}-home - - path: {{ dir }} + - name: prometheus-{{ name }}-home + - path: {{ p.dir.basedir }}/{{ bundle }} - require: - - cmd: prometheus-archive-alternatives-install-{{ k }}-home-cmd-run - - alternatives: prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install + - cmd: prometheus-archive-alternatives-install-{{ name }}-home-cmd-run + - alternatives: prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install - onlyif: {{ grains.os_family not in ('Suse',) }} + {% for b in p.pkg[name]['binaries'] %} - {% for i in p.archive.binaries[k] %} - -prometheus-archive-alternatives-install-{{ k }}-alternatives-install-{{ i }}: +prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }}: cmd.run: - onlyif: {{ grains.os_family in ('Suse',) }} - - name: update-alternatives --install /usr/bin/{{i}} prometheus-{{ k }}-{{i}} {{ dir }}/{{i}} {{p.linux.altpriority}} + - name: update-alternatives --install /usr/local/bin/{{ b }} prometheus-{{ name }}-{{ b }} {{ p.dir.basedir }}/{{ bundle }}/{{ b }} {{ p.linux.altpriority }} - require: - - cmd: prometheus-archive-alternatives-install-{{ k }}-home-cmd-run + - cmd: prometheus-archive-alternatives-install-{{ name }}-home-cmd-run alternatives.install: - - name: prometheus-{{ k }}-{{ i }} - - link: /usr/bin/{{ i }} - - path: {{ dir }}/{{ i }} + - name: prometheus-{{ name }}-{{ b }} + - link: /usr/local/bin/{{ b }} + - path: {{ p.dir.basedir }}/{{ bundle }}/{{ b }} - priority: {{ p.linux.altpriority }} - order: 10 - require: - - alternatives: prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install + - alternatives: prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install - onlyif: {{ grains.os_family not in ('Suse',) }} -prometheus-archive-alternatives-install-{{ k }}-alternatives-set-{{ i }}: +prometheus-archive-alternatives-install-{{ name }}-alternatives-set-{{ b }}: alternatives.set: - - name: prometheus-{{ k }}-{{ i }} - - path: {{ dir }}/{{ i }} + - name: prometheus-{{ name }}-{{ b }} + - path: {{ p.dir.basedir }}/{{ bundle }}/{{ b }} - require: - - alternatives: prometheus-archive-alternatives-install-{{ k }}-alternatives-install-{{ i }} + - alternatives: prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }} - onlyif: {{ grains.os_family not in ('Suse',) }} + {% endfor %} - - {% endfor %} + {% endfor %} {%- endif %} diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls index 047e86d..a1bfe5e 100644 --- a/prometheus/archive/clean.sls +++ b/prometheus/archive/clean.sls @@ -6,37 +6,38 @@ {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %} - {%- if p.pkg.use_upstream_archive %} + {%- if p.use_upstream_archive %} include: - {{ sls_alternatives_clean }} - {%- for k in p.archive.wanted %} - {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} + {%- for name in p.wanted %} -prometheus-archive-clean-{{ k }}-file-absent: +prometheus-archive-clean-{{ name }}-file-absent: file.absent: - names: - - {{ dir }} - - {{ p.archive.systemd.dir }}/{{ k }}.service - #- require: - #- sls: {{ sls_alternatives_clean }} - -prometheus-archive-clean-{{ k }}-user-absent: - user.absent: - - name: {{ k }} - group.absent: - - name: {{ k }} + - {{ p.dir.basedir }}/{{ name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) }} - require: - - user: prometheus-archive-clean-{{ k }}-user-absent + - sls: {{ sls_alternatives_clean }} + +prometheus-archive-clean-{{ name }}-user-absent: + user.absent: + - name: {{ name }} + group.absent: + - name: {{ name }} + - require: + - user: prometheus-archive-clean-{{ name }}-user-absent + - sls: {{ sls_alternatives_clean }} {%- endfor %} prometheus-archive-clean-file-directory: file.absent: - names: - - {{ p.archive.dir.opt }} - - {{ p.archive.dir.etc }} - - {{ p.archive.dir.var }} + - {{ p.dir.basedir }} + - {{ p.dir.etc }} + - {{ p.dir.var }} + - require: + - sls: {{ sls_alternatives_clean }} {%- endif %} diff --git a/prometheus/archive/defaults.yaml b/prometheus/archive/defaults.yaml deleted file mode 100644 index ce02d59..0000000 --- a/prometheus/archive/defaults.yaml +++ /dev/null @@ -1,89 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=yaml ---- -prometheus: - archive: - wanted: - - prometheus - - alertmanager - - node_exporter - systemd: - dir: /usr/lib/systemd/system - after: docker.service - wants: network-online.target docker.target - uri: https://github.com/prometheus - suffix: tar.gz - kwargs: - trim_output: True - enforce_toplevel: True - archive_format: tar - retry: - attempts: 3 - until: True - interval: 60 - splay: 10 - dir: - opt: /opt/prometheus - etc: /etc/prometheus - var: /var/lib/prometheus - binaries: - prometheus: - - prometheus - - promtool - alertmanager: - - amtool - - alertmanager - blackbox_exporter: - - blackbox_exporter - consul_exporter: - - consul_exporter - graphite_exporter: - - graphite_exporter - haproxy_exporter: - - haproxy_exporter - memcached_exporter: - - memcached_exporter - mysqld_exporter: - - mysqld_exporter - node_exporter: - - node_exporter - pushgateway: - - pushgateway - statsd_exporter: - - statsd_exporter - versions: - prometheus: '2.10.0' - alertmanager: '0.17.0' - blackbox_exporter: '0.14.0' - consul_exporter: '0.4.0' - graphite_exporter: '0.6.2' - haproxy_exporter: '0.10.0' - memcached_exporter: '0.5.0' - mysqld_exporter: '0.11.0' - node_exporter: '0.18.1' - pushgateway: '0.8.0' - statsd_exporter: '0.11.2' - hashes: - prometheus: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 - alertmanager: 7c8d2cfeb021c80881ae9904d959131091b8785b6fda9800f84ddef148fe0a4f - blackbox_exporter: a2918a059023045cafb911272c88a9eb83cdac9a8a5e8e74844b5d6d27f19117 - consul_exporter: ff77c03de67cf381f67480b5be6699901785a34145c518c3484ae3e5b8440d08 - graphite_exporter: 9b962bd06406ece4a865ad6947a6e652e48a92a0d77e496a0351c04e9c2c5e9e - haproxy_exporter: 08150728e281f813a8fcfff4b336f16dbfe4268a1c7510212c8cff2579b10468 - memcached_exporter: bb07f496ceb63dad9793ad4295205547a4bd20b90628476d64fa96c9a25a020f - mysqld_exporter: b53ad48ff14aa891eb6a959730ffc626db98160d140d9a66377394714c563acf - node_exporter: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424 - pushgateway: 6949866ba9ad0cb88d3faffd4281f17df79281398b4dbd0ec3aab300071681ca - statsd_exporter: 4632ad0c5552e271e84c376da3ffe3af8c265ec5c3035334b70e35756aca1906 - configs: - prometheus: {} - alertmanager: {} - blackbox_exporter: {} - consul_exporter: {} - graphite_exporter: {} - haproxy_exporter: {} - memcached_exporter: {} - mysqld_exporter: {} - node_exporter: {} - pushgateway: {} - statsd_exporter: {} diff --git a/prometheus/archive/init.sls b/prometheus/archive/init.sls index 9e050fa..7ad92ee 100644 --- a/prometheus/archive/init.sls +++ b/prometheus/archive/init.sls @@ -5,7 +5,7 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} - {%- if prometheus.pkg.use_upstream_archive %} + {%- if prometheus.use_upstream_archive %} include: - .install diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index b9120e3..d169323 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -7,45 +7,64 @@ {%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} - {%- for k in p.archive.wanted %} - {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} +prometheus-archive-install-file-directory: + file.directory: + - names: + - {{ p.dir.basedir }} + - {{ p.dir.etc }} + - {{ p.dir.var }} + - user: prometheus + - group: prometheus + - mode: 755 + - makedirs: True -prometheus-archive-install-{{ k }}-user-present: + {%- for name in p.wanted %} + {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} + +prometheus-archive-install-{{ name }}-user-present: group.present: - - name: {{ k }} + - name: {{ name }} - require_in: - - user: prometheus-archive-install-{{ k }}-user-present + - user: prometheus-archive-install-{{ name }}-user-present user.present: - - name: {{ k }} + - name: {{ name }} - shell: /bin/false - createhome: false - groups: - - {{ k }} + - {{ name }} - require_in: - - archive: prometheus-archive-install-{{ k }}-archive-extracted + - archive: prometheus-archive-install-{{ name }}-archive-extracted -prometheus-archive-install-{{ k }}-archive-extracted: +prometheus-archive-install-{{ name }}-archive-extracted: archive.extracted: - - name: {{ p.archive.dir.opt }} - - source: {{ p.archive.uri + '/' + k + '/releases/download/v' + p.archive.versions[k] - + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) - + '.' + p.archive.suffix }} - - source_hash: {{ p.archive.hashes[k] }} - - user: {{ k }} - - group: {{ k }} + - name: {{ p.dir.basedir }} + - source: {{ p.archive.uri }}/{{ name }}/releases/download/v{{ p.pkg[name]['archive_version'] + + '/' + bundle + '.' + p.archive.suffix }} + - source_hash: {{ p.pkg[name]['archive_hash'] }} + - user: {{ name }} + - group: {{ name }} {{- format_kwargs(p.archive.kwargs) }} - recurse: - user - group - - require_in: - - file: prometheus-archive-install-{{ k }}-managed-systemd_file - - file: prometheus-archive-install-file-directory -prometheus-archive-install-{{ k }}-managed-systemd_file: + {%- if name in p.service %} + +prometheus-archive-install-{{ name }}-file-directory: + file.directory: + - name: {{ p.dir.var }}/{{ name }} + - user: {{ name }} + - group: {{ name }} + - mode: 755 + - makedirs: True + - require: + - archive: prometheus-archive-install-{{ name }}-archive-extracted + +prometheus-archive-install-{{ name }}-managed-service: file.managed: - - name: {{ p.archive.systemd.dir }}/{{ k }}.service + - name: {{ p.dir.service }}/{{ name }}.service - source: {{ files_switch(['systemd.ini.jinja'], - lookup='prometheus-archive-install-{{ k }}-managed-systemd_file' + lookup='prometheus-archive-install-{{ name }}-managed-service' ) }} - mode: 644 @@ -54,25 +73,15 @@ prometheus-archive-install-{{ k }}-managed-systemd_file: - makedirs: True - template: jinja - context: - desc: prometheus - {{ k }} serice - name: {{ k }} - user: {{ k }} - group: {{ k }} - start: {{ dir }}/{{ k }} --config.file {{ p.archive.dir.etc }}/{{ k }}/{{ k }}.yml - stop: killall {{ dir }}/{{ k }} - after: {{ p.archive.systemd.after }} - wants: {{ p.archive.systemd.wants }} + desc: prometheus - {{ name }} service + name: {{ name }} + user: {{ name }} + group: {{ name }} + workdir: {{ p.dir.var }}/{{ name }} + start: {{ p.dir.basedir }}/{{ bundle }}/{{ name }} --config.file {{ p.dir.etc }}/{{ name }}.yml + stop: '' #not needed + - require: + - file: prometheus-archive-install-{{ name }}-file-directory - {%- endfor %} - -prometheus-archive-install-file-directory: - file.directory: - - names: - - {{ p.archive.dir.opt }} - - {{ p.archive.dir.etc }} - - {{ p.archive.dir.var }} - - user: prometheus - - group: prometheus - - mode: 755 - - makedirs: True - ##do not recurse!!! + {%- endif %} + {%- endfor %} diff --git a/prometheus/config/args.sls b/prometheus/config/args.sls deleted file mode 100644 index 35a4c4b..0000000 --- a/prometheus/config/args.sls +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- from tplroot ~ "/map.jinja" import concat_args %} - -{%- if 'args' in prometheus.service %} -{%- set args = prometheus.service.get('args', {}) -%} - -{%- if 'storage.tsdb.path' in args.keys() %} -prometheus-data-dir: - file.directory: - - name: {{ args['storage.tsdb.path'] }} - - owner: {{ prometheus.service.user }} - - group: {{ prometheus.service.group }} - - makedirs: True - - watch_in: - - service: prometheus-service-running-service-running -{%- endif %} - -{# FreeBSD #} -{%- if salt['grains.get']('os_family') == 'FreeBSD' %} -{%- if 'storage.tsdb.path' in args.keys() %} -{%- set value = args.pop('storage.tsdb.path') %} -prometheus-config-args-storage-tsdb-path: - sysrc.managed: - - name: prometheus_data_dir - - value: {{ value }} - - watch_in: - - service: prometheus-service-running-service-running -{%- endif %} - -prometheus-config-args-all: - sysrc.managed: - - name: prometheus_args - # service prometheus restart tended to hang on FreeBSD - # https://github.com/saltstack/salt/issues/44848#issuecomment-487016414 - - value: "{{ concat_args(args) }} >/dev/null 2>&1" - - watch_in: - - service: prometheus-service-running-service-running - -{# Debian #} -{%- elif salt['grains.get']('os_family') == 'Debian'%} -prometheus-config-args-file-managed: - file.managed: - - name: {{ prometheus.args_file }} - - contents: | - ARGS="{{ concat_args(args) }}" - - watch_in: - - service: prometheus-service-running-service-running -{%- endif %} -{%- endif %} diff --git a/prometheus/config/args/clean.sls b/prometheus/config/args/clean.sls new file mode 100644 index 0000000..e72d83c --- /dev/null +++ b/prometheus/config/args/clean.sls @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- set sls_service_clean = tplroot ~ '.service.clean' %} + +include: + - {{ sls_service_clean }} + + {%- for name in prometheus.wanted %} + {%- if name in prometheus.service %} + {%- set args = {} %} + {%- if 'args' in prometheus.service[name] %} + {%- set args = prometheus.service[name]['args'] or {} %} + {%- endif %} + {%- if args and 'storage.tsdb.path' in args.keys() %} + +prometheus-config-args-{{ name }}-data-dir: + file.absent: + - name: {{ args['storage.tsdb.path'] }} + - require: + - sls: {{ sls_service_clean }} + + {%- if grains.os_family == 'FreeBSD' %} + +prometheus-config-args-{{ name }}-{{ key }}: + sysrc.absent: + - name: {{ name }}_data_dir + - require: + - service: prometheus-service-clean-{{ name }}-service-dead + + {%- endif %} + {%- endif %} + {%- if args and grains.os_family == 'FreeBSD' %} + +prometheus-config-args-{{ name }}-all: + sysrc.absent: + - names: + - {{ name }}_args + - {{ name }}_listen_address + - {{ name }}_textfile_dir + - require: + - service: prometheus-service-clean-{{ name }}-service-dead + + {%- elif grains.os_family != 'FreeBSD' %} + +prometheus-config-args-{{ name }}-file-absent: + file.absent: + - name: {{ prometheus.dir.args }}/{{ name }}.sh + - require: + - service: prometheus-service-clean-{{ name }}-service-dead + + {%- endif %} + {%- endif %} + {%- endfor %} diff --git a/prometheus/config/args/init.sls b/prometheus/config/args/init.sls new file mode 100644 index 0000000..d3e5518 --- /dev/null +++ b/prometheus/config/args/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/prometheus/config/args/install.sls b/prometheus/config/args/install.sls new file mode 100644 index 0000000..787aa16 --- /dev/null +++ b/prometheus/config/args/install.sls @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/map.jinja" import concat_args %} +{%- set sls_config_install = tplroot ~ '.config' %} +{%- set sls_service_install = tplroot ~ '.service' %} + +include: + - {{ sls_config_install }} + - {{ sls_service_install }} + + {%- for name in prometheus.wanted %} + {%- if name in prometheus.config or name in prometheus.service %} + {%- set args = {} %} + {%- if 'args' in prometheus.service[name] %} + {%- set args = prometheus.service[name]['args'] or {} %} + {%- endif %} + {%- if args and 'storage.tsdb.path' in args.keys() %} + +prometheus-config-args-{{ name }}-data-dir: + file.directory: + - name: {{ args['storage.tsdb.path'] }} + - owner: {{ name }} + - group: {{ name }} + - makedirs: True + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- endif %} + {%- if args and grains.os_family == 'FreeBSD' %} + {%- if 'web.listen-address' in args.keys() %} + +prometheus-config-args-args-web-listen-address: + sysrc.managed: + - name: {{ name }}_listen_address + - value: {{ args.pop('web.listen-address') }} + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- endif %} + {%- if 'collector.textfile.directory' in args.keys() %} + +prometheus-config-args-{{ name }}--collector-textfile-directory: + sysrc.managed: + - name: {{ name }}_textfile_dir + - value: {{ args.pop('collector.textfile.directory') }} + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- endif %} + {%- if 'storage.tsdb.path' in args.keys() %} + +prometheus-config-args-{{ name }}-{{ key }}: + sysrc.managed: + - name: {{ name }}_data_dir + - value: {{ args.pop('storage.tsdb.path') }} + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- endif %} + +prometheus-config-args-{{ name }}-all: + sysrc.managed: + - name: {{ name }}_args + # service prometheus restart tended to hang on FreeBSD + # https://github.com/saltstack/salt/issues/44848#issuecomment-487016414 + - value: "{{ concat_args(args) }} >/dev/null 2>&1" + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- elif grains.os_family != 'FreeBSD' %} + +prometheus-config-args-{{ name }}-file-managed: + file.managed: + - name: {{ prometheus.dir.args }}/{{ name }}.sh + - contents: | + ARGS="{{ concat_args(args) }}" + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- endif %} + {%- endif %} + {%- endfor %} diff --git a/prometheus/config/clean.sls b/prometheus/config/clean.sls index 2be423a..7d54d55 100644 --- a/prometheus/config/clean.sls +++ b/prometheus/config/clean.sls @@ -1,18 +1,6 @@ # -*- coding: utf-8 -*- # vim: ft=sls -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- set sls_archive_clean = tplroot ~ '.archive.clean' %} - include: - - {{ sls_archive_clean }} - -prometheus-config-clean-file-absent: - file.absent: - - names: - - {{ prometheus.config_file }} - - {{ prometheus.environ_file }} - - require: - - sls: {{ sls_archive_clean }} + - .file.clean + - .args.clean diff --git a/prometheus/config/environ.sls b/prometheus/config/environ.sls deleted file mode 100644 index 25f976d..0000000 --- a/prometheus/config/environ.sls +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- set sls_archive_install = tplroot ~ '.archive.install' %} -{%- set sls_package_install = tplroot ~ '.package.install' %} -{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} - -include: - - {{ sls_archive_install if prometheus.pkg.use_upstream_archive else sls_package_install }} - -prometheus-config-file-file-managed-environ_file: - file.managed: - - name: {{ prometheus.environ_file }} - - source: {{ files_switch(['prometheus.sh.jinja'], - lookup='prometheus-config-file-file-managed-environ_file' - ) - }} - - mode: 644 - - user: root - - group: {{ prometheus.rootgroup }} - - makedirs: True - - template: jinja - - context: - prometheus: {{ prometheus|json }} - - require: - - sls: {{ sls_archive_install if prometheus.pkg.use_upstream_archive else sls_package_install }} diff --git a/prometheus/config/file.sls b/prometheus/config/file.sls deleted file mode 100644 index dd9a302..0000000 --- a/prometheus/config/file.sls +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} - -{%- if 'config' in prometheus and prometheus.config %} - {%- if prometheus.pkg.use_upstream_archive %} - {%- set sls_package_install = tplroot ~ '.archive.install' %} - {%- else %} - {%- set sls_package_install = tplroot ~ '.package.install' %} - {%- endif %} - -include: - - {{ sls_package_install }} - -prometheus-config-file-file-managed-config_file: - file.managed: - - name: {{ prometheus.config_file }} - - source: {{ files_switch(['prometheus.yml.jinja'], - lookup='prometheus-config-file-file-managed-config_file' - ) - }} - - mode: 644 - - user: root - - group: {{ prometheus.rootgroup }} - - makedirs: True - - template: jinja - - context: - config: {{ prometheus.config|json }} - - require: - - sls: {{ sls_package_install }} - -{%- endif %} diff --git a/prometheus/config/file/clean.sls b/prometheus/config/file/clean.sls new file mode 100644 index 0000000..a86ce29 --- /dev/null +++ b/prometheus/config/file/clean.sls @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{%- set sls_service_clean = tplroot ~ '.service.clean' %} + +include: + - {{ sls_service_clean }} + + {%- for name in prometheus.wanted %} + +prometheus-config-file-{{ name }}-file-absent: + file.absent: + - name: {{ prometheus.dir.etc }}/{{ name }}.yml + - require: + - sls: {{ sls_service_clean }} + + {%- endfor %} diff --git a/prometheus/config/file/init.sls b/prometheus/config/file/init.sls new file mode 100644 index 0000000..d3e5518 --- /dev/null +++ b/prometheus/config/file/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/prometheus/config/file/install.sls b/prometheus/config/file/install.sls new file mode 100644 index 0000000..0359979 --- /dev/null +++ b/prometheus/config/file/install.sls @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{%- set sls_archive_install = tplroot ~ '.archive.install' %} +{%- set sls_package_install = tplroot ~ '.package.install' %} + +include: + - {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + + {%- for name in prometheus.wanted %} + {%- if name in prometheus.config or name in prometheus.service %} + +prometheus-config-file-{{ name }}-file-managed: + file.managed: + - name: {{ prometheus.dir.etc }}/{{ name }}.yml + - source: {{ files_switch(['config.yml.jinja'], + lookup='prometheus-config-file-{{ name }}-file-managed' + ) + }} + - mode: 644 + - user: {{ name }} + - group: {{ name }} + - makedirs: True + - template: jinja + - context: + config: {{ '' if name not in prometheus.config else prometheus.config[name]|json }} + - require: + - sls: {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + + {%- endif %} + {%- endfor %} diff --git a/prometheus/config/init.sls b/prometheus/config/init.sls index 8875266..8919ea2 100644 --- a/prometheus/config/init.sls +++ b/prometheus/config/init.sls @@ -1,11 +1,6 @@ # -*- 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: - .args - .file - - .environ diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index ecedd90..2c45261 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -2,25 +2,104 @@ # vim: ft=yaml --- prometheus: - pkg: - name: prometheus - use_upstream_archive: False - rootgroup: root kernel: {{ grains.kernel | lower }} - config_file: /etc/prometheus/prometheus.yml - config: {} - environ_file: /etc/default/prometheus.sh - environ: [] + arch: {{ grains.osarch }} + + wanted: + - prometheus + - alertmanager + - node_exporter + + dir: + basedir: /opt/prometheus + etc: /etc/prometheus + var: /var/lib/prometheus + args: /etc/default + default: /etc/default + service: /usr/lib/systemd/system + service: - name: prometheus - user: prometheus - group: prometheus + prometheus: + args: + web.listen-address: 0.0.0.0:9090 + alertmanager: {} + + config: + prometheus: {} + + pkg: + prometheus: + archive_version: '2.10.0' + archive_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 + binaries: + - prometheus + - promtool + alertmanager: + archive_version: '0.17.0' + archive_hash: 7c8d2cfeb021c80881ae9904d959131091b8785b6fda9800f84ddef148fe0a4f + binaries: + - amtool + - alertmanager + blackbox_exporter: + archive_version: '0.14.0' + archive_hash: a2918a059023045cafb911272c88a9eb83cdac9a8a5e8e74844b5d6d27f19117 + binaries: + - blackbox_exporter + consul_exporter: + archive_version: '0.4.0' + archive_hash: ff77c03de67cf381f67480b5be6699901785a34145c518c3484ae3e5b8440d08 + binaries: + - consul_exporter + graphite_exporter: + archive_version: '0.6.2' + archive_hash: 9b962bd06406ece4a865ad6947a6e652e48a92a0d77e496a0351c04e9c2c5e9e + binaries: + - graphite_exporter + haproxy_exporter: + archive_version: '0.10.0' + archive_hash: 08150728e281f813a8fcfff4b336f16dbfe4268a1c7510212c8cff2579b10468 + binaries: + - haproxy_exporter + memcached_exporter: + archive_version: '0.5.0' + archive_hash: bb07f496ceb63dad9793ad4295205547a4bd20b90628476d64fa96c9a25a020f + binaries: + - memcached_exporter + mysqld_exporter: + archive_version: '0.11.0' + archive_hash: b53ad48ff14aa891eb6a959730ffc626db98160d140d9a66377394714c563acf + binaries: + - mysqld_exporter + node_exporter: + archive_version: '0.18.1' + archive_hash: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424 + binaries: + - node_exporter + pushgateway: + archive_version: '0.8.0' + archive_hash: 6949866ba9ad0cb88d3faffd4281f17df79281398b4dbd0ec3aab300071681ca + binaries: + - pushgateway + statsd_exporter: + archive_version: '0.11.2' + archive_hash: 4632ad0c5552e271e84c376da3ffe3af8c265ec5c3035334b70e35756aca1906 + binaries: + - statsd_exporter + + use_upstream_archive: False + archive: + uri: https://github.com/prometheus + suffix: tar.gz + kwargs: + trim_output: True + enforce_toplevel: True + archive_format: tar + retry: + attempts: 3 + until: True + interval: 60 + splay: 10 + linux: - #'Alternatives system' priority: zero disables (default) - altpriority: 0 - exporters: - node: - pkg: - name: prometheus-node-exporter - service: prometheus-node-exporter + altpriority: 0 ##'Alternatives system' priority: zero disables (default) diff --git a/prometheus/exporters/init.sls b/prometheus/exporters/init.sls deleted file mode 100644 index 1e5daf5..0000000 --- a/prometheus/exporters/init.sls +++ /dev/null @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- set sls_config_file = tplroot ~ '.config.file' %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} - -{%- if prometheus.exporters.keys()|length > 0 %} -include: -{%- for name in prometheus.exporters.keys()|list %} - - .{{ name }} -{%- endfor %} -{%- endif %} diff --git a/prometheus/exporters/node/clean.sls b/prometheus/exporters/node/clean.sls deleted file mode 100644 index 14401e2..0000000 --- a/prometheus/exporters/node/clean.sls +++ /dev/null @@ -1,28 +0,0 @@ -# -*- 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-exporters-node-service-dead: - service.dead: - - name: {{ prometheus.exporters.node.service }} - - enable: False - -prometheus-exporters-node-pkg-removed: - pkg.removed: - - name: {{ prometheus.exporters.node.pkg.name }} - - require: - - service: prometheus-exporters-node-service-dead - -{# FreeBSD #} -{%- if salt['grains.get']('os_family') == 'FreeBSD' %} -{%- for parameter in ['args', 'listen_address', 'textfile_dir'] %} -prometheus-exporters-node-args-{{ parameter }}: - sysrc.absent: - - name: node_exporter_{{ parameter }} - - require: - - service: prometheus-exporters-node-service-dead -{%- endfor %} -{%- endif %} diff --git a/prometheus/exporters/node/init.sls b/prometheus/exporters/node/init.sls deleted file mode 100644 index f8f7534..0000000 --- a/prometheus/exporters/node/init.sls +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- from tplroot ~ "/map.jinja" import concat_args %} - -prometheus-exporters-node-pkg-installed: - pkg.installed: - - name: {{ prometheus.exporters.node.pkg.name }} - -{%- if 'args' in prometheus.exporters.node %} -{%- set args = prometheus.exporters.node.get('args', {}) -%} - -{# FreeBSD #} -{%- if salt['grains.get']('os_family') == 'FreeBSD' %} -{%- if 'web.listen-address' in args.keys() %} -{%- set value = args.pop('web.listen-address') %} -prometheus-exporters-node-args-web-listen-address: - sysrc.managed: - - name: node_exporter_listen_address - - value: {{ value }} - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} - -{%- if 'collector.textfile.directory' in args.keys() %} -{%- set value = args.pop('collector.textfile.directory') %} -prometheus-exporters-node-args-collector-textfile-directory: - sysrc.managed: - - name: node_exporter_textfile_dir - - value: {{ value }} - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} - -prometheus-exporters-node-args: - sysrc.managed: - - name: node_exporter_args - # service node_exporter restart tended to hang on FreeBSD - # https://github.com/saltstack/salt/issues/44848#issuecomment-487016414 - - value: "{{ concat_args(args) }} >/dev/null 2>&1" - - watch_in: - - service: prometheus-exporters-node-service-running - -{# Debian #} -{%- elif salt['grains.get']('os_family') == 'Debian'%} -prometheus-exporters-node-args: - file.managed: - - name: {{ prometheus.exporters.node.config_file }} - - contents: | - ARGS="{{ concat_args(args) }}" - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} -{%- endif %} - -prometheus-exporters-node-service-running: - service.running: - - name: {{ prometheus.exporters.node.service }} - - enable: True - - watch: - - pkg: prometheus-exporters-node-pkg-installed diff --git a/prometheus/files/default/prometheus.yml.jinja b/prometheus/files/default/config.yml.jinja similarity index 100% rename from prometheus/files/default/prometheus.yml.jinja rename to prometheus/files/default/config.yml.jinja diff --git a/prometheus/files/default/prometheus.sh.jinja b/prometheus/files/default/default.sh.jinja similarity index 78% rename from prometheus/files/default/prometheus.sh.jinja rename to prometheus/files/default/default.sh.jinja index afc0f91..0a1fe22 100644 --- a/prometheus/files/default/prometheus.sh.jinja +++ b/prometheus/files/default/default.sh.jinja @@ -3,8 +3,8 @@ # Your changes may be overwritten. ######################################################################## -{%- if prometheus.environ %} - {%- for item in prometheus.environ %} +{%- if defaults %} + {%- for item in defaults %} {{ item }} {%- endfor %} {%- endif %} diff --git a/prometheus/files/default/systemd.ini.jinja b/prometheus/files/default/systemd.ini.jinja index 02d8105..959ad17 100644 --- a/prometheus/files/default/systemd.ini.jinja +++ b/prometheus/files/default/systemd.ini.jinja @@ -3,13 +3,14 @@ ######################################################### [Unit] Description={{ desc }} -Wants={{ wants }} -After={{ after }} +Wants=network-online.target +After= Documentation=https://github.com/saltstack-formulas/prometheus-formula [Service] User={{ user }} Group={{ group }} +WorkingDirectory={{ workdir }} ExecStart={{ start }} ExecStop={{ stop }} PIDFile=/var/run/{{ name }}.pid diff --git a/prometheus/init.sls b/prometheus/init.sls index 11743b6..c281ea9 100644 --- a/prometheus/init.sls +++ b/prometheus/init.sls @@ -6,6 +6,6 @@ {%- from tplroot ~ "/map.jinja" import prometheus with context %} include: - - {{ '.archive' if prometheus.pkg.use_upstream_archive else '.package' }} + - {{ '.archive' if prometheus.use_upstream_archive else '.package' }} - .config - .service diff --git a/prometheus/map.jinja b/prometheus/map.jinja index fbbf314..183d72c 100644 --- a/prometheus/map.jinja +++ b/prometheus/map.jinja @@ -5,23 +5,17 @@ {%- set tplroot = tpldir.split('/')[0] %} {#- Start imports as #} {%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %} -{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %} -{%- import_yaml tplroot ~ "/osmap.yaml" as osmap %} {%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %} -{%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %} +{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %} {%- import_yaml tplroot ~ "/archive/defaults.yaml" as archive_defaults %} {%- set defaults = salt['grains.filter_by'](default_settings, merge=salt['grains.filter_by'](archive_defaults, + merge=salt['grains.filter_by'](osarchmap, grain='osarch', merge=salt['grains.filter_by'](osfamilymap, grain='os_family', - merge=salt['grains.filter_by'](osmap, grain='os', - merge=salt['grains.filter_by'](osfingermap, grain='osfinger', - merge=salt['grains.filter_by'](osarchmap, grain='osarch', - merge=salt['pillar.get']('prometheus:lookup', default={}), - base='prometheus'), - base='prometheus'), - base='prometheus'), + merge=salt['pillar.get']('prometheus:lookup', default={}), base='prometheus'), + base='prometheus'), base='prometheus'), base='prometheus') %} diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index c2c8188..0fc5fc2 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -14,15 +14,11 @@ {% set macos_group = salt['cmd.run']("stat -f '%Sg' /dev/console") %} {%- endif %} -Debian: - args_file: /etc/default/prometheus - exporters: - node: - config_file: /etc/default/prometheus-node-exporter +Debian: {} RedHat: - pkg: - use_upstream_archive: True + ## remove when https://github.com/saltstack-formulas/prometheus-formula/pull/4 is merged + use_upstream_archive: True Suse: {} @@ -34,75 +30,107 @@ Alpine: {} FreeBSD: rootgroup: wheel - config_file: /usr/local/etc/prometheus.yml - exporters: - node: - pkg: - name: node_exporter - service: node_exporter - archive: - hashes: - prometheus: 94a63f14baeadab2f17b5ae0bbeda6688e6d06f964ef4e32c2954a0ecf3996a1 - alertmanager: ec171b13976baceace193461f8a1e61021ab9657df5ba45157cd0095aee7d569 - blackbox_exporter: 2b92752decf2cf1883ce4f72301e4f911dab79efbd87db4df23dc9771e53e4af - consul_exporter: 62e16c2f1acb9bf9411126478caccb5962da203cfb58d8c97f54b9c0add5171c - graphite_exporter: ff424b923733d8247314353ba4d13a1c4b06450c35f005bfd6c3b6ff60b047fd - haproxy_exporter: f32d158f9e3314828dc155a30a1f4c858876e1ea8ff543a4000afcbc7e923505 - memcached_exporter: 8fd53b9aede6b78e0530b159ccd0a437cf2f100da1ddc586681f389d804f5f19 - mysqld_exporter: 9bcbbd8b3568818fd4c95d255c6f93c357ea25aed3364d7428f4ff9c89cd489a - node_exporter: {} - pushgateway: ebcd21dc25e439eed64559e89cd7da9a94073d5ff321a8a3a4214ac2ebe04e34 - statsd_exporter: f345dff6311501f09bb5b6ba1128e925d504c6325ee97ad91a975f2be0d44da9 + dir: + config: /usr/local/etc + pkg: + prometheus: + archive_hash: 94a63f14baeadab2f17b5ae0bbeda6688e6d06f964ef4e32c2954a0ecf3996a1 + alertmanager: + archive_hash: ec171b13976baceace193461f8a1e61021ab9657df5ba45157cd0095aee7d569 + blackbox_exporter: + archive_hash: 2b92752decf2cf1883ce4f72301e4f911dab79efbd87db4df23dc9771e53e4af + consul_exporter: + archive_hash: 62e16c2f1acb9bf9411126478caccb5962da203cfb58d8c97f54b9c0add5171c + graphite_exporter: + archive_hash: ff424b923733d8247314353ba4d13a1c4b06450c35f005bfd6c3b6ff60b047fd + haproxy_exporter: + archive_hash: f32d158f9e3314828dc155a30a1f4c858876e1ea8ff543a4000afcbc7e923505 + memcached_exporter: + archive_hash: 8fd53b9aede6b78e0530b159ccd0a437cf2f100da1ddc586681f389d804f5f19 + mysqld_exporter: + archive_hash: 9bcbbd8b3568818fd4c95d255c6f93c357ea25aed3364d7428f4ff9c89cd489a + node_exporter: {} + pushgateway: + archive_hash: ebcd21dc25e439eed64559e89cd7da9a94073d5ff321a8a3a4214ac2ebe04e34 + statsd_exporter: + archive_hash: f345dff6311501f09bb5b6ba1128e925d504c6325ee97ad91a975f2be0d44da9 OpenBSD: rootgroup: wheel kernel: openbsd - archive: - hashes: - prometheus: c3c69919b359f00a84ef12f7ed6a956111790d64a71bd94990572baaf63377ce - alertmanager: 88ce1b3f11bb28f24b98235994277b2c31aa03b2b2609e0058c04efa0cc5596f - blackbox_exporter: 0dee97d1204bac925bde919958ae890730d87386a816ed0b248c8038ee43794d - consul_exporter: b53ee2bd0e670907eac894387e286b0dd11eb3149fcd4e19ed586006d3de741a - graphite_exporter: 98cbd7176f1c61023892de64ad26edc3cd7895037e3cc282c4edec53dded7156 - haproxy_exporter: bc2b222f6a08232ef643cd6dcda3264f3bd7388a5bee25365cef137c7dea17e8 - memcached_exporter: 21db1bffc561d47b4490ccb2cde721244d00e95f504cdcfee618bc4bb877e731 - mysqld_exporter: b37d6fe68e2c884540ea41c5efcfb16d0bc5da517fe3ba713144504df1ba635d - node_exporter: {} - pushgateway: 0bce168e4b19234df9e954393a2102c91e4d62336b2721ed882f2003a4445d51 - statsd_exporter: c89acb365b75af03ce612873d8b20226e3882c0177752ea0ce17a9f5e41eb5b4 + pkg: + prometheus: + archive_hash: c3c69919b359f00a84ef12f7ed6a956111790d64a71bd94990572baaf63377ce + alertmanager: + archive_hash: 88ce1b3f11bb28f24b98235994277b2c31aa03b2b2609e0058c04efa0cc5596f + blackbox_exporter: + archive_hash: 0dee97d1204bac925bde919958ae890730d87386a816ed0b248c8038ee43794d + consul_exporter: + archive_hash: b53ee2bd0e670907eac894387e286b0dd11eb3149fcd4e19ed586006d3de741a + graphite_exporter: + archive_hash: 98cbd7176f1c61023892de64ad26edc3cd7895037e3cc282c4edec53dded7156 + haproxy_exporter: + archive_hash: bc2b222f6a08232ef643cd6dcda3264f3bd7388a5bee25365cef137c7dea17e8 + memcached_exporter: + archive_hash: 21db1bffc561d47b4490ccb2cde721244d00e95f504cdcfee618bc4bb877e731 + mysqld_exporter: + archive_hash: b37d6fe68e2c884540ea41c5efcfb16d0bc5da517fe3ba713144504df1ba635d + pushgateway: + archive_hash: 0bce168e4b19234df9e954393a2102c91e4d62336b2721ed882f2003a4445d51 + statsd_exporter: + archive_hash: c89acb365b75af03ce612873d8b20226e3882c0177752ea0ce17a9f5e41eb5b4 Solaris: {} Windows: kernel: windows - archive: - name: C:\\Program Files - hashes: - prometheus: eb138082a4d5e4d5b1e3ca838fa508f053474d46bca76e87ab0834f0d8b110db - alertmanager: 512dbed02a3cc7e3f06d737f56179e458c462762b3427063b89c62a54d9645c6 - blackbox_exporter: 21ea148870631310002cbd48be54ca45e8d300da5a902b0aec052f1a64316d93 - consul_exporter: 54579bc5dfa6a238e310a1874b0a362027661dfa1754535e74610dc8ef6163b1 - graphite_exporter: f83fad71bad99ccac145d65f82bf9d17fa37168a5dcce6415c6350e79a84e638 - haproxy_exporter: 044118feb98b74eb921e27bd4b511732b553896c672c19bdd3418445dc030794 - memcached_exporter: 9e83c00c9d249c942f65b6a48112e6bd6e28a3d15b8a1d35e935621657b3d837 - mysqld_exporter: 38605ae648f8def07a0f412d81a30a6c48c0d20a6981468d25b91c8aa529e599 - node_exporter: {} - pushgateway: 506b555e7a13cabf3d85ec0dbe1bc6bc3a2444c0cc468baa8d31e7fc2fe18dd1 - statsd_exporter: 9362b7482e74792f111c4bb1a372b18a88f6354c78f24713bacfbcb050883556 + dir: + opt: C:\\Program Files + pkg: + prometheus: + archive_hash: eb138082a4d5e4d5b1e3ca838fa508f053474d46bca76e87ab0834f0d8b110db + alertmanager: + archive_hash: 512dbed02a3cc7e3f06d737f56179e458c462762b3427063b89c62a54d9645c6 + blackbox_exporter: + archive_hash: 21ea148870631310002cbd48be54ca45e8d300da5a902b0aec052f1a64316d93 + consul_exporter: + archive_hash: 54579bc5dfa6a238e310a1874b0a362027661dfa1754535e74610dc8ef6163b1 + graphite_exporter: + archive_hash: f83fad71bad99ccac145d65f82bf9d17fa37168a5dcce6415c6350e79a84e638 + haproxy_exporter: + archive_hash: 044118feb98b74eb921e27bd4b511732b553896c672c19bdd3418445dc030794 + memcached_exporter: + archive_hash: 9e83c00c9d249c942f65b6a48112e6bd6e28a3d15b8a1d35e935621657b3d837 + mysqld_exporter: + archive_hash: 38605ae648f8def07a0f412d81a30a6c48c0d20a6981468d25b91c8aa529e599 + pushgateway: + archive_hash: 506b555e7a13cabf3d85ec0dbe1bc6bc3a2444c0cc468baa8d31e7fc2fe18dd1 + statsd_exporter: + archive_hash: 9362b7482e74792f111c4bb1a372b18a88f6354c78f24713bacfbcb050883556 MacOS: rootgroup: {{ macos_group | d('') }} kernel: darwin - archive: - hashes: - prometheus: 740e36bcacc0c5d4495f5341fcfa8b7e0dc623d12e8b07ac291052ea0a681325 - alertmanager: efeebaa8e51c521ecb3440345fb65962533cae022d71dff8b127911e893ded2a - blackbox_exporter: a371d0496adb5d62368d6606928c5effd318d1387f6b9a9998f8d0333492645a - consul_exporter: 75641783938967c11c18d6d340028ff2dce7ad0ae5e300fa631b813cc6ea9647 - graphite_exporter: f9c0aa745502c0ab01fdcca29181801810202e0aed512a9aa9a37bb4be88a919 - haproxy_exporter: 8fdb8bb182586c57e5892816a02846bae0998916765d22bb81b2c444a3565862 - memcached_exporter: e10685cca5ffd8a3a7574b3dc096dc7418f34906abd399f881be06dd38be62cb - mysqld_exporter: 8e0a7d8847790d6dcdcf392e6dd227458a7bcaa1e0890cc6326fdf956421f2a7 - node_exporter: 20fadb3108de0a9cc70a1333394e5be90416b4f91025f9fc66f5736335e94398 - pushgateway: 25399a4c6600c1931f9d9bd5294700c2b53f964188b1c6003f9d12a2e176aac1 - statsd_exporter: 15132494523c2b6a89e09b2da63452c8fe587fb82fcc3fd21cc75a4aa2766644 + pkg: + prometheus: + archive_hash: 740e36bcacc0c5d4495f5341fcfa8b7e0dc623d12e8b07ac291052ea0a681325 + alertmanager: + archive_hash: efeebaa8e51c521ecb3440345fb65962533cae022d71dff8b127911e893ded2a + blackbox_exporter: + archive_hash: a371d0496adb5d62368d6606928c5effd318d1387f6b9a9998f8d0333492645a + consul_exporter: + archive_hash: 75641783938967c11c18d6d340028ff2dce7ad0ae5e300fa631b813cc6ea9647 + graphite_exporter: + archive_hash: f9c0aa745502c0ab01fdcca29181801810202e0aed512a9aa9a37bb4be88a919 + haproxy_exporter: + archive_hash: 8fdb8bb182586c57e5892816a02846bae0998916765d22bb81b2c444a3565862 + memcached_exporter: + archive_hash: e10685cca5ffd8a3a7574b3dc096dc7418f34906abd399f881be06dd38be62cb + mysqld_exporter: + archive_hash: 8e0a7d8847790d6dcdcf392e6dd227458a7bcaa1e0890cc6326fdf956421f2a7 + node_exporter: + archive_hash: 20fadb3108de0a9cc70a1333394e5be90416b4f91025f9fc66f5736335e94398 + pushgateway: + archive_hash: 25399a4c6600c1931f9d9bd5294700c2b53f964188b1c6003f9d12a2e176aac1 + statsd_exporter: + archive_hash: 15132494523c2b6a89e09b2da63452c8fe587fb82fcc3fd21cc75a4aa2766644 diff --git a/prometheus/osfingermap.yaml b/prometheus/osfingermap.yaml deleted file mode 100644 index 0fac2c6..0000000 --- a/prometheus/osfingermap.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=yaml -# -# Setup variables using grains['osfinger'] based logic. -# You just need to add the key:values for an `osfinger` that differ -# from `defaults.yaml` + `os_family.yaml` + `osmap.yaml`. -# Only add an `osfinger` which is/will be supported by the formula -# -# If you do not need to provide defaults via the `os_finger` grain, -# you will need to provide at least an empty dict in this file, e.g. -# osfingermap: {} ---- -# os: Ubuntu -Ubuntu-18.04: {} diff --git a/prometheus/osmap.yaml b/prometheus/osmap.yaml deleted file mode 100644 index 20a12fd..0000000 --- a/prometheus/osmap.yaml +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=yaml -# -# Setup variables using grains['os'] based logic. -# You just need to add the key:values for an `os` that differ -# from `defaults.yaml` + `os_family.yaml`. -# Only add an `os` which is/will be supported by the formula -# -# If you do not need to provide defaults via the `os` grain, -# you will need to provide at least an empty dict in this file, e.g. -# osmap: {} ---- -# os_family: Debian -Ubuntu: {} - -Raspbian: {} - -# os_family: Gentoo -Funtoo: {} - -# os_family: Arch -Manjaro: {} - -# os_family: Solaris -SmartOS: {} diff --git a/prometheus/package/clean.sls b/prometheus/package/clean.sls index 04c2cfd..59f0ab5 100644 --- a/prometheus/package/clean.sls +++ b/prometheus/package/clean.sls @@ -9,10 +9,16 @@ include: - {{ sls_config_clean }} -prometheus-package-clean-pkg-removed: + {%- for name in prometheus.wanted %} + {%- if name in prometheus.pkg %} + +prometheus-package-clean-{{ name }}-removed: pkg.removed: - - name: {{ prometheus.pkg.name }} - {%- if 'config' in prometheus and prometheus.config %} + - name: {{ name }} + {%- if name in prometheus.service %} - require: - - sls: {{ sls_config_clean }} - {%- endif %} + - service: prometheus-service-clean-{{ name }}-service-dead + {%- endif %} + + {%- endif %} + {%- endfor %} diff --git a/prometheus/package/install.sls b/prometheus/package/install.sls index 8280d96..cc540aa 100644 --- a/prometheus/package/install.sls +++ b/prometheus/package/install.sls @@ -5,6 +5,10 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} -prometheus-package-install-pkg-installed: + {%- for name in prometheus.wanted %} + +prometheus-package-install-{{ name }}-installed: pkg.installed: - - name: {{ prometheus.pkg.name }} + - name: {{ name }} + + {%- endfor %} diff --git a/prometheus/service/clean.sls b/prometheus/service/clean.sls index 71d9806..9a69790 100644 --- a/prometheus/service/clean.sls +++ b/prometheus/service/clean.sls @@ -5,7 +5,16 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} -prometheus-service-clean-service-dead: + {%- for name in prometheus.wanted %} + {%- if name in prometheus.service %} + +prometheus-service-clean-{{ name }}-service-dead: service.dead: - - name: {{ prometheus.service.name }} + - name: {{ name }} - enable: False + {%- if grains.kernel|lower == 'linux' %} + - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 + {%- endif %} + + {%- endif %} + {%- endfor %} diff --git a/prometheus/service/running.sls b/prometheus/service/running.sls index a64f9fa..ec5300f 100644 --- a/prometheus/service/running.sls +++ b/prometheus/service/running.sls @@ -3,29 +3,44 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} -{%- set sls_config_args = tplroot ~ '.config.args' %} -{%- set sls_config_file = tplroot ~ '.config.file' %} +{%- set sls_config_args = tplroot ~ '.config.args.install' %} +{%- set sls_config_file = tplroot ~ '.config.file.install' %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} include: - {{ sls_config_args }} - {{ sls_config_file }} -prometheus-service-running-service-unmasked: - service.unmasked: - - name: {{ prometheus.service.name }} - - onlyif: systemctl list-unit-files | grep {{ prometheus.service.name }} >/dev/null 2>&1 + {%- for name in prometheus.wanted %} + {%- if name in prometheus.service %} -prometheus-service-running-service-running: - service.running: - - name: {{ prometheus.service.name }} - - enable: True - {%- if 'config' in prometheus and prometheus.config %} - - watch: - - file: prometheus-config-file-file-managed-config_file +prometheus-service-running-{{ name }}-service-unmasked: + service.unmasked: + - name: {{ name }} - require: - - service: prometheus-service-running-service-unmasked - sls: {{ sls_config_args }} - sls: {{ sls_config_file }} - {%- endif %} - - onlyif: systemctl list-unit-files | grep {{ prometheus.service.name }} >/dev/null 2>&1 + {%- if grains.kernel|lower == 'linux' %} + - onlyif: + - systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 + {%- endif %} + +prometheus-service-running-{{ name }}-service-running: + service.running: + - name: {{ name }} + - enable: True + {%- if name in prometheus.config %} + - watch: + - file: prometheus-config-file-{{ name }}-file-managed + {%- endif %} + - require: + - service: prometheus-service-running-{{ name }}-service-unmasked + - sls: {{ sls_config_args }} + - sls: {{ sls_config_file }} + {%- if grains.kernel|lower == 'linux' %} + - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 + {%- endif %} + + {%- endif %} + {%- endfor %} + diff --git a/prometheus/systemd.sls b/prometheus/systemd.sls deleted file mode 100644 index e69de29..0000000