Skip to content

Instantly share code, notes, and snippets.

Created October 15, 2013 09:40
Show Gist options
  • Save anonymous/6989149 to your computer and use it in GitHub Desktop.
Save anonymous/6989149 to your computer and use it in GitHub Desktop.
Creates graphs like these: http://i.imgur.com/e81lG8I.png The first one shows how long did one wait between the upgrades, the second – at what hours one upgraded.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
from math import ceil
from matplotlib import pyplot as plt
import re
update_dates = []
with open("/var/log/pacman.log") as input_file:
for line in input_file.readlines():
if re.search("\[PACMAN\] starting full system upgrade", line):
update_dates.append(datetime.strptime(re.search(
"\[[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+\]", line).group(0),
"[%Y-%m-%d %H:%M]"))
update_times = [ dt.time().hour + dt.time().minute/60. for dt in update_dates ]
time_deltas = [ (d1-d0).total_seconds()/(24.*3600)
for d0, d1 in zip(update_dates[:-1], update_dates[1:]) ]
plt.subplot(1, 2, 1)
range_days = ceil(max(time_deltas))
plt.hist(time_deltas, bins=6*range_days, range=[0, range_days]);
plt.xlim([0, range_days]);
plt.xlabel("Time between updates (days)");
plt.ylabel("Number of updates");
plt.subplot(1, 2, 2)
plt.hist(update_times, bins=24, range=[0, 24]);
plt.xlim([0, 24]);
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(4))
plt.xlabel("Local time of update");
plt.ylabel("Number of updates");
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment