From ca7db7f244f25be1704f777078a98708a49e0192 Mon Sep 17 00:00:00 2001 From: Bach Le Date: Fri, 1 Apr 2016 21:13:44 +0800 Subject: [PATCH] Consider timezone when parsing docker's timestamp When the plugin and the docker host is running in different timezones e.g: the plugin runs inside a container with UTC timezone while the host is in some local timezone, the plugin will converts the time string reported by docker into a wrong unix timestamp. --- dockerplugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dockerplugin.py b/dockerplugin.py index 2a9dc04..3a6d8b3 100755 --- a/dockerplugin.py +++ b/dockerplugin.py @@ -25,6 +25,7 @@ import dateutil.parser from distutils.version import StrictVersion +import calendar import docker import os import threading @@ -58,7 +59,7 @@ def emit(cls, container, type, value, t=None, type_instance=None): val.type_instance = type_instance if t: - val.time = time.mktime(dateutil.parser.parse(t).timetuple()) + val.time = calendar.timegm(dateutil.parser.parse(t).utctimetuple()) else: val.time = time.time()