-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example on how to update prometheus targets
Updates a target list in the format expected by file_sd_config[0] every 20 seconds. [0]: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#file_sd_config
- Loading branch information
Linus Wallgren
committed
Dec 9, 2019
1 parent
8f4561f
commit 8d478f3
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Update the prometheus static file config based off of PushProx | ||
|
||
[Service] | ||
User=pushprox-updater | ||
Group=pushprox-updater | ||
|
||
EnvironmentFile=-/etc/default/pushprox-updater | ||
ExecStart=/usr/bin/pushprox-updater | ||
|
||
NoNewPrivileges=true | ||
PrivateTmp=yes | ||
PrivateDevices=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=Update the prometheus static file config based off of PushProx | ||
|
||
[Timer] | ||
OnStartupSec=20s | ||
OnUnitInactiveSec=20s | ||
|
||
[Install] | ||
WantedBy=timers.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
host=${PUSHPROX_HOST:-localhost:8080} | ||
ports=${PUSHPROXY_PORTS:-9100} | ||
sd_file=${PUSHPROXY_FILE:-/etc/prometheus/file_sd/clients.json} | ||
|
||
tmpfile=$(mktemp --suffix "pushprox-target-updater") | ||
trap 'rm -f "$tmpfile"' EXIT | ||
|
||
if ! curl -s "$host/clients" | jq --argjson ports "[$ports]" ' | ||
. | map(.targets[0] as $target | { | ||
targets: $ports | map(tostring) | map($target + ":" + .) | ||
})' > "$tmpfile"; then | ||
echo >&2 "Failed to update inventory" | ||
exit 2 | ||
fi | ||
|
||
chmod a+r "$tmpfile" | ||
mv "$tmpfile" "$sd_file" |