#!/bin/sh set -eu 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