Created
November 20, 2018 21:47
-
-
Save dovy/9631442906d22b82c4d0e9978fc74038 to your computer and use it in GitHub Desktop.
It's a REAL pain to figure out how to grab the data from Google cloud logging. This script lets you grab historic data and save locally so you can process since Cloud Logging Sync's won't do anything historic.
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
gcloud beta logging read "resource.type=\"dataflow_step\" resource.labels.job_id=\"2018-11-13_09_13_59-6912497806535022683\" OR \"timestamp>=\\\"2018-11-12T00:00:00Z\" OR \"timing:\" timestamp<=\"2200-01-01T00:00:00.000000000Z\" timestamp<\"2018-11-20T20:20:01.065Z\"" --format=json --limit 100000 | jq -rnc --stream 'fromstream(1|truncate_stream(inputs)) | .jsonPayload.message' >> gcs.txt |
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
filename = "gcs.txt" | |
file = open(filename, "r") | |
data = file.read() | |
data = data.replace('\t', '').split("\n---> Method timing:") | |
data = filter(None, data) # fastest | |
results = {} | |
for item in data: | |
item = item.strip().split('\n') | |
for i in item: | |
i = i.split(': ') | |
keys = ['TOTAL', | |
'apply_routing', | |
'apply_scrubbing', | |
'calculate_consumption', | |
'calculate_pricing', | |
'apply_leg_segments', | |
'write_pricing'] | |
if i[0] not in keys: | |
continue | |
if i[0] not in results: | |
results[i[0]] = [] | |
results[i[0]].append(float(i[1])) | |
# print(item) | |
final_results = {} | |
for key, value in results.iteritems(): | |
final_results[key] = round(reduce(lambda x, y: x + y, value) / len(value), 2) | |
final_results['TOTAL_WO_WRITING'] = round(final_results['TOTAL'] - final_results['write_pricing'], 2) | |
from pprint import pprint | |
pprint(final_results) | |
print(len(results['TOTAL'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment