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