Inputs.exec error

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

Script i’m running:

#!/bin/bash

#echo "["
#du -ks "$@" | awk '{if (NR!=1) {printf ",\n"};printf "  { \"directory_size_kilobytes\": "$1", \"path\": \""$2"\" }";}'
#echo
#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
echo "]"
[[inputs.exec]]
#   ## Commands array
   commands = [ "/usr/local/bin/metrics-exec_du.sh /opt/veeam/veeam1","sudo du -hx /opt/veeam/prd_veeam-gwy_01" ]
#     "/tmp/test.sh",
#     "/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:
#   ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
   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: host=prdxpromapp01.panerabread.com
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/github.com/awslabs/kinesis-aggregation/@v/v0.0.0-20211222152315-953b66f67407.zip" }
]

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/github.com/awslabs/kinesis-aggregation/@v/v0.0.0-20211222152315-953b66f67407.zip" }
]

Give that a shot and let us know.