-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added request metrics to gain request stats from log file
- Loading branch information
1 parent
75622e7
commit e4d2cb8
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
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
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() | ||
|