I need the command from Javascript,
this is the part of my script
for (var i = 0; i < vmsList.length; i++) {
var vmName = vmsList[i].name;
var state = vmsList[i].state;
var upTime = vmsList[i].xxxxxxxxxx ????
}
please if you can help
Thanks
Hello @jeep2004,
maybe this can help you.
var vms = VcPlugin.getAllVirtualMachines();
vms.forEach( function(vm) {
var runtime = vm.runtime;
var bootTime = runtime.bootTime;
if (bootTime !== null) {
var currentTime = Date.now();
System.log(
vm.name + ": " + bootTime +
" upTime - " + (currentTime - bootTime) / 1000
)
}
});
The bootTime delivers a date about the time when the host was booted. I don't know exactly.
I assume that the difference between the boot time and the current time should provide the uptime.
Best regards
Stefan
You haven't pasted the part of your workflow where you are getting vmlist. But I assume this is an array of VCVM objects. I don't believe uptime is a property of this object. You would need to query the OS to get this info via guest config or some other method
Hello @jeep2004,
maybe this can help you.
var vms = VcPlugin.getAllVirtualMachines();
vms.forEach( function(vm) {
var runtime = vm.runtime;
var bootTime = runtime.bootTime;
if (bootTime !== null) {
var currentTime = Date.now();
System.log(
vm.name + ": " + bootTime +
" upTime - " + (currentTime - bootTime) / 1000
)
}
});
The bootTime delivers a date about the time when the host was booted. I don't know exactly.
I assume that the difference between the boot time and the current time should provide the uptime.
Best regards
Stefan
thank you , its help me
I do some change for me and its works
this is the final for me based on what you wrote
function padWithZero(value) {
return value < 10 ? '0' + value : value.toString();
}
var runtime = vm.runtime;
var bootTime = runtime.bootTime;
if (bootTime !== null) {
var currentTime = Date.now();
var uptimeMinutes = ((currentTime - bootTime) / 1000 / 60).toFixed(2);
var minutes = Math.floor(uptimeMinutes);
var seconds = Math.floor((uptimeMinutes - minutes) * 60);
var formattedMinutes = padWithZero(minutes);
var formattedSeconds = padWithZero(seconds);
var upTime = formattedMinutes +":" + formattedSeconds
System.log(upTime);
}