Commit 657f9447 authored by Łukasz Nowak's avatar Łukasz Nowak Committed by Rafael Monnerat

Fix/slapos node collect utc

/reviewed-on !147
parent 2baa2125
......@@ -29,7 +29,7 @@
from __future__ import print_function
from psutil import process_iter, NoSuchProcess, AccessDenied
from time import strftime
from time import strftime, gmtime
import shutil
import datetime
from slapos.collect.db import Database
......@@ -46,7 +46,7 @@ from slapos.collect.reporter import RawCSVDumper, \
from .entity import get_user_list, Computer
def _get_time():
return strftime("%Y-%m-%d -- %H:%M:%S").split(" -- ")
return strftime("%Y-%m-%d -- %H:%M:%S", gmtime()).split(" -- ")
def build_snapshot(proc):
try:
......@@ -144,10 +144,10 @@ def do_collect(conf):
database=database,
location=consumption_report_directory)
base = datetime.datetime.today()
base = datetime.datetime.utcnow().date()
for x in range(1, 3):
report_file = consumption_report.buildXMLReport(
(base - datetime.timedelta(days=x)).strftime("%Y-%m-%d"))
(base - datetime.timedelta(days=x)).strftime("%Y-%m-%d"), gmtime())
if report_file is not None:
shutil.copy(report_file, xml_report_directory)
......
......@@ -28,7 +28,7 @@
##############################################################################
import os
from time import strftime
from time import strftime, gmtime
import datetime
from slapos.util import sqlite_connect
......@@ -162,7 +162,7 @@ class Database:
self.close()
def _getInsertionDateTuple(self):
return strftime("%Y-%m-d -- %H:%M:%S").split(" -- ")
return strftime("%Y-%m-d -- %H:%M:%S", gmtime()).split(" -- ")
###################
# Insertion methods
......@@ -252,7 +252,7 @@ class Database:
def _getGarbageCollectionDateList(self, days_to_preserve=3):
""" Return the list of dates to Preserve when data collect
"""
base = datetime.datetime.today()
base = datetime.datetime.utcnow().date()
date_list = []
for x in range(0, days_to_preserve):
date_list.append((base - datetime.timedelta(days=x)).strftime("%Y-%m-%d"))
......@@ -419,7 +419,7 @@ class Database:
select_sql = "SELECT date, time FROM heating ORDER BY date, time DESC LIMIT 1"
for __date, __time in self._execute(select_sql):
_date = datetime.datetime.strptime("%s %s" % (__date, __time), "%Y-%m-%d %H:%M:%S")
return datetime.datetime.now() - _date
return datetime.datetime.utcnow() - _date
return datetime.timedelta(weeks=520)
def getLastZeroEmissionRatio(self):
......
......@@ -79,7 +79,7 @@ class User(object):
where="partition='%s'" % self.name):
latest_date = datetime.strptime('%s %s' % date_time,
"%Y-%m-%d %H:%M:%S")
if (datetime.now() - latest_date).seconds < time_cycle:
if (datetime.utcnow() - latest_date).seconds < time_cycle:
# wait the time cycle
return
break
......
......@@ -59,7 +59,7 @@ class SystemReporter(Dumper):
def dump(self, folder):
""" Dump data """
_date = time.strftime("%Y-%m-%d")
_date = time.strftime("%Y-%m-%d", time.gmtime())
self.db.connect()
for item, collected_item_list in six.iteritems(self.db.exportSystemAsDict(_date)):
self.writeFile(item, folder, collected_item_list)
......@@ -94,7 +94,7 @@ class RawDumper(Dumper):
""" Dump raw data in a certain format
"""
def dump(self, folder):
date = time.strftime("%Y-%m-%d")
date = time.strftime("%Y-%m-%d", time.gmtime())
self.db.connect()
table_list = self.db.getTableList()
for date_scope, amount in self.db.getDateScopeList(ignore_date=date):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment