Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example script for log processing
- Loading branch information
danielsanchezq
committed
Aug 3, 2020
1 parent
73033c3
commit d835cc1
Showing
1 changed file
with
22 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,22 @@ | ||
import json | ||
|
||
|
||
ELAPSED_TIME_ID = {'Other': 'request_elapsed_time'} | ||
|
||
|
||
def get_data(line: str): | ||
try: | ||
return json.loads(line.split(" ", 2)[-1]) | ||
except json.JSONDecodeError: | ||
return None | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
data_stream = iter(sys.stdin) | ||
jsons = (x for x in map(get_data, data_stream) if x) | ||
elapsed_time_logs = [x for x in jsons if x["id"] == ELAPSED_TIME_ID] | ||
average_request_time = sum( | ||
int(x["metadata"]["elapsed_nano_seconds"]) for x in elapsed_time_logs | ||
)/len(elapsed_time_logs) | ||
print(f"Average request time: {average_request_time}ns") |