#!/bin/sh # Einzeldaten und Summen von nodes.json sowie Verbindungsdaten aus graph.json # als labeled metrics fuer prometheus ME="`basename $0`" PROMDIR=%%EXPORT_DIR%% [ -d $PROMDIR -a -w $PROMDIR ] || PROMDIR=/tmp NODES_PROM=$PROMDIR/%%PROM_PREFIX%%.prom NODES_URL="%%NODES_URL%%" NODES_FILE=/tmp/nodes.json.$$ NODES2PROM=%%BIN_DIR%%/nodes2prom [ -f $NODES2PROM -a -x $NODES2PROM ] || NODES2PROM=./nodes2prom GRAPH_PROM=$PROMDIR/%%PROM_GRAPH_PREFIX%%.prom GRAPH_URL="%%GRAPH_URL%%" GRAPH_FILE=/tmp/graph.json.$$ GRAPH2PROM=%%BIN_DIR%%/graph2prom [ -f $GRAPH2PROM -a -x $GRAPH2PROM ] || GRAPH2PROM=./graph2prom result=0 if timeout -s HUP -k 2 50 \ %%FETCH_CMD%% $NODES_FILE "$NODES_URL" then $NODES2PROM $NODES_FILE > $NODES_PROM.new && \ mv $NODES_PROM.new $NODES_PROM rm -f $NODES_FILE else logger -t "$ME" "failed to fetch $NODES_URL" rm -f $NODES_FILE result=1 fi if timeout -s HUP -k 2 50 \ %%FETCH_CMD%% $GRAPH_FILE "$GRAPH_URL" then $GRAPH2PROM $GRAPH_FILE > $GRAPH_PROM.new && \ mv $GRAPH_PROM.new $GRAPH_PROM rm -f $GRAPH_FILE else logger -t "$ME" "failed to fetch $GRAPH_URL" rm -f $GRAPH_FILE result=1 fi return $result