Created
December 11, 2023 11:20
-
-
Save scmmishra/a6ffdbb62bf0624b23125d587b363a2c to your computer and use it in GitHub Desktop.
Count MutexApplicationJob::LockAcquisitionError in a list of logs
This file contains 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
import json | |
from collections import defaultdict | |
LEADING = """MutexApplicationJob::LockAcquisitionError: Failed to acquire lock for key: FB_MESSAGE_CREATE_LOCK::""" | |
def get_logs(): | |
f = open('logs.json') | |
return json.load(f) | |
def count_logs(): | |
logs = get_logs() | |
counter = defaultdict(int) | |
for item in logs: | |
message = item['message'] | |
if message.startswith(LEADING): | |
message = message.replace(LEADING, "") | |
counter[message] += 1 | |
return counter | |
if __name__ == "__main__": | |
counts = count_logs() | |
# sort the counts by value, descending | |
sorted_counts = sorted(counts.items(), key=lambda x: x[1], reverse=True) | |
# print the top 10 | |
print(sorted_counts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment