Inputs.exec error

I am trying to monitor an NFS mount with the inputs.exec plugin.

Script i’m running:


#echo "["
#du -ks "$@" | awk '{if (NR!=1) {printf ",\n"};printf "  { \"directory_size_kilobytes\": "$1", \"path\": \""$2"\" }";}'
#echo "]"

#du -bs "$@" | awk '{if (NR!=1) {printf ",\n"};printf "  { \"directory_size_megabytes\": "$1", \"path\": \""$2"\" }";}'
#du -bs "${1}" | awk '{print "[ { \"bytes\": "$1", \"dudir\": \""$2"\" } ]";}'
echo "["
sudo find "$@" -xdev -type f -size +100M -exec du -sh {} ';' | sort -rh | head -n5 | awk '{if (NR!=1) {printf ",\n"};printf " { \"big_file_size\": "$1", \"path\": \""$2"\" }";}'
echo "]"
#   ## Commands array
   commands = [ "/usr/local/bin/ /opt/veeam/veeam1","sudo du -hx /opt/veeam/prd_veeam-gwy_01" ]
#     "/tmp/",
#     "/usr/bin/mycollector --foo=bar",
#     "/tmp/collect_*.sh"
#   ]
#   ## Timeout for each command to complete.
   timeout = "30s"
   name_override = "du"
#   ## measurement name suffix (for separating different commands)
   name_suffix = "_du"
#   ## Data format to consume.
#   ## Each data format has its own unique set of configuration options, read
#   ## more about them here:
#   ##
   data_format = "json"
   tag_keys = [ "filesize" ]

I am getting the following error:

telegraf --debug --config /etc/telegraf/telegraf.conf --input-filter exec --test
2022-05-25T17:41:17Z E! Unable to open /var/log/telegraf/telegraf.log (open /var/log/telegraf/telegraf.log: permission denied), using stderr
2022-05-25T17:41:17Z I! Starting Telegraf 1.22.1
2022-05-25T17:41:17Z I! Loaded inputs: exec
2022-05-25T17:41:17Z I! Loaded aggregators:
2022-05-25T17:41:17Z I! Loaded processors:
2022-05-25T17:41:17Z W! Outputs are not used in testing mode!
2022-05-25T17:41:17Z I! Tags enabled:
2022-05-25T17:41:17Z D! [agent] Initializing plugins
2022-05-25T17:41:17Z D! [agent] Starting service inputs
2022-05-25T17:41:21Z E! [inputs.exec] Error in plugin: invalid character 'T' after top-level value
2022-05-25T17:41:36Z E! [inputs.exec] Error in plugin: invalid character 'T' after object key:value pair
2022-05-25T17:41:36Z D! [agent] Stopping service inputs
2022-05-25T17:41:36Z D! [agent] Input channel closed
2022-05-25T17:41:36Z D! [agent] Stopped Successfully
2022-05-25T17:41:36Z E! [telegraf] Error running agent: input plugins recorded 2 errors

Can you run the script and provide the output?

If I run your script I believe you get JSON that looks like this:

 { "big_file_size": 286M, "path": "./go/pkg/mod/cache/download/" }

The value of big_file_size is not valid json. That is a string and as a result should be quoted. My suggestion is to report the file size in some standard units like bytes by dropping the -h in the du command. Then you should get something like:

 { "big_file_size": 292684, "path": "./go/pkg/mod/cache/download/" }

Give that a shot and let us know.