cdist/cdist/conf/type/__prometheus_server/manifest

70 lines
2.6 KiB
Plaintext
Raw Normal View History

2017-06-28 11:19:32 +00:00
#!/bin/sh -e
##### HARD-CODED CONFIG #####################################################
CONF_DIR=/etc/prometheus
CONF=$CONF_DIR/prometheus.yml
##### GET SETTINGS ##########################################################
config="$(cat "$__object/parameter/config")"
retention_days="$(cat "$__object/parameter/retention-days")"
storage_path="$(cat "$__object/parameter/storage-path")"
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 ###################################################
if [ -f "$__object/parameter/install-from-backports" ]; then
os=$(cat "$__global/explorer/os")
lsb_codename=$(cat "$__global/explorer/lsb_codename")
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
##### PREPARE PATHS AND SUCH ################################################
require="__package_apt/prometheus" __directory "$storage_path" --owner prometheus --parents
##### CONFIGURE #############################################################
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 "promtool check config $CONF && service prometheus reload"
for file in $rule_files; do
dest=$CONF_DIR/$(basename $file)
require="$require __package_apt/prometheus" \
__config_file "$dest" \
--source "$file" \
--owner prometheus \
--onchange "promtool check rules '$dest' && service prometheus reload"
done