From 8a488591bb190d712fd44588ae727d1eb92fdac3 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Sun, 11 Mar 2018 00:47:33 +0100 Subject: [PATCH 1/7] __prometheus_server: switch to packages; assume prometheus 2.x --- cdist/conf/type/__prometheus_server/man.rst | 24 ++------ cdist/conf/type/__prometheus_server/manifest | 61 ++++++++++++------- .../__prometheus_server/parameter/boolean | 1 + .../__prometheus_server/parameter/required | 2 - 4 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 cdist/conf/type/__prometheus_server/parameter/boolean diff --git a/cdist/conf/type/__prometheus_server/man.rst b/cdist/conf/type/__prometheus_server/man.rst index fadebd3f..33dd3e53 100644 --- a/cdist/conf/type/__prometheus_server/man.rst +++ b/cdist/conf/type/__prometheus_server/man.rst @@ -10,18 +10,12 @@ DESCRIPTION ----------- Install and configure Prometheus (https://prometheus.io/). -This type creates a daemontools-compatible service directory under /service/prometheus. -Daemontools (or something compatible) must be installed (in particular, the command `svc` must be executable). - +Note that due to significant differences between Prometheus 1.x and 2.x, only 2.x is supported. 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 @@ -32,8 +26,6 @@ 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 @@ -49,22 +41,16 @@ EXAMPLES 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 \ - --with-daemontools \ + __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" + --rule-files "$__manifest/files/*.rules" SEE ALSO -------- -:strong:`cdist-type__prometheus_alertmanager`\ (7), :strong:`cdist-type__daemontools`\ (7), +:strong:`cdist-type__prometheus_alertmanager`\ (7), :strong:`cdist-type__grafana_dashboard`\ (7), Prometheus documentation: https://prometheus.io/docs/introduction/overview/ AUTHORS @@ -73,7 +59,7 @@ Kamila Součková COPYING ------- -Copyright \(C) 2017 Kamila Součková. You can redistribute it +Copyright \(C) 2018 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 index 96717ed6..d19d35b1 100755 --- a/cdist/conf/type/__prometheus_server/manifest +++ b/cdist/conf/type/__prometheus_server/manifest @@ -1,52 +1,69 @@ #!/bin/sh -e -GOBIN=/opt/gocode/bin # where to find go binaries +##### HARD-CODED CONFIG ##################################################### + CONF_DIR=/etc/prometheus CONF=$CONF_DIR/prometheus.yml -LOGLEVEL=info + +##### GET SETTINGS ########################################################## 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)) +##### INSTALL THE PACKAGE ################################################### -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" +if [ -f "$__object/parameter/install-from-backports" ]; then + os=$(cat "$__global/explorer/os") + lsb_codename=$(cat "$__global/explorer/lsb_codename") -REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')" + case $os in + devuan) + if [ -z "$lsb_codename" ]; then + echo "Command `lsb_release` not functional -- is package `lsb-release` installed?" >&2 + exit 1 + fi + [ "$lsb_codename" = "n/a" ] && lsb_codename='ascii' # TODO this is a devuan bug that should be fixed soon => remove when no longer needed + __apt_source backports --uri http://auto.mirror.devuan.org/merged --distribution $lsb_codename-backports --component main + require="$require __apt_source/backports" __package_apt prometheus --target-release $lsb_codename-backports + ;; + *) + echo "--install-from-backports is only supported on Devuan -- ignoring" >&2 + echo "send a pull request if you require it" >&2 + ;; + esac +else + __package prometheus +fi -__go_get github.com/prometheus/prometheus/cmd/... +##### PREPARE PATHS AND SUCH ################################################ -__user prometheus --system -require="__user/prometheus" __directory "$storage_path" --owner prometheus --parents -require="__user/prometheus" __directory "$CONF_DIR" --owner prometheus --parents +require="__package_apt/prometheus" __directory "$storage_path" --owner prometheus --parents -__daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $REAL_FLAGS" +##### CONFIGURE ############################################################# -require="$require __directory/$storage_path __user/prometheus" \ +FLAGS="--storage.tsdb.path $storage_path --storage.tsdb.retention $(($retention_days*24))h" + +# TODO it would be neat to restart prometheus on change -- __key_value really should have an --onchange parameter +require="$require __package_apt/prometheus" \ +__key_value prometheus_args --file /etc/default/prometheus --key "ARGS" --value "\"$FLAGS\"" --delimiter "=" + +require="$require __directory/$storage_path __package_apt/prometheus" \ __config_file $CONF \ --source $config \ --group prometheus --mode 640 \ - --onchange "$GOBIN/promtool check-config $CONF && svc -h /service/prometheus" + --onchange "promtool check config $CONF && service prometheus reload" for file in $rule_files; do dest=$CONF_DIR/$(basename $file) - require="$require __directory/$CONF_DIR __user/prometheus" \ + require="$require __package_apt/prometheus" \ __config_file "$dest" \ --source "$file" \ --owner prometheus \ - --onchange "$GOBIN/promtool check-rules '$dest' && svc -h /service/prometheus" + --onchange "promtool check rules '$dest' && service prometheus reload" 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..5d15e93d --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/boolean @@ -0,0 +1 @@ +install-from-backports diff --git a/cdist/conf/type/__prometheus_server/parameter/required b/cdist/conf/type/__prometheus_server/parameter/required index 49abf924..04204c7c 100644 --- a/cdist/conf/type/__prometheus_server/parameter/required +++ b/cdist/conf/type/__prometheus_server/parameter/required @@ -1,3 +1 @@ -alertmanager-url config -listen-address From ee6d63325d5e0267be90a70ae0c9db0e35764968 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Sun, 11 Mar 2018 01:28:26 +0100 Subject: [PATCH 2/7] new __prometheus_alertmanager; fixes to __prometheus_server --- .../type/__prometheus_alertmanager/manifest | 62 ++++++++++++++----- .../parameter/boolean | 1 + .../parameter/default/retention-days | 1 + .../parameter/optional | 1 + .../parameter/required | 1 - cdist/conf/type/__prometheus_server/manifest | 13 ++-- .../parameter/default/target-heap-size | 1 - .../__prometheus_server/parameter/optional | 1 - 8 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 cdist/conf/type/__prometheus_alertmanager/parameter/boolean create mode 100644 cdist/conf/type/__prometheus_alertmanager/parameter/default/retention-days delete mode 100644 cdist/conf/type/__prometheus_server/parameter/default/target-heap-size diff --git a/cdist/conf/type/__prometheus_alertmanager/manifest b/cdist/conf/type/__prometheus_alertmanager/manifest index 0dbce3c2..926ad712 100755 --- a/cdist/conf/type/__prometheus_alertmanager/manifest +++ b/cdist/conf/type/__prometheus_alertmanager/manifest @@ -1,34 +1,64 @@ #!/bin/sh -e -GOBIN=/opt/gocode/bin # where to find go binaries +##### HARD-CODED CONFIG ##################################################### + CONF_DIR=/etc/prometheus -LOGLEVEL=info CONF=$CONF_DIR/alertmanager.yml -### Prometheus server ####################################################### +##### GET SETTINGS ########################################################## 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")" +# listen_address="$(cat "$__object/parameter/listen-address")" -FLAGS="config.file '$CONF' -storage.path '$storage_path' -web.listen-address '$listen_address' -log.level $LOGLEVEL" +##### INSTALL THE PACKAGE ################################################### -REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')" +require_pkg="" # what to require if I want to require "the package" +if [ -f "$__object/parameter/install-from-backports" ]; then + os=$(cat "$__global/explorer/os") + lsb_codename=$(cat "$__global/explorer/lsb_codename") -__go_get github.com/prometheus/alertmanager/cmd/... + case $os in + devuan) + if [ -z "$lsb_codename" ]; then + echo "Command `lsb_release` not functional -- is package `lsb-release` installed?" >&2 + exit 1 + fi + [ "$lsb_codename" = "n/a" ] && lsb_codename='ascii' # TODO this is a devuan bug that should be fixed soon => remove when no longer needed + __apt_source backports --uri http://auto.mirror.devuan.org/merged --distribution $lsb_codename-backports --component main + require="$require __apt_source/backports" __package_apt prometheus-alertmanager --target-release $lsb_codename-backports + require_pkg="__package_apt/prometheus-alertmanager" + ;; + *) + echo "--install-from-backports is only supported on Devuan -- ignoring" >&2 + echo "send a pull request if you require it" >&2 + ;; + esac +else + __package prometheus-alertmanager + require_pkg="__package/prometheus-alertmanager" +fi -__user prometheus --system -require="__user/prometheus" __directory "$storage_path" --owner prometheus --parents -require="__user/prometheus" __directory "$CONF_DIR" --owner prometheus --parents +##### PREPARE PATHS AND SUCH ################################################ -__daemontools_service alertmanager --run "setuidgid prometheus $GOBIN/alertmanager $REAL_FLAGS" +require="$require $require_pkg" __directory "$storage_path" --owner prometheus --parents -require="$require __directory/$storage_path __user/prometheus" \ +# TODO this is a bug in the init script, patching it like this is awful and it should be reported +require="$require $require_pkg" \ +__key_value alertmanager_fix_init_script --file /etc/init.d/prometheus-alertmanager --key="NAME" --value="prometheus-alertmanager" --delimiter "=" + + +##### CONFIGURE ############################################################# + +FLAGS="--storage.path $storage_path --data.retention $(($retention_days*24))h --web.listen-address [::]:9093" + +require="$require $require_pkg" \ +__key_value alertmanager_args --file /etc/default/prometheus-alertmanager --key="ARGS" --value="\"$FLAGS\"" --delimiter "=" + +require="$require __directory/$storage_path $require_pkg" \ __config_file $CONF \ --source $config \ --group prometheus --mode 640 \ - --onchange "svc -h /service/alertmanager" # TODO when a config-check tool is available, check config here + --onchange "service prometheus-alertmanager reload" # TODO when a config-check tool is available, check config here diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/boolean b/cdist/conf/type/__prometheus_alertmanager/parameter/boolean new file mode 100644 index 00000000..5d15e93d --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/boolean @@ -0,0 +1 @@ +install-from-backports diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/default/retention-days b/cdist/conf/type/__prometheus_alertmanager/parameter/default/retention-days new file mode 100644 index 00000000..d61f00d8 --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/default/retention-days @@ -0,0 +1 @@ +90 diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/optional b/cdist/conf/type/__prometheus_alertmanager/parameter/optional index f99d0d37..7fe79009 100644 --- a/cdist/conf/type/__prometheus_alertmanager/parameter/optional +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/optional @@ -1 +1,2 @@ storage-path +retention-days diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/required b/cdist/conf/type/__prometheus_alertmanager/parameter/required index 02cb49d0..04204c7c 100644 --- a/cdist/conf/type/__prometheus_alertmanager/parameter/required +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/required @@ -1,2 +1 @@ config -listen-address diff --git a/cdist/conf/type/__prometheus_server/manifest b/cdist/conf/type/__prometheus_server/manifest index d19d35b1..a5c31b4e 100755 --- a/cdist/conf/type/__prometheus_server/manifest +++ b/cdist/conf/type/__prometheus_server/manifest @@ -17,6 +17,7 @@ rule_files="$(cat "$__object/parameter/rule-files")" ##### INSTALL THE PACKAGE ################################################### +require_pkg="" # what to require if I want to require "the package" if [ -f "$__object/parameter/install-from-backports" ]; then os=$(cat "$__global/explorer/os") lsb_codename=$(cat "$__global/explorer/lsb_codename") @@ -30,6 +31,7 @@ if [ -f "$__object/parameter/install-from-backports" ]; then [ "$lsb_codename" = "n/a" ] && lsb_codename='ascii' # TODO this is a devuan bug that should be fixed soon => remove when no longer needed __apt_source backports --uri http://auto.mirror.devuan.org/merged --distribution $lsb_codename-backports --component main require="$require __apt_source/backports" __package_apt prometheus --target-release $lsb_codename-backports + require_pkg="__package_apt/prometheus" ;; *) echo "--install-from-backports is only supported on Devuan -- ignoring" >&2 @@ -38,21 +40,22 @@ if [ -f "$__object/parameter/install-from-backports" ]; then esac else __package prometheus + require_pkg="__package/prometheus" fi ##### PREPARE PATHS AND SUCH ################################################ -require="__package_apt/prometheus" __directory "$storage_path" --owner prometheus --parents +require="$require $require_pkg" __directory "$storage_path" --owner prometheus --parents ##### CONFIGURE ############################################################# -FLAGS="--storage.tsdb.path $storage_path --storage.tsdb.retention $(($retention_days*24))h" +FLAGS="--storage.tsdb.path $storage_path --storage.tsdb.retention $(($retention_days*24))h --web.listen-address [::]:9090" # TODO it would be neat to restart prometheus on change -- __key_value really should have an --onchange parameter -require="$require __package_apt/prometheus" \ +require="$require $require_pkg" \ __key_value prometheus_args --file /etc/default/prometheus --key "ARGS" --value "\"$FLAGS\"" --delimiter "=" -require="$require __directory/$storage_path __package_apt/prometheus" \ +require="$require __directory/$storage_path $require_pkg" \ __config_file $CONF \ --source $config \ --group prometheus --mode 640 \ @@ -60,7 +63,7 @@ __config_file $CONF \ for file in $rule_files; do dest=$CONF_DIR/$(basename $file) - require="$require __package_apt/prometheus" \ + require="$require $require_pkg" \ __config_file "$dest" \ --source "$file" \ --owner 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 deleted file mode 100644 index 865faf10..00000000 --- a/cdist/conf/type/__prometheus_server/parameter/default/target-heap-size +++ /dev/null @@ -1 +0,0 @@ -auto diff --git a/cdist/conf/type/__prometheus_server/parameter/optional b/cdist/conf/type/__prometheus_server/parameter/optional index 4d8d8f3e..cb437211 100644 --- a/cdist/conf/type/__prometheus_server/parameter/optional +++ b/cdist/conf/type/__prometheus_server/parameter/optional @@ -1,4 +1,3 @@ -target-heap-size retention-days rule-files storage-path From 34aefbc0f6ea3340c6661f1c23be3ae1fe5f0a71 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Sun, 11 Mar 2018 01:35:16 +0100 Subject: [PATCH 3/7] __prometheus_{server,alertmanager}: new man pages --- .../type/__prometheus_alertmanager/man.rst | 25 ++++++++----------- .../type/__prometheus_alertmanager/manifest | 1 - cdist/conf/type/__prometheus_server/man.rst | 4 ++- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/cdist/conf/type/__prometheus_alertmanager/man.rst b/cdist/conf/type/__prometheus_alertmanager/man.rst index ba99e7c8..894100c8 100644 --- a/cdist/conf/type/__prometheus_alertmanager/man.rst +++ b/cdist/conf/type/__prometheus_alertmanager/man.rst @@ -18,19 +18,20 @@ 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.) +retention-days + How long to retain data. Default: 90 days. BOOLEAN PARAMETERS ------------------ -None +install-from-backports + Valid on Devuan only. Will enable the backports apt source and install the package from there. Useful for getting a newer version. EXAMPLES @@ -38,21 +39,15 @@ 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 \ - --with-daemontools \ - --config "$__manifest/files/alertmanager.yml" \ - --storage-path /data/alertmanager \ - --listen-address "[::]:$ALERTPORT" + __prometheus_alertmanager \ + --install-from-backports \ + --config "$__manifest/files/alertmanager.yml" \ + --storage-path /data/alertmanager SEE ALSO -------- -:strong:`cdist-type__prometheus_server`\ (7), :strong:`cdist-type__daemontools`\ (7), +:strong:`cdist-type__prometheus_server`\ (7), :strong:`cdist-type__grafana_dashboard`\ (7), Prometheus alerting documentation: https://prometheus.io/docs/alerting/overview/ AUTHORS @@ -61,7 +56,7 @@ Kamila Součková COPYING ------- -Copyright \(C) 2017 Kamila Součková. You can redistribute it +Copyright \(C) 2018 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 index 926ad712..8278170a 100755 --- a/cdist/conf/type/__prometheus_alertmanager/manifest +++ b/cdist/conf/type/__prometheus_alertmanager/manifest @@ -48,7 +48,6 @@ require="$require $require_pkg" __directory "$storage_path" --owner prometheus - require="$require $require_pkg" \ __key_value alertmanager_fix_init_script --file /etc/init.d/prometheus-alertmanager --key="NAME" --value="prometheus-alertmanager" --delimiter "=" - ##### CONFIGURE ############################################################# FLAGS="--storage.path $storage_path --data.retention $(($retention_days*24))h --web.listen-address [::]:9093" diff --git a/cdist/conf/type/__prometheus_server/man.rst b/cdist/conf/type/__prometheus_server/man.rst index 33dd3e53..4308e6c4 100644 --- a/cdist/conf/type/__prometheus_server/man.rst +++ b/cdist/conf/type/__prometheus_server/man.rst @@ -30,7 +30,8 @@ storage-path BOOLEAN PARAMETERS ------------------ -None +install-from-backports + Valid on Devuan only. Will enable the backports apt source and install the package from there. Useful for getting a newer version. EXAMPLES @@ -42,6 +43,7 @@ EXAMPLES ALERTPORT=9093 __prometheus_server \ + --install-from-backports \ --config "$__manifest/files/prometheus.yml" \ --retention-days 14 \ --storage-path /data/prometheus \ From 7ae24cf67785d98c8877e363cf53ad411f2d601b Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Sun, 11 Mar 2018 10:52:25 +0100 Subject: [PATCH 4/7] __grafana_dashboard: cleanup --- cdist/conf/type/__grafana_dashboard/manifest | 54 ++++++++------------ 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/cdist/conf/type/__grafana_dashboard/manifest b/cdist/conf/type/__grafana_dashboard/manifest index 8f089367..e62bd15f 100755 --- a/cdist/conf/type/__grafana_dashboard/manifest +++ b/cdist/conf/type/__grafana_dashboard/manifest @@ -7,44 +7,34 @@ case $os in debian|devuan) case $os_version in 8*|jessie) - __apt_key_uri grafana \ - --name 'Grafana Release Signing Key' \ - --uri https://packagecloud.io/gpg.key - - require="__apt_key_uri/grafana" __apt_source grafana \ - --uri https://packagecloud.io/grafana/stable/debian/ \ - --distribution jessie \ - --component main - - __package apt-transport-https - - require="__apt_source/grafana __package/apt-transport-https" __package grafana - require="__package/grafana" __start_on_boot grafana-server + apt_source_distribution=jessie ;; 9*|ascii/ceres) - __apt_key_uri grafana \ - --name 'Grafana Release Signing Key' \ - --uri https://packagecloud.io/gpg.key - - require="__apt_key_uri/grafana" __apt_source grafana \ - --uri https://packagecloud.io/grafana/stable/debian/ \ - --distribution stretch \ - --component main - - __package apt-transport-https - - require="__apt_source/grafana __package/apt-transport-https" __package grafana - require="__package/grafana" __start_on_boot grafana-server + apt_source_distribution=stretch ;; - *) - echo "Don't know how to install Grafana on $os $os_version. Send us a pull request!" + echo "Don't know how to install Grafana on $os $os_version. Send us a pull request!" >&2 exit 1 - ;; + ;; esac - ;; + + __apt_key_uri grafana \ + --name 'Grafana Release Signing Key' \ + --uri https://packagecloud.io/gpg.key + + require="$require __apt_key_uri/grafana" __apt_source grafana \ + --uri https://packagecloud.io/grafana/stable/debian/ \ + --distribution $apt_source_distribution \ + --component main + + __package apt-transport-https + + require="$require __apt_source/grafana __package/apt-transport-https" __package grafana + require="$require __package/grafana" __start_on_boot grafana-server + require="$require __start_on_boot/grafana-server" __process grafana-server --start "service grafana-server start" + ;; *) - echo "Don't know how to install Grafana on $os. Send us a pull request!" + echo "Don't know how to install Grafana on $os. Send us a pull request!" >&2 exit 1 - ;; + ;; esac From 787f5237e5f3c274c94d7b647f874df14c9ccc71 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Sun, 11 Mar 2018 10:55:21 +0100 Subject: [PATCH 5/7] __prometheus_{server,alertmanager}: use os_version instead of lsb_release works without the `lsb-release` package and actually seems to be more reliable, even though it is inconsistent between debian and devuan --- .../conf/type/__prometheus_alertmanager/manifest | 16 ++++++---------- cdist/conf/type/__prometheus_server/manifest | 16 ++++++---------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/cdist/conf/type/__prometheus_alertmanager/manifest b/cdist/conf/type/__prometheus_alertmanager/manifest index 8278170a..87546f47 100755 --- a/cdist/conf/type/__prometheus_alertmanager/manifest +++ b/cdist/conf/type/__prometheus_alertmanager/manifest @@ -17,22 +17,18 @@ storage_path="$(cat "$__object/parameter/storage-path")" require_pkg="" # what to require if I want to require "the package" if [ -f "$__object/parameter/install-from-backports" ]; then os=$(cat "$__global/explorer/os") - lsb_codename=$(cat "$__global/explorer/lsb_codename") + os_version=$(cat "$__global/explorer/os_version") case $os in devuan) - if [ -z "$lsb_codename" ]; then - echo "Command `lsb_release` not functional -- is package `lsb-release` installed?" >&2 - exit 1 - fi - [ "$lsb_codename" = "n/a" ] && lsb_codename='ascii' # TODO this is a devuan bug that should be fixed soon => remove when no longer needed - __apt_source backports --uri http://auto.mirror.devuan.org/merged --distribution $lsb_codename-backports --component main - require="$require __apt_source/backports" __package_apt prometheus-alertmanager --target-release $lsb_codename-backports + [ "$os_version" = "ascii/ceres" ] && os_version='ascii' # "ascii" used in the repo URLs + __apt_source backports --uri http://auto.mirror.devuan.org/merged --distribution $os_version-backports --component main + require="$require __apt_source/backports" __package_apt prometheus-alertmanager --target-release $os_version-backports require_pkg="__package_apt/prometheus-alertmanager" ;; *) - echo "--install-from-backports is only supported on Devuan -- ignoring" >&2 - echo "send a pull request if you require it" >&2 + echo "--install-from-backports is only supported on Devuan -- ignoring." >&2 + echo "Send a pull request if you require it." >&2 ;; esac else diff --git a/cdist/conf/type/__prometheus_server/manifest b/cdist/conf/type/__prometheus_server/manifest index a5c31b4e..a7ba7884 100755 --- a/cdist/conf/type/__prometheus_server/manifest +++ b/cdist/conf/type/__prometheus_server/manifest @@ -20,22 +20,18 @@ rule_files="$(cat "$__object/parameter/rule-files")" require_pkg="" # what to require if I want to require "the package" if [ -f "$__object/parameter/install-from-backports" ]; then os=$(cat "$__global/explorer/os") - lsb_codename=$(cat "$__global/explorer/lsb_codename") + os_version=$(cat "$__global/explorer/os_version") case $os in devuan) - if [ -z "$lsb_codename" ]; then - echo "Command `lsb_release` not functional -- is package `lsb-release` installed?" >&2 - exit 1 - fi - [ "$lsb_codename" = "n/a" ] && lsb_codename='ascii' # TODO this is a devuan bug that should be fixed soon => remove when no longer needed - __apt_source backports --uri http://auto.mirror.devuan.org/merged --distribution $lsb_codename-backports --component main - require="$require __apt_source/backports" __package_apt prometheus --target-release $lsb_codename-backports + [ "$os_version" = "ascii/ceres" ] && os_version='ascii' # "ascii" used in the repo URLs + __apt_source backports --uri http://auto.mirror.devuan.org/merged --distribution $os_version-backports --component main + require="$require __apt_source/backports" __package_apt prometheus --target-release $os_version-backports require_pkg="__package_apt/prometheus" ;; *) - echo "--install-from-backports is only supported on Devuan -- ignoring" >&2 - echo "send a pull request if you require it" >&2 + echo "--install-from-backports is only supported on Devuan -- ignoring." >&2 + echo "Send a pull request if you require it." >&2 ;; esac else From e63c3429da906510b16587888f98490be87bc114 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Sun, 11 Mar 2018 11:07:59 +0100 Subject: [PATCH 6/7] __prometheus_{server,alertmanager}: update man pages --- cdist/conf/type/__prometheus_alertmanager/man.rst | 3 +-- cdist/conf/type/__prometheus_server/man.rst | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__prometheus_alertmanager/man.rst b/cdist/conf/type/__prometheus_alertmanager/man.rst index 894100c8..67e97eaf 100644 --- a/cdist/conf/type/__prometheus_alertmanager/man.rst +++ b/cdist/conf/type/__prometheus_alertmanager/man.rst @@ -10,8 +10,7 @@ DESCRIPTION ----------- Install and configure Prometheus Alertmanager (https://prometheus.io/docs/alerting/alertmanager/). -This type create a daemontools-compatible service directory under /service/prometheus. -Daemontools (or something compatible) must be installed (in particular, the command `svc` must be executable). +Note that due to significant differences between Prometheus 1.x and 2.x, only 2.x is supported. It is your responsibility to make sure that your package manager installs 2.x. (On Devuan Ascii, the parameter `--install-from-backports` helps.) REQUIRED PARAMETERS diff --git a/cdist/conf/type/__prometheus_server/man.rst b/cdist/conf/type/__prometheus_server/man.rst index 4308e6c4..ab6a3c9b 100644 --- a/cdist/conf/type/__prometheus_server/man.rst +++ b/cdist/conf/type/__prometheus_server/man.rst @@ -10,7 +10,7 @@ DESCRIPTION ----------- Install and configure Prometheus (https://prometheus.io/). -Note that due to significant differences between Prometheus 1.x and 2.x, only 2.x is supported. +Note that due to significant differences between Prometheus 1.x and 2.x, only 2.x is supported. It is your responsibility to make sure that your package manager installs 2.x. (On Devuan Ascii, the parameter `--install-from-backports` helps.) REQUIRED PARAMETERS ------------------- From f03a0e586e3d867d65244b586fee6516c8854a6c Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Sun, 11 Mar 2018 11:40:47 +0100 Subject: [PATCH 7/7] __prometheus_{server,alertmanager}: restart when cli parameters change --- cdist/conf/type/__prometheus_alertmanager/manifest | 8 ++++++-- cdist/conf/type/__prometheus_server/manifest | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__prometheus_alertmanager/manifest b/cdist/conf/type/__prometheus_alertmanager/manifest index 87546f47..be50b71e 100755 --- a/cdist/conf/type/__prometheus_alertmanager/manifest +++ b/cdist/conf/type/__prometheus_alertmanager/manifest @@ -42,14 +42,18 @@ require="$require $require_pkg" __directory "$storage_path" --owner prometheus - # TODO this is a bug in the init script, patching it like this is awful and it should be reported require="$require $require_pkg" \ -__key_value alertmanager_fix_init_script --file /etc/init.d/prometheus-alertmanager --key="NAME" --value="prometheus-alertmanager" --delimiter "=" +__key_value alertmanager_fix_init_script --file /etc/init.d/prometheus-alertmanager \ + --key "NAME" --value "prometheus-alertmanager" --delimiter "=" \ + --onchange "service prometheus-alertmanager restart" ##### CONFIGURE ############################################################# FLAGS="--storage.path $storage_path --data.retention $(($retention_days*24))h --web.listen-address [::]:9093" require="$require $require_pkg" \ -__key_value alertmanager_args --file /etc/default/prometheus-alertmanager --key="ARGS" --value="\"$FLAGS\"" --delimiter "=" +__key_value alertmanager_args --file /etc/default/prometheus-alertmanager \ + --key "ARGS" --value "\"$FLAGS\"" --delimiter "=" \ + --onchange "service prometheus-alertmanager restart" require="$require __directory/$storage_path $require_pkg" \ __config_file $CONF \ diff --git a/cdist/conf/type/__prometheus_server/manifest b/cdist/conf/type/__prometheus_server/manifest index a7ba7884..84ba53cf 100755 --- a/cdist/conf/type/__prometheus_server/manifest +++ b/cdist/conf/type/__prometheus_server/manifest @@ -49,7 +49,9 @@ FLAGS="--storage.tsdb.path $storage_path --storage.tsdb.retention $(($retention_ # TODO it would be neat to restart prometheus on change -- __key_value really should have an --onchange parameter require="$require $require_pkg" \ -__key_value prometheus_args --file /etc/default/prometheus --key "ARGS" --value "\"$FLAGS\"" --delimiter "=" +__key_value prometheus_args --file /etc/default/prometheus \ + --key "ARGS" --value "\"$FLAGS\"" --delimiter "=" \ + --onchange "service prometheus restart" require="$require __directory/$storage_path $require_pkg" \ __config_file $CONF \