nodes2prometheus.sh.in 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. # Einzeldaten und Summen von nodes.json sowie Verbindungsdaten aus graph.json
  3. # als labeled metrics fuer prometheus
  4. ME="`basename $0`"
  5. PROMDIR=%%EXPORT_DIR%%
  6. [ -d $PROMDIR -a -w $PROMDIR ] || PROMDIR=/tmp
  7. NODES_PROM=$PROMDIR/%%PROM_PREFIX%%.prom
  8. NODES_URL="%%NODES_URL%%"
  9. NODES_FILE=/tmp/nodes.json.$$
  10. NODES2PROM=%%BIN_DIR%%/nodes2prom
  11. [ -f $NODES2PROM -a -x $NODES2PROM ] || NODES2PROM=./nodes2prom
  12. GRAPH_PROM=$PROMDIR/%%PROM_GRAPH_PREFIX%%.prom
  13. GRAPH_URL="%%GRAPH_URL%%"
  14. GRAPH_FILE=/tmp/graph.json.$$
  15. GRAPH2PROM=%%BIN_DIR%%/graph2prom
  16. [ -f $GRAPH2PROM -a -x $GRAPH2PROM ] || GRAPH2PROM=./graph2prom
  17. result=0
  18. if timeout -s HUP -k 2 50 \
  19. %%FETCH_CMD%% $NODES_FILE "$NODES_URL"
  20. then
  21. $NODES2PROM $NODES_FILE > $NODES_PROM.new && \
  22. mv $NODES_PROM.new $NODES_PROM
  23. rm -f $NODES_FILE
  24. else
  25. logger -t "$ME" "failed to fetch $NODES_URL"
  26. rm -f $NODES_FILE
  27. result=1
  28. fi
  29. if timeout -s HUP -k 2 50 \
  30. %%FETCH_CMD%% $GRAPH_FILE "$GRAPH_URL"
  31. then
  32. $GRAPH2PROM $GRAPH_FILE > $GRAPH_PROM.new && \
  33. mv $GRAPH_PROM.new $GRAPH_PROM
  34. rm -f $GRAPH_FILE
  35. else
  36. logger -t "$ME" "failed to fetch $GRAPH_URL"
  37. rm -f $GRAPH_FILE
  38. result=1
  39. fi
  40. return $result