Skip to content

Commit

Permalink
added request metrics to gain request stats from log file
Browse files Browse the repository at this point in the history
  • Loading branch information
superisaac committed Dec 19, 2023
1 parent 75622e7 commit e4d2cb8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions utils/request_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3

import fileinput
import json
from collections import defaultdict

def main():
counts = defaultdict(int)
times = defaultdict(int)
for line in fileinput.input():
entry = json.loads(line)
if entry.get('msg') not in ('call jsonrpc', 'relay http'):
continue
key = (entry['chain'], entry['method'], entry['endpoint'])
counts[key] += 1
times[key] += entry['timeSpentMS']

print('chain', 'method', 'endopint', 'avgtime', 'count')
for key, cnt in sorted(counts.items()):
tm = times[key] # total request time
avg = int(tm/cnt) # average request time
print(key[0], key[1], key[2], avg, cnt)

if __name__ == '__main__':
main()

0 comments on commit e4d2cb8

Please sign in to comment.