From 79ae03c4c7315eeebab360bceb6ac16722265418 Mon Sep 17 00:00:00 2001 From: anarcat Date: Wed, 21 Feb 2018 10:24:48 -0500 Subject: [PATCH] add sample directory size exporter (#789) * add sample directory size exporter This is a possible workaround for the lack of metrics in the new storage backend, as documented in: https://github.com/prometheus/prometheus/issues/3684 Partly inspired by this post as well: https://www.robustperception.io/monitoring-directory-sizes-with-the-textfile-collector/ * properly escape backslashes and double-quotes --- text_collector_examples/directory-size.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 text_collector_examples/directory-size.sh diff --git a/text_collector_examples/directory-size.sh b/text_collector_examples/directory-size.sh new file mode 100755 index 00000000..2c15402f --- /dev/null +++ b/text_collector_examples/directory-size.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Expose directory usage metrics, passed as an argument. +# +# Usage: add this to crontab: +# +# */5 * * * * prometheus directory-size.sh /var/lib/prometheus | sponge /var/lib/node_exporter/directory_size.prom +# +# sed pattern taken from https://www.robustperception.io/monitoring-directory-sizes-with-the-textfile-collector/ +# +# Author: Antoine Beaupré +echo "# HELP anarcat_dir_space_bytes Disk space used by some directories" +echo "# TYPE anarcat_dir_space_bytes gauge" +du --block-size=1 --summarize "$@" \ + | sed -ne 's/\\/\\\\/;s/"/\\"/g;s/^\([0-9]\+\)\t\(.*\)$/node_directory_size_bytes{directory="\2"} \1/p'