is it Christmas today? So many new awesome types!

This commit is contained in:
kamila 2017-06-01 23:52:23 +02:00
parent 8d5e207577
commit 2272539c16
17 changed files with 255 additions and 0 deletions

View File

@ -0,0 +1,66 @@
cdist-type__prometheus_alertmanager(7)
======================================
NAME
----
cdist-type__prometheus_alertmanager - install Alertmanager
DESCRIPTION
-----------
Install and configure Prometheus Alertmanager (https://prometheus.io/docs/alerting/alertmanager/).
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.)
BOOLEAN PARAMETERS
------------------
with-daemontools
Create a daemontools service directory under /service/prometheus. Default: yes.
Note: If you do not use this, Alertmanager will not be launched, and will not reload config on change.
If you use this, daemontools (or something compatible) must be installed.
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 \
--config "$__manifest/files/alertmanager.yml" \
--storage-path /data/alertmanager \
--listen-address "[::]:$ALERTPORT"
SEE ALSO
--------
:strong:`cdist-type__prometheus_server`\ (7), :strong:`cdist-type__daemontools`\ (7),
Prometheus alerting documentation: https://prometheus.io/docs/alerting/overview/
AUTHORS
-------
Kamila Součková <kamila--@--ksp.sk>
COPYING
-------
Copyright \(C) 2017 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.

View File

@ -0,0 +1,39 @@
#!/bin/sh
GOBIN=/opt/gocode/bin # where to find go binaries
CONF_DIR=/etc/prometheus
LOGLEVEL=info
CONF=$CONF_DIR/alertmanager.yml
### Prometheus server #######################################################
config="$(cat "$__object/parameter/config")"
storage_path="$(cat "$__object/parameter/storage-path")"
listen_address="$(cat "$__object/parameter/listen-address")"
ONCHANGE=""
if [ -f "$__object/parameter/with-daemontools" ]; then
__daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $REAL_FLAGS"
ONCHANGE="svc -h /service/prometheus"
fi
FLAGS="config.file '$CONF'
storage.path '$storage_path'
web.listen-address '$listen_address'
log.level $LOGLEVEL"
REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')"
__go_get github.com/prometheus/alertmanager/cmd/...
__user prometheus --system
__directory "$storage_path" --owner prometheus
__directory "$CONF_DIR" --owner prometheus
__daemontools_service alertmanager --run "setuidgid prometheus $GOBIN/alertmanager $REAL_FLAGS"
require="$require __directory/$storage_path" \
__config_file $CONF \
--source $config \
--group prometheus --mode 640 \
--onchange "$ONCHANGE"

View File

@ -0,0 +1 @@
/data/alertmanager

View File

@ -0,0 +1 @@
storage-path

View File

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

View File

@ -0,0 +1,78 @@
cdist-type__prometheus_server(7)
================================
NAME
----
cdist-type__prometheus_server - install Prometheus
DESCRIPTION
-----------
Install and configure Prometheus (https://prometheus.io/).
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
-------------------
retention-days
How long to keep data. Default: 30
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
------------------
with-daemontools
Create a daemontools service directory under /service/prometheus. Default: yes.
Note: If you do not use this, Prometheus will not be launched, and will not reload config on change.
If you use this, daemontools (or something compatible) must be installed.
EXAMPLES
--------
.. code-block:: sh
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 \
--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"
SEE ALSO
--------
:strong:`cdist-type__prometheus_alertmanager`\ (7), :strong:`cdist-type__daemontools`\ (7),
Prometheus documentation: https://prometheus.io/docs/introduction/overview/
AUTHORS
-------
Kamila Součková <kamila--@--ksp.sk>
COPYING
-------
Copyright \(C) 2017 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.

View File

@ -0,0 +1,57 @@
#!/bin/sh
GOBIN=/opt/gocode/bin # where to find go binaries
CONF_DIR=/etc/prometheus
CONF=$CONF_DIR/prometheus.yml
LOGLEVEL=info
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))
ONCHANGE=""
if [ -f "$__object/parameter/with-daemontools" ]; then
__daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $REAL_FLAGS"
ONCHANGE="&& svc -h /service/prometheus"
fi
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"
REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')"
__go_get github.com/prometheus/prometheus/cmd/...
__user prometheus --system
__directory "$storage_path" --owner prometheus
__directory "$CONF_DIR" --owner prometheus
require="$require __directory/$storage_path" \
__config_file $CONF \
--source $config \
--group prometheus --mode 640 \
--onchange "$GOBIN/promtool check-config $CONF $ONCHANGE"
for file in $rule_files; do
dest=$CONF_DIR/$(basename $file)
require="$require __directory/$CONF_DIR" \
__config_file "$dest" \
--source "$file" \
--owner prometheus \
--onchange "$GOBIN/promtool check-rules '$dest' $ONCHANGE"
done

View File

@ -0,0 +1 @@
with-daemontools

View File

@ -0,0 +1 @@
/data/prometheus

View File

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

View File

@ -0,0 +1,3 @@
alertmanager-url
config
listen-address