add command to create prometheus scrape config

This commit is contained in:
Philipp Rothmann 2023-05-23 12:19:16 +02:00
parent 83eb9c47c2
commit d31d56ed03
1 changed files with 24 additions and 0 deletions

24
abra.sh
View File

@ -9,3 +9,27 @@ export PROMTAIL_YML_VERSION=v1
export LOKI_YML_VERSION=v1
export PROMETHEUS_YML_VERSION=v1
export ALERTMANAGER_CONFIG_VERSION=v1
# creates a default prometheus scrape config for a given node
add_node(){
name=$1
add_domain "$name" "$name:8082/metrics"
add_domain "$name" "node.monitoring.$name"
add_domain "$name" "cadvisor.monitoring.$name"
cat "/prometheus/scrape_configs/$name.yml"
}
# adds a domain to a scrape config or creates a new one
add_domain(){
name=$1
domain=$2
if [ ! -d "/prometheus/scrape_configs/" ]; then
mkdir -p /prometheus/scrape_configs/
fi
cd /prometheus/scrape_configs/ || exit 1
if [ ! -f "$name.yml" ]; then
echo -e "- targets:\n - '$domain'" > "$name.yml"
else
echo " - '$domain'" >> "$name.yml"
fi
}