Skip to content

Commit

Permalink
add sample directory size exporter (prometheus#789)
Browse files Browse the repository at this point in the history
* add sample directory size exporter

This is a possible workaround for the lack of metrics in the new
storage backend, as documented in:

prometheus/prometheus#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
  • Loading branch information
anarcat authored and oblitorum committed Apr 9, 2024
1 parent 077e3f8 commit e45ce35
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions text_collector_examples/directory-size.sh
Original file line number Diff line number Diff line change
@@ -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é <[email protected]>
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'

0 comments on commit e45ce35

Please sign in to comment.