__prometheus_server: switch to packages; assume prometheus 2.x
This commit is contained in:
parent
fe870ba8ba
commit
8a488591bb
4 changed files with 45 additions and 43 deletions
|
@ -10,18 +10,12 @@ DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
Install and configure Prometheus (https://prometheus.io/).
|
Install and configure Prometheus (https://prometheus.io/).
|
||||||
|
|
||||||
This type creates a daemontools-compatible service directory under /service/prometheus.
|
Note that due to significant differences between Prometheus 1.x and 2.x, only 2.x is supported.
|
||||||
Daemontools (or something compatible) must be installed (in particular, the command `svc` must be executable).
|
|
||||||
|
|
||||||
|
|
||||||
REQUIRED PARAMETERS
|
REQUIRED PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
config
|
config
|
||||||
Prometheus configuration file. It will be saved as /etc/prometheus/prometheus.yml on the target.
|
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
|
OPTIONAL PARAMETERS
|
||||||
|
@ -32,8 +26,6 @@ rule-files
|
||||||
Path to rule files. They will be installed under /etc/prometheus/<filename>. You need to include `rule_files: [/etc/prometheus/<your-pattern>]` in the config file if you use this.
|
Path to rule files. They will be installed under /etc/prometheus/<filename>. You need to include `rule_files: [/etc/prometheus/<your-pattern>]` in the config file if you use this.
|
||||||
storage-path
|
storage-path
|
||||||
Where to put data. Default: /data/prometheus. (Directory will be created if needed.)
|
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
|
BOOLEAN PARAMETERS
|
||||||
|
@ -49,22 +41,16 @@ EXAMPLES
|
||||||
PROMPORT=9090
|
PROMPORT=9090
|
||||||
ALERTPORT=9093
|
ALERTPORT=9093
|
||||||
|
|
||||||
__daemontools
|
__prometheus_server \
|
||||||
__golang_from_vendor --version 1.8.1 # required for prometheus and many exporters
|
|
||||||
|
|
||||||
require="__daemontools __golang_from_vendor" __prometheus_server \
|
|
||||||
--with-daemontools \
|
|
||||||
--config "$__manifest/files/prometheus.yml" \
|
--config "$__manifest/files/prometheus.yml" \
|
||||||
--retention-days 14 \
|
--retention-days 14 \
|
||||||
--storage-path /data/prometheus \
|
--storage-path /data/prometheus \
|
||||||
--listen-address "[::]:$PROMPORT" \
|
--rule-files "$__manifest/files/*.rules"
|
||||||
--rule-files "$__manifest/files/*.rules" \
|
|
||||||
--alertmanager-url "http://monitoring1.node.consul:$ALERTPORT,http://monitoring2.node.consul:$ALERTPORT"
|
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
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/
|
Prometheus documentation: https://prometheus.io/docs/introduction/overview/
|
||||||
|
|
||||||
AUTHORS
|
AUTHORS
|
||||||
|
@ -73,7 +59,7 @@ Kamila Součková <kamila--@--ksp.sk>
|
||||||
|
|
||||||
COPYING
|
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
|
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
|
published by the Free Software Foundation, either version 3 of the
|
||||||
License, or (at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
|
@ -1,52 +1,69 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
GOBIN=/opt/gocode/bin # where to find go binaries
|
##### HARD-CODED CONFIG #####################################################
|
||||||
|
|
||||||
CONF_DIR=/etc/prometheus
|
CONF_DIR=/etc/prometheus
|
||||||
CONF=$CONF_DIR/prometheus.yml
|
CONF=$CONF_DIR/prometheus.yml
|
||||||
LOGLEVEL=info
|
|
||||||
|
##### GET SETTINGS ##########################################################
|
||||||
|
|
||||||
config="$(cat "$__object/parameter/config")"
|
config="$(cat "$__object/parameter/config")"
|
||||||
retention_days="$(cat "$__object/parameter/retention-days")"
|
retention_days="$(cat "$__object/parameter/retention-days")"
|
||||||
storage_path="$(cat "$__object/parameter/storage-path")"
|
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")"
|
rule_files="$(cat "$__object/parameter/rule-files")"
|
||||||
|
|
||||||
# explorer in kB => convert; by default we go with 1/2 RAM
|
# 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))
|
[ "$target_heap_size" = "auto" ] && target_heap_size=$(($(cat $__global/explorer/memory)*1024/2))
|
||||||
|
|
||||||
|
##### INSTALL THE PACKAGE ###################################################
|
||||||
|
|
||||||
FLAGS="config.file '$CONF'
|
if [ -f "$__object/parameter/install-from-backports" ]; then
|
||||||
storage.local.path '$storage_path'
|
os=$(cat "$__global/explorer/os")
|
||||||
storage.local.target-heap-size $(($target_heap_size)) # in bytes; should be 2/3 of available memory because it may be hungry
|
lsb_codename=$(cat "$__global/explorer/lsb_codename")
|
||||||
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')"
|
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="__package_apt/prometheus" __directory "$storage_path" --owner prometheus --parents
|
||||||
require="__user/prometheus" __directory "$storage_path" --owner prometheus --parents
|
|
||||||
require="__user/prometheus" __directory "$CONF_DIR" --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 \
|
__config_file $CONF \
|
||||||
--source $config \
|
--source $config \
|
||||||
--group prometheus --mode 640 \
|
--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
|
for file in $rule_files; do
|
||||||
dest=$CONF_DIR/$(basename $file)
|
dest=$CONF_DIR/$(basename $file)
|
||||||
require="$require __directory/$CONF_DIR __user/prometheus" \
|
require="$require __package_apt/prometheus" \
|
||||||
__config_file "$dest" \
|
__config_file "$dest" \
|
||||||
--source "$file" \
|
--source "$file" \
|
||||||
--owner prometheus \
|
--owner prometheus \
|
||||||
--onchange "$GOBIN/promtool check-rules '$dest' && svc -h /service/prometheus"
|
--onchange "promtool check rules '$dest' && service prometheus reload"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
1
cdist/conf/type/__prometheus_server/parameter/boolean
Normal file
1
cdist/conf/type/__prometheus_server/parameter/boolean
Normal file
|
@ -0,0 +1 @@
|
||||||
|
install-from-backports
|
|
@ -1,3 +1 @@
|
||||||
alertmanager-url
|
|
||||||
config
|
config
|
||||||
listen-address
|
|
||||||
|
|
Loading…
Reference in a new issue