Last active
January 17, 2025 02:02
-
-
Save 1stvamp/07d7203425cb0f542c6c8f10437552c0 to your computer and use it in GitHub Desktop.
Parse Cloud66 server deployment logs for times taken
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
#!/usr/bin/env python3 | |
from sys import argv, exit | |
from os.path import dirname | |
from datetime import datetime | |
from pprint import pprint | |
if len(argv) == 1 or argv[1] in ('-h', '--help'): | |
print('USAGE: parse_deploy_log.py LOG_FILE [NUMBER_OF_TOP_TIMES]') | |
exit(1) | |
times = {} | |
with open(argv[1]) as f: | |
last_ts = None | |
last_action = None | |
date = '01-01-1970 ' | |
twentythree = False | |
format = '%d-%m-%Y %H:%M:%S:%f' | |
for i, line in enumerate(f): | |
if i == 0: | |
if line.startswith('23'): | |
twentythree = True | |
last_ts = datetime.strptime(date + line.strip(), format).timestamp() | |
elif i % 2 == 0: | |
if twentythree and line.startswith('0'): | |
date = '02-01-1970 ' | |
ts = datetime.strptime(date + line.strip(), format).timestamp() | |
times[last_action] = ts - last_ts | |
last_ts = ts | |
else: | |
last_action = line.strip() | |
print('Total: {}'.format(sum(times.values()))) | |
print('Top times:') | |
pprint(sorted(times.items(), key=lambda x:x[1], reverse=True)[:int((argv[2:3] or [10])[0])]) |
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
Total: 213.0039999999999 | |
Top times: | |
[('Executing health check command: /usr/bin/curl -kLs -o /dev/null -w ' | |
'"%{http_code}" --connect-timeout 60 --max-time 60 ' | |
'https://localhost/healthcheck', | |
40.11700000000019), | |
('Retrieving code by revision: 70c7b447477bc0bef5a4d696f0a1b030c047bdcf', | |
33.15000000000009), | |
('Applying NGINX configuration (deployment)', 16.239000000000033), | |
('warning " > [email protected]" has unmet peer dependency "@types/node@>=18".', | |
14.333999999999833), | |
('Executing: bundle install --gemfile ' | |
'/var/deploy/pinpoint_staging/web_head_wlozpiht/releases/20250115012501/Gemfile ' | |
'--quiet', | |
12.162000000000035), | |
('Checking out source code on server', 9.876999999999953), | |
('Revision: 70c7b447477bc0bef5a4d696f0a1b030c047bdcf', 9.86200000000008), | |
('Deploying logrotate configuration', 9.09199999999987), | |
('Preparing Cloud 66 profiles on the server', 7.069999999999936), | |
('Waiting for dependencies to finish', 6.045000000000073)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment