I am trying to count the number of listening ports of my java application that is running on RHEL server. To do so, I created the following config file:
commands = ["/bin/bash -c ‘netstat -ltp | grep java | wc -l’"]
timeout = “5s”
name_override = “listen_ports”
data_format = “value”
data_type = “integer”
However, this config file does not work as expected because of the grep command, I strongly believe. I think in that way because if I remove “grep java” part of the command, then the command starts to work as it should and send the output to InfluxDB. However, it always sends zero (0i) when “grep” is included. I have confirmed this by having the output written to a file on disk using outputs.file plugin.
I have tried to;
-Give the full paths to the commands, i.e., instead of grep, I tried /bin/grep.
-Use “grep -c java” instead of “grep java | wc -l”.
-Create a bash script and call the script instead of entering the command in the config file.
None of the above has helped at all. It always sends the output of 0.
Telegraf version installed on the machine is 1.19.2.
Has anyone ever experienced this issue with grep command before?