Merge pull request #52 from lagooj/feat/unofficial_exporters

Manage unofficial exporters
This commit is contained in:
N 2020-11-17 23:17:31 +00:00 committed by GitHub
commit 6ab735e16c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 130 additions and 9 deletions

View File

@ -13,6 +13,8 @@ prometheus:
- prometheus
- alertmanager
- node_exporter
- php-fpm_exporter
- postgres_exporter
# - memcached_exporter # not in upstream repo, only archive
exporters:
@ -171,6 +173,30 @@ prometheus:
web.listen-address: ":9091"
web.telemetry-path: "/metrics"
php-fpm_exporter:
version: v0.6.1
archive:
official: false
tar: false
# yamllint disable-line rule:line-length
source: https://github.com/bakins/php-fpm-exporter/releases/download/v0.6.1/php-fpm-exporter.linux.amd64
source_hash: 40e52d84f7decb5fdad9fadacf63cb2de26ebddce56e11b20651555e8d6c6130
service:
args:
addr: ":9253"
fastcgi: "unix:///run/php/php-fpm.sock"
postgres_exporter:
version: v0.8.0
service:
env:
- 'DATA_SOURCE_NAME=foo:bar@/'
archive:
official: false
# yamllint disable-line rule:line-length
source: https://github.com/wrouesnel/postgres_exporter/releases/download/v0.8.0/postgres_exporter_v0.8.0_linux-amd64.tar.gz
skip_verify: true
linux:
# 'Alternatives system' priority: zero disables (default)
# yamllint disable-line rule:braces

View File

@ -28,14 +28,10 @@ prometheus-archive-install-prerequisites:
{%- for name in p.wanted.component %}
prometheus-archive-install-{{ name }}:
prometheus-archive-directory-{{ name }}:
file.directory:
- name: {{ p.pkg.component[name]['path'] }}
- makedirs: True
- require:
- file: prometheus-archive-install-prerequisites
- require_in:
- archive: prometheus-archive-install-{{ name }}
{%- if grains.os != 'Windows' %}
- user: {{ p.identity.rootuser }}
- group: {{ p.identity.rootgroup }}
@ -45,6 +41,8 @@ prometheus-archive-install-{{ name }}:
- group
- mode
{%- endif %}
prometheus-archive-install-{{ name }}:
{%- if p.pkg.component.get(name).get('archive').get('tar', true) %}
archive.extracted:
{{- format_kwargs(p.pkg.component[name]['archive']) }}
- trim_output: true
@ -53,12 +51,24 @@ prometheus-archive-install-{{ name }}:
- force: {{ p.force }}
- retry: {{ p.retry_option|json }}
- require:
- file: prometheus-archive-install-{{ name }}
{%- if grains.os != 'Windows' %}
- file: prometheus-archive-directory-{{ name }}
{%- if grains.os != 'Windows' %}
- user: {{ p.identity.rootuser }}
- group: {{ p.identity.rootgroup }}
{%- endif %}
{% else %}
file.managed:
- name: {{ p.pkg.component[name]['path'] }}/{{ name }}
- source: {{ p.pkg.component[name]['archive']['source'] }}
- source_hash: {{ p.pkg.component[name]['archive']['source_hash'] }}
- mode: '0755'
- require:
- file: prometheus-archive-directory-{{ name }}
{%- if grains.os != 'Windows' %}
- user: {{ p.identity.rootuser }}
- group: {{ p.identity.rootgroup }}
{%- endif %}
{%- endif %}
{%- if (grains.kernel|lower == 'linux' and p.linux.altpriority|int <= 0) or grains.os_family|lower in ('macos', 'arch') %}
{%- if 'commands' in p.pkg.component[name] and p.pkg.component[name]['commands'] is iterable %}
{%- for cmd in p.pkg.component[name]['commands'] %}
@ -73,7 +83,11 @@ prometheus-archive-install-{{ name }}-file-symlink-{{ cmd }}:
- target: {{ p.pkg.component[name]['path'] }}/{{ cmd }}
- force: True
- require:
{%- if p.pkg.component.get(name).get('archive').get('tar', true) %}
- archive: prometheus-archive-install-{{ name }}
{% else %}
- file: prometheus-archive-install-{{ name }}
{% endif %}
{%- endfor %}
{%- endif %}
@ -125,13 +139,21 @@ prometheus-archive-install-{{ name }}-managed-service:
{%- endif %}
- require:
- file: prometheus-archive-install-{{ name }}-file-directory
{%- if p.pkg.component.get(name).get('archive').get('tar', true) %}
- archive: prometheus-archive-install-{{ name }}
{% else %}
- file: prometheus-archive-install-{{ name }}
{% endif %}
- user: prometheus-config-users-install-{{ name }}-user-present
- group: prometheus-config-users-install-{{ name }}-group-present
cmd.run:
- name: systemctl daemon-reload
- require:
{%- if p.pkg.component.get(name).get('archive').get('tar', true) %}
- archive: prometheus-archive-install-{{ name }}
{% else %}
- file: prometheus-archive-install-{{ name }}
{% endif %}
{%- endif %}{# linux #}
{%- endif %}{# service #}

View File

@ -34,7 +34,11 @@
{%- set url = '%s-%s.%s-%s.tar.gz'|format(uri, v.version|replace('v',''), p.kernel, p.arch) %}
{%- set dir = '%s-%s'|format(name, v.version) %}
{%- do p.pkg.component[name].update({'path': p.dir.archive ~ '/' + dir }) %}
{%- do p.pkg.component[name]['archive'].update({'name': p.dir.archive + '/' + dir, 'source': url}) %}
{% if p.pkg.component[name]['archive'].get('official', true) %}
{%- do p.pkg.component[name]['archive'].update({'name': p.dir.archive + '/' + dir, 'source': url}) %}
{% else %}
{%- do p.pkg.component[name]['archive'].update({'name': p.dir.archive + '/' + dir }) %}
{% endif %}
{%- endif %}
{%- endfor %}
{%- endif %}

View File

@ -8,10 +8,14 @@ control 'prometheus components' do
service_dir = '/lib/systemd/system'
alert_manager_service = 'prometheus-alertmanager'
node_exporter_service = 'prometheus-node-exporter'
php_fpm_exporter_service = 'php-fpm_exporter'
postgres_exporter_service = 'prometheus-postgres-exporter'
else
service_dir = '/usr/lib/systemd/system'
alert_manager_service = 'alertmanager'
node_exporter_service = 'node_exporter'
php_fpm_exporter_service = 'php-fpm_exporter'
postgres_exporter_service = 'postgres_exporter'
end
# describe package('cron') do
@ -35,6 +39,12 @@ control 'prometheus components' do
describe user('node_exporter') do
it { should exist }
end
describe user('php-fpm_exporter') do
it { should exist }
end
describe user('postgres_exporter') do
it { should exist }
end
describe directory('/var/lib/prometheus') do
it { should exist }
end
@ -89,6 +99,38 @@ control 'prometheus components' do
its('group') { should eq 'root' }
its('mode') { should cmp '0644' }
end
describe directory('/opt/prometheus/php-fpm_exporter-v0.6.1') do
it { should exist }
its('group') { should eq 'root' }
end
describe file('/opt/prometheus/php-fpm_exporter-v0.6.1/php-fpm_exporter') do
it { should exist }
its('group') { should eq 'root' }
end
describe directory('/var/lib/prometheus/php-fpm_exporter') do
it { should exist }
end
describe file("#{service_dir}/#{php_fpm_exporter_service}.service") do
it { should exist }
its('group') { should eq 'root' }
its('mode') { should cmp '0644' }
end
describe directory('/var/lib/prometheus/postgres_exporter') do
it { should exist }
end
describe directory('/opt/prometheus/postgres_exporter-v0.8.0') do
it { should exist }
its('group') { should eq 'root' }
end
describe file('/opt/prometheus/postgres_exporter-v0.8.0/postgres_exporter') do
it { should exist }
its('group') { should eq 'root' }
end
describe file("#{service_dir}/#{postgres_exporter_service}.service") do
it { should exist }
its('group') { should eq 'root' }
its('mode') { should cmp '0644' }
end
describe file('/usr/local/sbin/alertmanager') do
it { should exist }
its('group') { should eq 'root' }

View File

@ -15,6 +15,8 @@ prometheus:
- node_exporter
- blackbox_exporter
- consul_exporter
- php-fpm_exporter
- postgres_exporter
# - memcached_exporter # not in upstream repo, only archive
exporters:
@ -171,6 +173,31 @@ prometheus:
web.listen-address: ":9091"
web.telemetry-path: "/metrics"
# Unoffical php fpm exporter config
php-fpm_exporter:
version: v0.6.1
archive:
official: false
tar: false
# yamllint disable-line rule:line-length
source: https://github.com/bakins/php-fpm-exporter/releases/download/v0.6.1/php-fpm-exporter.linux.amd64
source_hash: 40e52d84f7decb5fdad9fadacf63cb2de26ebddce56e11b20651555e8d6c6130
service:
args:
addr: ":9253"
fastcgi: "unix:///run/php/php-fpm.sock"
postgres_exporter:
version: v0.8.0
service:
env:
- 'DATA_SOURCE_NAME=foo:bar@/'
archive:
official: false
# yamllint disable-line rule:line-length
source: https://github.com/wrouesnel/postgres_exporter/releases/download/v0.8.0/postgres_exporter_v0.8.0_linux-amd64.tar.gz
skip_verify: true
linux:
# 'Alternatives system' priority: zero disables (default)
# yamllint disable-line rule:braces