I'm trying to run dstat on a remote machine via ssh from my Java program using the sshj library
.
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;
What I need to do is start dstat on the remote machine (Linux), continue with my program to create some load on the remote machine (database server) and stop the dstat
logging after that.
what I have done so far :
connect to server, copy the dstat folder to /tmp/dstat
, make files runnable and then:
session = ssh.startSession();
Command cmd= session.exec("/tmp/BenchIT/rs-sysmon/dstat --noupdate -T -c -m -n -d -r --aio -s -g --vm --fs -i -y -p --disk-util --output /tmp/BenchIT/rs-sysmon/dstat_resultfile.csv 1");
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
cmd.join(5, TimeUnit.SECONDS);
System.out.println("\n** exit status: " + cmd.getExitStatus());
session.close();
so now the problem is, that the dstat
process starts on the remote machine and records into a .csv
file, just as I want it to do, but the Java program waits for the process to finish. so the line after session.exec()
is never reached.
I also tried to run a local script on the remote server just containing the dstat
command, but still my program waits for dstat
to finish, which never happens...
So now my question is: how do I continue with my program while dstat
runs on the remote machine? and when that is achieved, how do I stop dstat
after my program finished what it is supposed to do?
Do I need to run separate threads or something? I really don't know how that works...
(the machine running the code is Linux as well)