evoila / collectsphere

Collectd Plugin for VMware vSphere
MIT License
55 stars 9 forks source link

Timezone aware #18

Closed prjl closed 7 years ago

prjl commented 7 years ago

collectsphere.py isn't really timezone aware. It tries to be with: timestamp += time.localtime().tm_isdst * (3600) but that's not working for me.

I used calendar.timegm() instead of time.mktime() and it works perfectly.

Basically it looks like this

import calendar
...
# Get the timestamp of value. Because of an issue by VMware the
# has to be add an hour if you're at DST
timestamp = float(time.mktime(time.localtime(calendar.timegm(metricsOfEntities[p].sampleInfo[i].timestamp.timetuple()))))
cd_value.time = timestamp

Well after that the comment makes no sense, but it's easier to find...

EDIT: not it actually works... :)

dennis1987 commented 7 years ago

Hi there, I've committed an bug fix for the timezone disaster. This means, from now the metrics will be collected based on the time of the vsphere host. At the parsing time, the timestamps will be converted to the local timezone of the collect host.