2
0
python-capport/stats-to-prometheus-collector.sh

30 lines
563 B
Bash
Executable File

#!/bin/sh
set -e
base=$(dirname "$(readlink -f "$0")")
cd "${base}"
instance=$1
ifname=$2
if [ -z "${instance}" -o -z "${ifname}" ]; then
echo >&2 "Syntax: $0 instancename clientifname"
exit 1
fi
targetname="/var/lib/prometheus/node-exporter/capport-${instance}.prom"
tmpname="${targetname}.$$"
if [ -f "/run/netns/${instance}" ];then
_run_in_ns="/usr/sbin/ns-enter ${instance} -- "
else
_run_in_ns=""
fi
if ${_run_in_ns} ${base}/stats.sh "${ifname}" > "${tmpname}"; then
mv "${tmpname}" "${targetname}"
else
rm "${tmpname}"
exit 1
fi