jeyakarthika
Contributor
Contributor

Esx Server Host current time wrong when server reboot

Hi,

I wrote a code to get Esx server uptime using VISDK. My code connected to virtual center and collect the boot time (using runtime.bootTime) and the current time (using queryDateTime) for all the Esx servers which are in vc and calculate the uptime using the following

computation.

Esx_server_uptime = Esx_server_current_time - Esx_server_boottime

This ll works fine upto the Esxserver reboots.Once the Esx server is rebooted the Esx_server_current_time is less than the Esx_server_boottime.Esx_server_current_time is not updated.My code also calling refreshDateTimeSystem method to refresh DateTime related settings.i am getting correct Esx_server_current_time only after 30 minutes of the reboot.What is the reason this 30 mins delay how to resolve this?My code is running continuously for every 5 minutes. I need to get the correct Esx_server_current_time as soon as the server reboots.how to get this?

String[][] typeInfo = new String[][] { new String[] { "HostSystem", "name",

"runtime.connectionState","configManager.dateTimeSystem","runtime.bootTime"}};

ObjectContent[] ocary = getContentsRecursively(null, null, typeInfo, true);

if (ocary == null || ocary.length == 0)

{

return null;

}

DynamicProperty[] propary = null;

for(int jj=0; jj<ocary.length ; jj++)

{

propary = ocary[jj].getPropSet();

String hostname = "";

String hostStatus = "";

long bootTime = 0;

long currentEsxTime = 0;

if(propary==null )

{

continue;

}

int len =propary.length;

Hashtable refs = new Hashtable();

for(int jk=0;jk<len;jk++)

{

String propName = propary[jk].getName();

ArrayList al2 = (ArrayList) refs.get(propName);

if (al2 == null)

al2 = new ArrayList();

Object o = (Object) propary[jk].getVal();

al2.add(o);

refs.put(propName, al2);

}

if (refs == null || refs.size() == 0)

continue;

if (refs.containsKey("runtime.bootTime"))

{

ArrayList arr = (ArrayList)refs.get("runtime.bootTime");

Calendar cal_temp = (Calendar)arr.get(0);

Date dt_temp = cal_temp.getTime();

bootTime = dt_temp.getTime();

}

if (refs.containsKey("runtime.connectionState"))

{

ArrayList arr = (ArrayList)refs.get("runtime.connectionState");

HostSystemConnectionState connState = (HostSystemConnectionState)arr.get(0);

if (connState!=null)

{

hostStatus =""+connState;

}

}

if (refs.containsKey("name"))

{

ArrayList ar1 = (ArrayList)refs.get("name");

hostname = (String)ar1.get(0);

}

lastRunTime = System.currentTimeMillis();

if(hostStatus.equalsIgnoreCase("connected") )

{

if (refs.containsKey("configManager.dateTimeSystem"))

{

ArrayList arr = (ArrayList)refs.get("configManager.dateTimeSystem");

ManagedObjectReference dateTimeInfoRef = (ManagedObjectReference) arr.get(0);

if (dateTimeInfoRef != null && getService() != null)

{

lastRunTime = System.currentTimeMillis();

Calendar cal_temp = getService().queryDateTime(dateTimeInfoRef);

lastRunTime = System.currentTimeMillis();

if (cal_temp != null)

{

Date dt_temp = cal_temp.getTime();

currentEsxTime = dt_temp.getTime();

}

}

else

currentEsxTime = System.currentTimeMillis();

}

else

currentEsxTime = System.currentTimeMillis();

}

else

currentEsxTime = System.currentTimeMillis();

Long l_hostUptime = currentEsxTime - bootTime;

ht_HostUptimeDt.put(hostname,new Long(l_hostUptime));

}

Thanks,

karthika

0 Kudos
3 Replies
admin
Immortal
Immortal

Hi,

We tries to perform the same at our end with VC 4.0.0 Build 162856 and on ESX 4.0.0 Build-181768, the operation was successful with bootTime < currentTime.

As per our observation:

Current time just before reboot -"2009-12-30T13:21:34.012887Z"

Reboot time - "2009-12-30T13:32:55.441224Z"

Current time after the reboot - "2009-12-30T13:33:22.98555Z"

You can also cross check the same using the MOB, http://<serverIP>/mob and check if you still get the incorrect value for the bootTime property.

Hope this helps.

0 Kudos
jeyakarthika
Contributor
Contributor

Hi,

Thanks for ur reply.

when i connect Esxi server 4.0.0 directly i did not found this issue.

When i connect the Esx server 4.0.0 through vc the issue occurs.

In my environment we have virtual center 4.0.0 build 208111 and Esx server 4.0.0 build 208167 .

Is this the issue because of the build change?

Thanks,

karthika

0 Kudos
admin
Immortal
Immortal

Hi,

We performed the same at our end with VC 4.0.0 Build 208111 and on ESX 4.0.0 Build 208167, the operation was still successful with bootTime < currentTime.

As per our observation:

Boot time of server before restart - "2010-01-04T13:45:28.77104Z"

Current time of server before restart - "2010-01-05T03:33:42.609466Z"

Boot time of server after restart - "2010-01-05T03:37:04.841581Z"

Current time of server after restart - "2010-01-05T03:44:35.842526Z"

We are using MOB, http://<VCserverIP>/mob

host.configManager.dateTimeSystem.QueryDateTime => for current time of the system.

host.runtime.bootTime => for boot time of the system

You may also cross check the VCenter serverclock (using currentTime) and ESX host current time are in sync or not and take your observations accordingly.

0 Kudos