Skip to content

Commit

Permalink
Merge pull request #5 from noelmcloughlin/archives
Browse files Browse the repository at this point in the history
feat(archives): tarball archives & linux alternatives
  • Loading branch information
noelmcloughlin authored Jun 23, 2019
2 parents 0527efc + 4092fb4 commit d690778
Show file tree
Hide file tree
Showing 49 changed files with 1,236 additions and 369 deletions.
32 changes: 31 additions & 1 deletion docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ prometheus-formula
:alt: Semantic Release
:scale: 100%
:target: https://github.com/semantic-release/semantic-release
Manage Prometheus.
Manage Prometheus on MacOS, GNU/Linux and FreeBSD.

.. contents:: **Table of Contents**

Expand Down Expand Up @@ -48,11 +48,26 @@ This installs the prometheus package,
manages the prometheus configuration file and then
starts the associated prometheus service.

``prometheus.archive``
^^^^^^^^^^^^^^^^^^^^

This state will install the prometheus from archive file only.

``prometheus.archive.alternatives``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This state will install the prometheus linux alternatives for archives only.

``prometheus.package``
^^^^^^^^^^^^^^^^^^^^

This state will install the prometheus package only.

``prometheus.package.repo``
^^^^^^^^^^^^^^^^^^^^^^^^^

This state will install the prometheus package only.

``prometheus.config``
^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -92,6 +107,21 @@ dependency on ``prometheus.service.clean`` via include list.
This state will remove the prometheus package and has a depency on
``prometheus.config.clean`` via include list.

``prometheus.package.archive.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This state will uninstall the prometheus archive-extracted directory only.

``prometheus.package.archive.alternatives.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This state will uninstall the prometheus linux alternatives for archives only.

``prometheus.package.repo.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^

This state will uninstall the prometheus upstream package repository only.

``prometheus.exporters``
^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
1 change: 0 additions & 1 deletion kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ provisioner:
base:
'*':
- prometheus
- prometheus.exporters
pillars:
top.sls:
base:
Expand Down
153 changes: 120 additions & 33 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,39 @@
# vim: ft=yaml
---
prometheus:
wanted:
- prometheus
{%- if grains.os_family not in ('Debian',) %}
- alertmanager
{%- endif %}
- node_explorer
# no memcached_exporter in upstream repo - only archive
# memcached_exporter

use_upstream_archive: False
{%- if grains.os_family in ('CentOS',) %}
use_upstream_repo: False
{%- endif %}

pkg:
name: prometheus
config_file: /etc/prometheus/prometheus.yml
prometheus:
archive_version: '2.10.0'
archive_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7
alertmanager:
archive_version: '0.17.0'
archive_hash: ec171b13976baceace193461f8a1e61021ab9657df5ba45157cd0095aee7d569

service:
name: prometheus
args:
web.listen-address: 0.0.0.0:9090
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
Expand All @@ -35,37 +61,98 @@ prometheus:

# Pillar-based config
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=<job_name>` 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=<job_name>` 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.

exporters:
node:
args:
web.listen-address: ":9110"
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
29 changes: 29 additions & 0 deletions prometheus/archive/alternatives/clean.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
{%- if grains.kernel|lower == 'linux' and p.linux.altpriority|int > 0 %}
{%- for name in p.wanted %}
{%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %}
prometheus-archive-remove-{{ name }}-home-alternatives-remove:
alternatives.remove:
- name: prometheus-{{ name }}-home
- path: {{ p.dir.basedir }}/{{ bundle }}
- onlyif: update-alternatives --get-selections |grep ^prometheus-{{ name }}-home
{% for b in p.pkg[name]['binaries'] %}
prometheus-archive-remove-{{ name }}-alternatives-remove-{{ b }}:
alternatives.remove:
- name: prometheus-{{ name }}-{{ b }}
- path: {{ p.dir.basedir }}/{{ bundle }}/{{ b }}
- onlyif: update-alternatives --get-selections |grep ^prometheus-{{ name }}-{{ b }}
{% endfor %}
{% endfor %}
{%- endif %}
5 changes: 5 additions & 0 deletions prometheus/archive/alternatives/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install
79 changes: 79 additions & 0 deletions prometheus/archive/alternatives/install.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- set sls_archive_install = tplroot ~ '.archive' %}
{%- if grains.kernel|lower in ('linux',) and p.linux.altpriority|int > 0 %}
include:
- {{ sls_archive_install }}
{%- for name in p.wanted %}
{%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %}
{%- if grains.os_family == 'Suse' %}
prometheus-archive-alternatives-install-{{ name }}-home-cmd-run:
cmd.run:
- name: update-alternatives --install {{ p.dir.basedir }}/{{ name }} prometheus-{{ name }}-home {{ p.dir.basedir }}/{{ bundle }} {{p.linux.altpriority}}
- watch:
- archive: prometheus-archive-install-{{ name }}-archive-extracted
{%- else %}
prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install:
alternatives.install:
- 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-{{ name }}-archive-extracted
- onlyif: {{ grains.os_family not in ('Suse',) }}
prometheus-archive-alternatives-install-{{ name }}-home-alternatives-set:
alternatives.set:
- name: prometheus-{{ name }}-home
- path: {{ p.dir.basedir }}/{{ bundle }}
- require:
- cmd: prometheus-archive-alternatives-install-{{ name }}-home-cmd-run
- alternatives: prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install
{%- endif %}
{% for b in p.pkg[name]['binaries'] %}
{%- if grains.os_family == 'Suse' %}
prometheus-archive-alternatives-install-{{ name }}-cmd-run-{{ b }}-alternative:
cmd.run:
- onlyif: {{ grains.os_family in ('Suse',) }}
- 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-{{ name }}-home-cmd-run
{%- else %}
prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }}:
alternatives.install:
- 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-{{ name }}-home-alternatives-install
prometheus-archive-alternatives-install-{{ name }}-alternatives-set-{{ b }}:
alternatives.set:
- name: prometheus-{{ name }}-{{ b }}
- path: {{ p.dir.basedir }}/{{ bundle }}/{{ b }}
- require:
- alternatives: prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }}
{%- endif %}
{% endfor %}
{% endfor %}
{%- endif %}
35 changes: 35 additions & 0 deletions prometheus/archive/clean.sls
Original file line number Diff line number Diff line change
@@ -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 as p with context %}
{%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %}
{%- set sls_users_clean = tplroot ~ '.config.users.clean' %}
{%- set sls_service_clean = tplroot ~ '.service.clean' %}
include:
- {{ sls_users_clean }}
- {{ sls_service_clean }}
- {{ sls_alternatives_clean }}
{%- for name in p.wanted %}
prometheus-archive-clean-{{ name }}-file-absent:
file.absent:
- names:
- {{ p.dir.basedir }}/{{ name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) }}
prometheus-archive-clean-{{ name }}-user-absent:
user.absent:
- name: {{ name }}
group.absent:
- name: {{ name }}
- require:
- user: prometheus-archive-clean-{{ name }}-user-absent
{%- endfor %}
prometheus-archive-clean-basedir-file-directory:
file.absent:
- name: {{ p.dir.basedir }}
Loading

0 comments on commit d690778

Please sign in to comment.