Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 08:39:18

0001 #!/usr/bin/env python
0002 # Licensed under the Apache License, Version 2.0 (the "License");
0003 # you may not use this file except in compliance with the License.
0004 # You may obtain a copy of the License at
0005 # http://www.apache.org/licenses/LICENSE-2.0
0006 #
0007 # Authors:
0008 # - Paul Nilsson, paul.nilsson@cern.ch, 2018
0009 
0010 import time
0011 
0012 
0013 class MonitoringTime(object):
0014     """
0015     A simple class to store the various monitoring task times.
0016     Different monitoring tasks should be executed at different intervals. An object of this class is used to store
0017     the time when a specific monitoring task was last executed. The actual time interval for a given monitoring tasks
0018     is stored in the util/default.cfg file.
0019     """
0020 
0021     def __init__(self):
0022         """
0023         Return the initial MonitoringTime object with the current time as start values.
0024         """
0025 
0026         ct = int(time.time())
0027         self.ct_proxy = ct
0028         self.ct_looping = ct
0029         self.ct_looping_last_touched = None
0030         self.ct_diskspace = ct
0031         self.ct_memory = ct
0032         self.ct_process = ct
0033         self.ct_heartbeat = ct
0034         self.ct_kill = ct
0035 
0036     def update(self, key, modtime=None):
0037         """
0038         Update a given key with the current time or given time.
0039         Usage: mt=MonitoringTime()
0040                mt.update('ct_proxy')
0041 
0042         :param key: name of key (string).
0043         :param modtime: modification time (int).
0044         :return:
0045         """
0046 
0047         ct = int(time.time()) if not modtime else modtime
0048         if hasattr(self, key):
0049             setattr(self, key, ct)
0050 
0051     def get(self, key):
0052         """
0053         Return the value for the given key.
0054         Usage: mt=MonitoringTime()
0055                mt.get('ct_proxy')
0056         The method throws an AttributeError in case of no such key.
0057 
0058         :param key: name of key (string).
0059         :return: key value (int).
0060         """
0061 
0062         return getattr(self, key)