Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bro log lag
#!/usr/bin/env python
import os
import sys
import time
DEFAULT_LOG = "/usr/local/bro/logs/current/conn.log"
def config():
print """
graph_category network
graph_title Bro log lag
graph_vlabel lag
graph_args --base 1000 --vertical-label seconds --lower-limit 0
graph_info The bro log lag
lag.label lag log message lag in seconds
lag.min 0
lag.warning :5000
lag.warning 0:15
lag.critical 0:60
return 0
def get_latest_time(fn):
f = open(fn), os.SEEK_END)
end =[1:-1] #ignore possibly incomplete first and last lines
times = [line.split()[0] for line in end]
timestamps = map(float, times)
latest = max(timestamps)
return latest
def lag(fn):
try :
latest = get_latest_time(fn)
except (IOError, ValueError):
#File could be rotating, wait and try again
latest = get_latest_time(fn)
now = time.time()
lag = now - latest
print "lag.value %f" % lag
if __name__ == "__main__":
filename = os.getenv("BRO_LAG_FILENAME", DEFAULT_LOG)
if sys.argv[1:] and sys.argv[1] == 'config':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment