I have Jmeter serveragent running with sudo privileges
[sudo ./startAgent.sh --interval 1] on my server where I am trying to collect IO Stats using EXEC metric 
During the jmx run (GUI Mode for verification) the Server Agent throws error as below:
ERROR 2022-02-28 16:01:35.804 [kg.apc.p] (): Problems executing: iostat -d -z
java.io.IOException: Cannot run program "iostat -d -z": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:621)
at java.lang.Runtime.exec(Runtime.java:486)
at kg.apc.perfmon.metrics.ExecMetric.getValue(ExecMetric.java:31)
at kg.apc.perfmon.PerfMonMetricGetter.getMetricsLine(PerfMonMetricGetter.java:113)
at kg.apc.perfmon.PerfMonWorker.processSenders(PerfMonWorker.java:268)
at kg.apc.perfmon.PerfMonWorker.run(PerfMonWorker.java:231)
at java.lang.Thread.run(Thread.java:750)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 7 more
The command works fine from the terminal.

What could be wrong?
Perhaps your terminal has
iostatutility in PATH and the session which is established by JMeter doesn't know where thisiostatutility lives so try usingwhichcommand to determine full path to the utility and amend your PerfMon Metrics collector to use the full path.Also the command needs to exit and to supply single numeric value so you might want to amend the arguments accordingly.
More information: How to Monitor Your Server Health & Performance During a JMeter Load Test