VMware vSphere

 View Only
  • 1.  VM uptime

    Posted Nov 27, 2017 02:15 PM

    HI,

    kindly suggest me a command in which it could check the vm uptime through putty in vmware 6.0

    Thanks,

    shankar.p



  • 2.  RE: VM uptime

    Posted Nov 27, 2017 02:32 PM

    Why would you need Putty?

    You can do this via PowerCLI, something like this

    $stat = 'sys.osuptime.latest'

    $entity = Get-VM

    Get-Stat -Entity $entity -Stat $stat -Realtime -MaxSamples 1 -ErrorAction SilentlyContinue |

    Select @{N='VM';E={$_.Entity.Name}},

        @{N='Uptime (d.hh:mm:ss)';E={[timespan]::FromSeconds($_.value)}}



  • 3.  RE: VM uptime

    Posted Nov 27, 2017 02:41 PM

    Thanks for your update,

    we already running some script in putty we thought to add up-time in the same script



  • 4.  RE: VM uptime

    Posted Nov 27, 2017 03:03 PM

    I'm making the assumption that you're using putty to script Linux.

    You can use the uptime command:

    ~ # uptime

    09:52am  up 9 days 13:04,  1 user,  load average: 0.89, 0.73, 0.56

    If you just want the days and hours, use this:

    ~# uptime | sed 's/.*up \([^,]*\), .*/\1/'

    9 days 13:05

    If putting in a bash script you can set the output to a variable to use later:

    uptime="$(uptime | sed 's/.*up \([^,]*\), .*/\1/')"

    echo $uptime



  • 5.  RE: VM uptime

    Posted Nov 28, 2017 05:02 AM

    Thanks,

    but it shows only host update time  I need vm uptime



  • 6.  RE: VM uptime

    Posted Nov 28, 2017 05:54 AM

    OK, so you're using putty to connect to the ESXi host and then you want to run a command line option from the ESXi host shell to enumerate a specific VM's uptime?

    You'll have to do some tinkering to script it further, but you could get it with this

    [root@hwlesxi07:/bin] vim-cmd vmsvc/getallvms | grep hwlvra7201

    320    hwlvra7201                                                                         [NFS-01] hwlvra7201/hwlvra7201.vmx                                                                                                                                               sles11_64Guest          vmx-07    VMware vRealize Automation enables customized, self-service provisioning and lifecycle management of cloud services that comply with established business policies.                                                                                                                                                                                                                                                                                                                                                                                            

    [root@hwlesxi07:/bin] vim-cmd vmsvc/get.runtime 320 | grep bootTime

       bootTime = "2017-11-17T19:51:37.503343Z",

    You would have to parse the vmID from the first command ("320" in the example) and use it in the second command.  Parse the boot time value and subtract it from todays date to get total uptime.

    I don't know of any way to get a scalar value for uptime (i.e. seconds, days, etc.) of a VM from the host command line unless I missed a value somewhere in the vim-cmd vmsvc/ namespace.  You can play with the commands in there to see what might be of value to you.



  • 7.  RE: VM uptime

    Posted Nov 27, 2017 05:47 PM

    Then I guess your thread shouldn't be in the PowerCLI Community.

    Shall I move it?