From 2272539c16e594a3c4705b9aa4466b42f680d716 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Thu, 1 Jun 2017 23:52:23 +0200 Subject: [PATCH 1/2] is it Christmas today? So many new awesome types! --- .../type/__prometheus_alertmanager/man.rst | 66 ++++++++++++++++ .../type/__prometheus_alertmanager/manifest | 39 ++++++++++ .../parameter/default/storage-path | 1 + .../parameter/optional | 1 + .../parameter/required | 2 + .../type/__prometheus_alertmanager/singleton | 0 cdist/conf/type/__prometheus_server/man.rst | 78 +++++++++++++++++++ cdist/conf/type/__prometheus_server/manifest | 57 ++++++++++++++ .../__prometheus_server/parameter/boolean | 1 + .../parameter/default/retention-days | 1 + .../parameter/default/rule-files | 0 .../parameter/default/storage-path | 1 + .../parameter/default/target-heap-size | 1 + .../parameter/default/with-daemontools | 0 .../__prometheus_server/parameter/optional | 4 + .../__prometheus_server/parameter/required | 3 + cdist/conf/type/__prometheus_server/singleton | 0 17 files changed, 255 insertions(+) create mode 100644 cdist/conf/type/__prometheus_alertmanager/man.rst create mode 100644 cdist/conf/type/__prometheus_alertmanager/manifest create mode 100644 cdist/conf/type/__prometheus_alertmanager/parameter/default/storage-path create mode 100644 cdist/conf/type/__prometheus_alertmanager/parameter/optional create mode 100644 cdist/conf/type/__prometheus_alertmanager/parameter/required create mode 100644 cdist/conf/type/__prometheus_alertmanager/singleton create mode 100644 cdist/conf/type/__prometheus_server/man.rst create mode 100644 cdist/conf/type/__prometheus_server/manifest create mode 100644 cdist/conf/type/__prometheus_server/parameter/boolean create mode 100644 cdist/conf/type/__prometheus_server/parameter/default/retention-days create mode 100644 cdist/conf/type/__prometheus_server/parameter/default/rule-files create mode 100644 cdist/conf/type/__prometheus_server/parameter/default/storage-path create mode 100644 cdist/conf/type/__prometheus_server/parameter/default/target-heap-size create mode 100644 cdist/conf/type/__prometheus_server/parameter/default/with-daemontools create mode 100644 cdist/conf/type/__prometheus_server/parameter/optional create mode 100644 cdist/conf/type/__prometheus_server/parameter/required create mode 100644 cdist/conf/type/__prometheus_server/singleton diff --git a/cdist/conf/type/__prometheus_alertmanager/man.rst b/cdist/conf/type/__prometheus_alertmanager/man.rst new file mode 100644 index 00000000..f218254e --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/man.rst @@ -0,0 +1,66 @@ +cdist-type__prometheus_alertmanager(7) +====================================== + +NAME +---- +cdist-type__prometheus_alertmanager - install Alertmanager + + +DESCRIPTION +----------- +Install and configure Prometheus Alertmanager (https://prometheus.io/docs/alerting/alertmanager/). + + +REQUIRED PARAMETERS +------------------- +config + Alertmanager configuration file. It will be saved as /etc/alertmanager/alertmanager.yml on the target. +listen-address + Passed as web.listen-address. + + +OPTIONAL PARAMETERS +------------------- +storage-path + Where to put data. Default: /data/alertmanager. (Directory will be created if needed.) + + +BOOLEAN PARAMETERS +------------------ +with-daemontools + Create a daemontools service directory under /service/prometheus. Default: yes. + Note: If you do not use this, Alertmanager will not be launched, and will not reload config on change. + If you use this, daemontools (or something compatible) must be installed. + + +EXAMPLES +-------- + +.. code-block:: sh + + ALERTPORT=9093 + + __daemontools + __golang_from_vendor --version 1.8.1 # required for prometheus and many exporters + + require="__daemontools __golang_from_vendor" __prometheus_alertmanager \ + --config "$__manifest/files/alertmanager.yml" \ + --storage-path /data/alertmanager \ + --listen-address "[::]:$ALERTPORT" + + +SEE ALSO +-------- +:strong:`cdist-type__prometheus_server`\ (7), :strong:`cdist-type__daemontools`\ (7), +Prometheus alerting documentation: https://prometheus.io/docs/alerting/overview/ + +AUTHORS +------- +Kamila Součková + +COPYING +------- +Copyright \(C) 2017 Kamila Součková. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/cdist/conf/type/__prometheus_alertmanager/manifest b/cdist/conf/type/__prometheus_alertmanager/manifest new file mode 100644 index 00000000..61ac2d20 --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/manifest @@ -0,0 +1,39 @@ +#!/bin/sh + +GOBIN=/opt/gocode/bin # where to find go binaries +CONF_DIR=/etc/prometheus +LOGLEVEL=info +CONF=$CONF_DIR/alertmanager.yml + +### Prometheus server ####################################################### + +config="$(cat "$__object/parameter/config")" +storage_path="$(cat "$__object/parameter/storage-path")" +listen_address="$(cat "$__object/parameter/listen-address")" + +ONCHANGE="" +if [ -f "$__object/parameter/with-daemontools" ]; then + __daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $REAL_FLAGS" + ONCHANGE="svc -h /service/prometheus" +fi + +FLAGS="config.file '$CONF' +storage.path '$storage_path' +web.listen-address '$listen_address' +log.level $LOGLEVEL" + +REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')" + +__go_get github.com/prometheus/alertmanager/cmd/... + +__user prometheus --system +__directory "$storage_path" --owner prometheus +__directory "$CONF_DIR" --owner prometheus + +__daemontools_service alertmanager --run "setuidgid prometheus $GOBIN/alertmanager $REAL_FLAGS" + +require="$require __directory/$storage_path" \ +__config_file $CONF \ + --source $config \ + --group prometheus --mode 640 \ + --onchange "$ONCHANGE" diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/default/storage-path b/cdist/conf/type/__prometheus_alertmanager/parameter/default/storage-path new file mode 100644 index 00000000..4f3e7559 --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/default/storage-path @@ -0,0 +1 @@ +/data/alertmanager diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/optional b/cdist/conf/type/__prometheus_alertmanager/parameter/optional new file mode 100644 index 00000000..f99d0d37 --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/optional @@ -0,0 +1 @@ +storage-path diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/required b/cdist/conf/type/__prometheus_alertmanager/parameter/required new file mode 100644 index 00000000..02cb49d0 --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/required @@ -0,0 +1,2 @@ +config +listen-address diff --git a/cdist/conf/type/__prometheus_alertmanager/singleton b/cdist/conf/type/__prometheus_alertmanager/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__prometheus_server/man.rst b/cdist/conf/type/__prometheus_server/man.rst new file mode 100644 index 00000000..c03a71d5 --- /dev/null +++ b/cdist/conf/type/__prometheus_server/man.rst @@ -0,0 +1,78 @@ +cdist-type__prometheus_server(7) +================================ + +NAME +---- +cdist-type__prometheus_server - install Prometheus + + +DESCRIPTION +----------- +Install and configure Prometheus (https://prometheus.io/). + + +REQUIRED PARAMETERS +------------------- +config + Prometheus configuration file. It will be saved as /etc/prometheus/prometheus.yml on the target. +listen-address + Passed as web.listen-address. +alertmanager-url + Passed as alertmanager.url + + +OPTIONAL PARAMETERS +------------------- +retention-days + How long to keep data. Default: 30 +rule-files + Path to rule files. They will be installed under /etc/prometheus/. You need to include `rule_files: [/etc/prometheus/]` in the config file if you use this. +storage-path + Where to put data. Default: /data/prometheus. (Directory will be created if needed.) +target-heap-size + Passed as storage.local.target-heap-size. Default: 1/2 of RAM. + + +BOOLEAN PARAMETERS +------------------ +with-daemontools + Create a daemontools service directory under /service/prometheus. Default: yes. + Note: If you do not use this, Prometheus will not be launched, and will not reload config on change. + If you use this, daemontools (or something compatible) must be installed. + + +EXAMPLES +-------- + +.. code-block:: sh + + PROMPORT=9090 + ALERTPORT=9093 + + __daemontools + __golang_from_vendor --version 1.8.1 # required for prometheus and many exporters + + require="__daemontools __golang_from_vendor" __prometheus_server \ + --config "$__manifest/files/prometheus.yml" \ + --retention-days 14 \ + --storage-path /data/prometheus \ + --listen-address "[::]:$PROMPORT" \ + --rule-files "$__manifest/files/*.rules" \ + --alertmanager-url "http://monitoring1.node.consul:$ALERTPORT,http://monitoring2.node.consul:$ALERTPORT" + + +SEE ALSO +-------- +:strong:`cdist-type__prometheus_alertmanager`\ (7), :strong:`cdist-type__daemontools`\ (7), +Prometheus documentation: https://prometheus.io/docs/introduction/overview/ + +AUTHORS +------- +Kamila Součková + +COPYING +------- +Copyright \(C) 2017 Kamila Součková. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/cdist/conf/type/__prometheus_server/manifest b/cdist/conf/type/__prometheus_server/manifest new file mode 100644 index 00000000..dd81701d --- /dev/null +++ b/cdist/conf/type/__prometheus_server/manifest @@ -0,0 +1,57 @@ +#!/bin/sh + +GOBIN=/opt/gocode/bin # where to find go binaries +CONF_DIR=/etc/prometheus +CONF=$CONF_DIR/prometheus.yml +LOGLEVEL=info + +config="$(cat "$__object/parameter/config")" +retention_days="$(cat "$__object/parameter/retention-days")" +storage_path="$(cat "$__object/parameter/storage-path")" +listen_address="$(cat "$__object/parameter/listen-address")" +alertmanager_url="$(cat "$__object/parameter/alertmanager-url")" +target_heap_size="$(cat "$__object/parameter/target-heap-size")" +rule_files="$(cat "$__object/parameter/rule-files")" + +# explorer in kB => convert; by default we go with 1/2 RAM +[ "$target_heap_size" = "auto" ] && target_heap_size=$(($(cat $__global/explorer/memory)*1024/2)) + +ONCHANGE="" +if [ -f "$__object/parameter/with-daemontools" ]; then + __daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $REAL_FLAGS" + ONCHANGE="&& svc -h /service/prometheus" +fi + +FLAGS="config.file '$CONF' +storage.local.path '$storage_path' +storage.local.target-heap-size $(($target_heap_size)) # in bytes; should be 2/3 of available memory because it may be hungry +storage.local.retention $(($retention_days*24))h # golang doesn't have days :D +web.listen-address '$listen_address' +alertmanager.url '$alertmanager_url' +log.level $LOGLEVEL" + +REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')" + +__go_get github.com/prometheus/prometheus/cmd/... + +__user prometheus --system +__directory "$storage_path" --owner prometheus +__directory "$CONF_DIR" --owner prometheus + + + +require="$require __directory/$storage_path" \ +__config_file $CONF \ + --source $config \ + --group prometheus --mode 640 \ + --onchange "$GOBIN/promtool check-config $CONF $ONCHANGE" + +for file in $rule_files; do + dest=$CONF_DIR/$(basename $file) + require="$require __directory/$CONF_DIR" \ + __config_file "$dest" \ + --source "$file" \ + --owner prometheus \ + --onchange "$GOBIN/promtool check-rules '$dest' $ONCHANGE" +done + diff --git a/cdist/conf/type/__prometheus_server/parameter/boolean b/cdist/conf/type/__prometheus_server/parameter/boolean new file mode 100644 index 00000000..de4eefdd --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/boolean @@ -0,0 +1 @@ +with-daemontools diff --git a/cdist/conf/type/__prometheus_server/parameter/default/retention-days b/cdist/conf/type/__prometheus_server/parameter/default/retention-days new file mode 100644 index 00000000..64bb6b74 --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/default/retention-days @@ -0,0 +1 @@ +30 diff --git a/cdist/conf/type/__prometheus_server/parameter/default/rule-files b/cdist/conf/type/__prometheus_server/parameter/default/rule-files new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__prometheus_server/parameter/default/storage-path b/cdist/conf/type/__prometheus_server/parameter/default/storage-path new file mode 100644 index 00000000..fc05f8f3 --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/default/storage-path @@ -0,0 +1 @@ +/data/prometheus diff --git a/cdist/conf/type/__prometheus_server/parameter/default/target-heap-size b/cdist/conf/type/__prometheus_server/parameter/default/target-heap-size new file mode 100644 index 00000000..865faf10 --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/default/target-heap-size @@ -0,0 +1 @@ +auto diff --git a/cdist/conf/type/__prometheus_server/parameter/default/with-daemontools b/cdist/conf/type/__prometheus_server/parameter/default/with-daemontools new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__prometheus_server/parameter/optional b/cdist/conf/type/__prometheus_server/parameter/optional new file mode 100644 index 00000000..4d8d8f3e --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/optional @@ -0,0 +1,4 @@ +target-heap-size +retention-days +rule-files +storage-path diff --git a/cdist/conf/type/__prometheus_server/parameter/required b/cdist/conf/type/__prometheus_server/parameter/required new file mode 100644 index 00000000..49abf924 --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/required @@ -0,0 +1,3 @@ +alertmanager-url +config +listen-address diff --git a/cdist/conf/type/__prometheus_server/singleton b/cdist/conf/type/__prometheus_server/singleton new file mode 100644 index 00000000..e69de29b From 4c9863cc542e5e77bc17a19814dd8048de86488b Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 2 Jun 2017 17:39:43 +0200 Subject: [PATCH 2/2] Update changelog --- docs/changelog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index e691145c..c33ad05a 100644 --- a/docs/changelog +++ b/docs/changelog @@ -8,7 +8,8 @@ next: * Type __sysctl: Add devuan support (Nico Schottelius) * Core: Shorten ssh control path (Darko Poljak) * Type __consul: Add new version and add http check (Kamila Součková) - * New types: __daemontools and __daemontools_service (Kamila Součková) + * New types: __daemontools and __daemontools_service (Kamila Součková) + * New types: __prometheus_server and __prometheus_alertmanager (Kamila Součková) 4.4.2: 2017-03-08 * Core: Fix suppression of manifests' outputs (Darko Poljak)