Skip to content

Instantly share code, notes, and snippets.

@nathan-sixnines
Created July 1, 2019 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathan-sixnines/f6a9681c9310dbc7e4f0fc28438fdde4 to your computer and use it in GitHub Desktop.
Save nathan-sixnines/f6a9681c9310dbc7e4f0fc28438fdde4 to your computer and use it in GitHub Desktop.
import sys
import string
import matplotlib.dates as mdates
#lines, warnings, errors
timeBuckets = [[],[],[]]
hoursList = []
with open(sys.argv[1]) as f:
for line in f:
if(len(line) >= 20):
if(line[13] ==':' and line[16] == ':'):
#print('true')
hours = int(line[11:13])
#print(hours)
mins = int(line[14:16])
#print(mins)
secs = int(line[17:19])
#print(secs)
hoursList.append(hours)
daySecs = secs + mins*60 + hours*60*60
timeBuckets[0].append(daySecs)
if('warning' in line.lower()):
timeBuckets[1].append(daySecs)
if('error' in line.lower()):
timeBuckets[2].append(daySecs)
#print(timeBuckets)
#https://towardsdatascience.com/histograms-and-density-plots-in-python-f6bda88f5ac0
#print(max(timeBuckets[0]))
#print(max(hoursList))
import matplotlib.pyplot as plt
import seaborn as sns
"""
# List of five airlines to plot
messages = ['events','warnings','errors']
# Iterate through the five airlines
for i, line in enumerate(messages):
# Subset to the airline
# Draw the density plot
sns.distplot(timeBuckets[i], hist = False, kde = True,
kde_kws = {'linewidth': 3},
label = messages)
# Plot formatting
plt.legend(prop={'size': 16}, title = 'log events')
plt.title('Density Plot of log')
plt.xlabel('time')
plt.ylabel('Density')
"""
colors = ['blue','yellow','red']
names = ['messages','warnings','errors']
for i in range(0,3):
plt.hist(timeBuckets[i], bins = int(200), log = True, range = [0,86400],
color = colors[i], label=names[i])
# matplotlib histogram
#plt.hist(timeBuckets[0], color = 'blue', edgecolor = 'black',
# bins = int(86400/100))
"""
# seaborn histogram
sns.distplot(timeBuckets[0], hist=True, kde=False,
bins=int(86400/100), color = 'blue',
hist_kws={'edgecolor':'black'})
"""
# Add labels
plt.title('Histogram of Log Events')
plt.xlabel('Time')
plt.ylabel('Events')
plt.savefig("density-of-logs%s" % i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment