If you need to monitor multiple directories I updated the answer by Tw Bert and extended it to allow you to pass them all on one command line. This saves you having to add multiple [[input.exec]]
entries into your telegraf.conf file.
Create the file /etc/telegraf/scripts/disk-usage.sh
containing:
#!/bin/bash
echo "["
du -ks "$@" | awk '{if (NR!=1) {printf ",\n"};printf " { \"directory_size_kilobytes\": "$1", \"path\": \""$2"\" }";}'
echo
echo "]"
I want to monitor two directories: /mnt/user/appdata/influxdb
and /mnt/user/appdata/grafana
. I can do something like this:
# Get disk usage for multiple directories
[[inputs.exec]]
commands = [ "/etc/telegraf/scripts/disk-usage.sh /mnt/user/appdata/influxdb /mnt/user/appdata/grafana" ]
timeout = "5s"
name_override = "du"
name_suffix = ""
data_format = "json"
tag_keys = [ "path" ]
Once you've updated your config, you can test this with:
telegraf --debug --config /etc/telegraf/telegraf.conf --input-filter exec --test
Which should show you what Telegraf will push to influx:
bash-4.3# telegraf --debug --config /etc/telegraf/telegraf.conf --input-filter exec --test
> du,host=SomeHost,path=/mnt/user/appdata/influxdb directory_size_kilobytes=80928 1536297559000000000
> du,host=SomeHost,path=/mnt/user/appdata/grafana directory_size_kilobytes=596 1536297559000000000