Skip to content

Instantly share code, notes, and snippets.

@scmmishra
Created December 11, 2023 11:20
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 scmmishra/a6ffdbb62bf0624b23125d587b363a2c to your computer and use it in GitHub Desktop.
Save scmmishra/a6ffdbb62bf0624b23125d587b363a2c to your computer and use it in GitHub Desktop.
Count MutexApplicationJob::LockAcquisitionError in a list of logs
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