Last active
August 29, 2015 14:02
-
-
Save xrl/d33e14ba6b447893a183 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LogLine(object): | |
def __init__(self,raw_line): | |
self.pid = pid(raw_line) | |
self.ip = ip(raw_line) | |
self.timestamp = timestamp(raw_line) | |
def pid(self,line): | |
pass | |
def ip(self,line): | |
pass | |
def timestamp(self,line): | |
pass | |
if __name__ == '__main__': | |
PIDS_IN_PROCESSING = {} | |
IP_DURATIONS = [] | |
for line in open("you/file.log"): | |
log_line = LogLine(line) | |
# means it's a CLOSE log line since we have seen it before | |
if log_line.pid in PIDS_IN_PROCESSING: | |
accept_line = PIDS_IN_PROCESSING[log_line.pid] | |
duration = (accept_line.ip,log_line.timestamp - accept_line.timestamp) | |
IP_DURATIONS.append( duration ) | |
delete PIDS_IN_PROCESSING[log_line.pid] | |
# first time we have seen the log line | |
else: | |
PIDS_IN_PROCESSING[log_line.pid] = log_line | |
print IP_DURATIONS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment