Example #1
0
 def test_alert_1(self):
     out = StringIO()
     lock = threading.Lock()
     alarmQueue = deque()
     reqPerSec = 0.5;
     alarmPeriodSec = 5;
     
     thread1 = AlarmThread(reqPerSec, alarmPeriodSec, alarmQueue, lock, out=out)
     thread1.start()        
     
     time.sleep(1)
     
     for _ in range(alarmPeriodSec):
         entry = generateLogEntry()
         lock.acquire()
         alarmQueue.append(entry)
         lock.release()
             
     time.sleep(alarmPeriodSec * 2)
     
     output = out.getvalue()
     lines = output.split('\n')
     
     self.assertTrue("High traffic generated an alert" in lines[0]) 
     self.assertTrue("High traffic alert recovered" in lines[1]) 
Example #2
0
        sys.exit(2)

    logFile = ""
    for o, a in myopts:
        if o == '-i':
            logFile = a

    if (not os.path.exists(logFile)):
        print('Input http-access-log file "%s" does not exist' % (logFile))
        sys.exit(2)

    lock = threading.Lock()
    alarmQueue = deque()
    analyticsQueue = queue.Queue()

    thread1 = AlarmThread(ALARM_REQUESTS_PER_S, ALARM_AVERAGE_PERIOD_S,
                          alarmQueue, lock)
    thread2 = AnalyticsThread(ANALYTICS_UPDATE_S, analyticsQueue, lock)

    thread1.start()
    thread2.start()

    logFile = open(logFile, "r")
    logLines = follow(logFile)
    for line in logLines:
        entry = LogEntry(line)
        lock.acquire()
        analyticsQueue.put(entry)
        alarmQueue.append(entry)
        lock.release()
Example #3
0
        printUsage()
        sys.exit(2)

    logFile = ""
    for o, a in myopts:
        if o == '-i':
            logFile = a

    if (not os.path.exists(logFile)):
        print ('Input http-access-log file "%s" does not exist' % (logFile))
        sys.exit(2)

    lock = threading.Lock()
    alarmQueue = deque()
    analyticsQueue = queue.Queue()

    thread1 = AlarmThread(ALARM_REQUESTS_PER_S, ALARM_AVERAGE_PERIOD_S, alarmQueue, lock)
    thread2 = AnalyticsThread(ANALYTICS_UPDATE_S, analyticsQueue, lock)

    thread1.start()
    thread2.start()

    logFile = open(logFile, "r")
    logLines = follow(logFile)
    for line in logLines:
        entry = LogEntry(line)
        lock.acquire()
        analyticsQueue.put(entry)
        alarmQueue.append(entry)
        lock.release()