Skip to content

Instantly share code, notes, and snippets.

@major
Created February 3, 2017 03:31
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 major/b090eaa865b5e86ec9676610acb6b47f to your computer and use it in GitHub Desktop.
Save major/b090eaa865b5e86ec9676610acb6b47f to your computer and use it in GitHub Desktop.
Gate Recap Parser for OpenStack-Ansible
#!/usr/bin/env python
#
# Usage: ./gate-recap-parser.py console-html-url
#
"""Parse OpenStack-Ansible gate console logs for slow tasks."""
import re
import sys
import requests
def read_console_file(url):
"""Read console data from a downloaded file."""
r = requests.get(url, stream=True)
for line in r.iter_lines():
yield line
regex = r"TASK: (.*)\s-{3,}\s([0-9\.]+)s"
metrics = []
for line in read_console_file(sys.argv[1]):
match = re.findall(regex, line, re.IGNORECASE)
if len(match) > 0:
metrics.append(match[0])
total_time = sum([float(x[1]) for x in metrics])
print("{} TOTAL TIME".format(str(total_time).ljust(8)))
print("-" * 80)
for metric in sorted(metrics, reverse=True, key=lambda x: float(x[1]))[:50]:
report_line = "{:8} {}".format(metric[1], metric[0])
print(report_line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment