forked from ungleich-public/cdist
Merge pull request #647 from ungleich/new-prometheus
New __prometheus_server, __prometheus_alertmanager, __grafana_dashboard
This commit is contained in:
commit
1bb9da233e
13 changed files with 130 additions and 112 deletions
|
@ -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_source_distribution=stretch
|
||||
;;
|
||||
*)
|
||||
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="__apt_key_uri/grafana" __apt_source grafana \
|
||||
require="$require __apt_key_uri/grafana" __apt_source grafana \
|
||||
--uri https://packagecloud.io/grafana/stable/debian/ \
|
||||
--distribution stretch \
|
||||
--distribution $apt_source_distribution \
|
||||
--component main
|
||||
|
||||
__package apt-transport-https
|
||||
|
||||
require="__apt_source/grafana __package/apt-transport-https" __package grafana
|
||||
require="__package/grafana" __start_on_boot grafana-server
|
||||
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 $os_version. Send us a pull request!"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
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
|
||||
|
|
|
@ -10,27 +10,27 @@ 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
|
||||
-------------------
|
||||
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 +38,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 \
|
||||
__prometheus_alertmanager \
|
||||
--install-from-backports \
|
||||
--config "$__manifest/files/alertmanager.yml" \
|
||||
--storage-path /data/alertmanager \
|
||||
--listen-address "[::]:$ALERTPORT"
|
||||
--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 +55,7 @@ Kamila Součková <kamila--@--ksp.sk>
|
|||
|
||||
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.
|
||||
|
|
|
@ -1,34 +1,63 @@
|
|||
#!/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")
|
||||
os_version=$(cat "$__global/explorer/os_version")
|
||||
|
||||
__go_get github.com/prometheus/alertmanager/cmd/...
|
||||
case $os in
|
||||
devuan)
|
||||
[ "$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
|
||||
;;
|
||||
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 "=" \
|
||||
--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 "=" \
|
||||
--onchange "service prometheus-alertmanager restart"
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
install-from-backports
|
|
@ -0,0 +1 @@
|
|||
90
|
|
@ -1 +1,2 @@
|
|||
storage-path
|
||||
retention-days
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
config
|
||||
listen-address
|
||||
|
|
|
@ -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. 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
|
||||
-------------------
|
||||
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,13 +26,12 @@ 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.
|
||||
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
|
||||
------------------
|
||||
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
|
||||
|
@ -49,22 +42,17 @@ 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 \
|
||||
--install-from-backports \
|
||||
--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 +61,7 @@ Kamila Součková <kamila--@--ksp.sk>
|
|||
|
||||
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.
|
||||
|
|
|
@ -1,52 +1,70 @@
|
|||
#!/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"
|
||||
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")
|
||||
os_version=$(cat "$__global/explorer/os_version")
|
||||
|
||||
REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')"
|
||||
case $os in
|
||||
devuan)
|
||||
[ "$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
|
||||
;;
|
||||
esac
|
||||
else
|
||||
__package prometheus
|
||||
require_pkg="__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="$require $require_pkg" __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 --web.listen-address [::]:9090"
|
||||
|
||||
# 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 "=" \
|
||||
--onchange "service prometheus restart"
|
||||
|
||||
require="$require __directory/$storage_path $require_pkg" \
|
||||
__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 $require_pkg" \
|
||||
__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
|
||||
|
||||
|
|
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 +0,0 @@
|
|||
auto
|
|
@ -1,4 +1,3 @@
|
|||
target-heap-size
|
||||
retention-days
|
||||
rule-files
|
||||
storage-path
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
alertmanager-url
|
||||
config
|
||||
listen-address
|
||||
|
|
Loading…
Reference in a new issue