new __prometheus_alertmanager; fixes to __prometheus_server

This commit is contained in:
kamila 2018-03-11 01:28:26 +01:00
parent 8a488591bb
commit ee6d63325d
8 changed files with 57 additions and 24 deletions

View file

@ -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

View file

@ -0,0 +1 @@
install-from-backports

View file

@ -1 +1,2 @@
storage-path
retention-days

View file

@ -1,2 +1 @@
config
listen-address

View file

@ -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 \

View file

@ -1,4 +1,3 @@
target-heap-size
retention-days
rule-files
storage-path