diff --git a/config.py b/config.py index 26afbdd..b1a65d7 100644 --- a/config.py +++ b/config.py @@ -2,9 +2,9 @@ # See README before changing any of these options. -hostMonitoringPeriod = 15 +hostMonitoringPeriod = 1 urlMonitoringPeriod = 60 -urls = ["https://1.1.1.1"] +urls = ["https://one.one.one.one"] urlTimeout = 10 maxWorkers = 4 forceNonPOSIXCPU = True @@ -15,3 +15,7 @@ sqlUsername = '' sqlPassword = '' logRetentionDays = 90 maximumSQLAttempts = 3 +hostMonitorStartTime = "00:00:00" +hostMonitorEndTime = "23:59:59" +urlMonitorStartTime = "00:00:00" +urlMonitorEndTime = "23:59:59" diff --git a/main.py b/main.py index 652736a..33f59a4 100755 --- a/main.py +++ b/main.py @@ -90,9 +90,12 @@ def getNonPOSIXCPUAverage(): def monitorHost(stop_event): + while time.strftime("%H:%M:%S") <= config.hostMonitorStartTime: + time.sleep(1) # This block is important to ensure the thread sleeps until the start time is reached. Else the thread wont start if the script is started before the start time + nonPOSIXCPUStarted = False - while not stop_event.is_set(): + while not (stop_event.is_set()) and (time.strftime("%H:%M:%S") >= config.hostMonitorStartTime and time.strftime("%H:%M:%S") <= config.hostMonitorEndTime): if os.name != 'posix' or config.forceNonPOSIXCPU: @@ -120,7 +123,10 @@ def monitorHost(stop_event): def monitorUrls(stop_event): - while not stop_event.is_set(): + while time.strftime("%H:%M:%S") <= config.urlMonitorStartTime: + time.sleep(1) # This block is important to ensure the thread sleeps until the start time is reached. Else the thread wont start if the script is started before the start time + + while not (stop_event.is_set()) and (time.strftime("%H:%M:%S") >= config.urlMonitorStartTime and time.strftime("%H:%M:%S") <= config.urlMonitorEndTime): for url in config.urls: @@ -167,6 +173,7 @@ def logHostLog(hostname, logTime, cpu, memory): def logURLLog(hostname, logTime, url, responseTime): if not config.loggingMode == 'none': + manager = logsManager(config.sqlServer, config.sqlDatabase, config.sqlUsername, config.sqlPassword) manager.insertURLLog(hostname, socket.gethostbyname(socket.gethostname()), logTime, url, responseTime)