Skip to content

Commit c02b15e

Browse files
authored
[directory-size.sh] Support spaces in paths (#239)
The current code emits directory label only up to the first space, due to the default behavior of `awk`. This change pulls in the rest of the line output from `du` into the label, so directories containing spaces are properly captured --------- Signed-off-by: Andrew Roberts <adroberts@gmail.com>
1 parent fcfb2e6 commit c02b15e

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

directory-size.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@
1111
echo "# HELP node_directory_size_bytes Disk space used by some directories"
1212
echo "# TYPE node_directory_size_bytes gauge"
1313
du --block-size=1 --summarize "$@" \
14-
| awk '{ print "node_directory_size_bytes{directory=\"" $2 "\"} " $1 }'
14+
| sed -E \
15+
-e 's/\\/\\\\/g' \
16+
-e 's/"/\\"/g' \
17+
-e 's/^([0-9]+)[[:blank:]](.+)$/node_directory_size_bytes{directory="\2"} \1/'

0 commit comments

Comments
 (0)