Skip to content

Commit

Permalink
Added example script for log processing
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsanchezq committed Aug 3, 2020
1 parent 73033c3 commit d835cc1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions log-processing-scrips/average_request_response_time.py
@@ -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")

0 comments on commit d835cc1

Please sign in to comment.