node_exporter: Add verbose option

This commit is contained in:
Timo Makinen 2025-04-04 05:46:33 +00:00
parent b6bceb64a4
commit 56ed9010ac

View file

@ -6,19 +6,35 @@ umask 022
PATH="/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin"
if [ "${1:-}" = "-v" ]; then
shift
VERBOSE=true
else
VERBOSE=false
fi
if [ -n "${1:-}" ]; then
echo "Usage: $(basename "$0") [-v]" 1>&2
exit 1
fi
if [ "$(uname -s)" = "OpenBSD" ]; then
OUTDIR="/var/db/node-exporter"
else
OUTDIR="/var/lib/prometheus/node-exporter"
fi
"$VERBOSE" && echo "Using output directory '${OUTDIR}'"
for script in /usr/local/libexec/node-exporter/*; do
[ -x "$script" ] || continue
"$VERBOSE" && echo "Processing script '${script}'"
target="${OUTDIR}/$(basename "$script")"
tmpfile="$(mktemp -p "$OUTDIR")"
if "$script" > "$tmpfile" ; then
"$VERBOSE" && echo " Success, updating stats"
mv "$tmpfile" "$target"
else
"$VERBOSE" && echo " Failure, skipping stats update"
rm -f "$tmpfile"
fi
done