Skip to content

Commit

Permalink
add timestamp in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
giannisdoukas committed Mar 5, 2020
1 parent 533fb5d commit 23d1fc2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cwlkernel/CWLLogger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
from collections import namedtuple
from datetime import datetime
from typing import NamedTuple, List, Iterator, Dict

import jsonschema
Expand All @@ -15,6 +16,7 @@ class CWLLogger:
def __init__(self, root_directory):
self.process_id = {"process_id": None, "parent_process_id": None}
self._storage_manager = CWLLoggerStorageManager(root_directory)
self._last_to_dict = None

@classmethod
def collect_infrastructure_metrics(cls) -> NamedTuple:
Expand Down Expand Up @@ -43,6 +45,7 @@ def get_hostname(cls) -> str:
return socket.gethostname()

def to_dict(self):
self._last_to_dict = datetime.utcnow().strftime('%Y%b%d%H%M%f')
metrics = self.collect_infrastructure_metrics()._asdict()
for key in ['cpu_metrics', 'vmemory_metrics']:
metrics[key] = {**metrics[key]._asdict()}
Expand All @@ -51,7 +54,7 @@ def to_dict(self):
for key in ['disk_usage']:
metrics[key] = [{m[0]: {**m[1]._asdict()}} for m in metrics[key]]
hostname = self.get_hostname()
return {**metrics, 'hostname': hostname, **{"process_id": self.process_id}}
return {**metrics, 'hostname': hostname, "process_id": self.process_id, 'timestamp': self._last_to_dict}

@classmethod
def get_running_kernels(cls) -> List[int]:
Expand Down

0 comments on commit 23d1fc2

Please sign in to comment.