From 7c2430803998be47b6c8dc3ebf02badb22aa1a29 Mon Sep 17 00:00:00 2001 From: Ray Miller Date: Wed, 23 Oct 2024 10:50:59 +0100 Subject: [PATCH] Ruff format --- aws/cloudwatch-log-costs.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/aws/cloudwatch-log-costs.py b/aws/cloudwatch-log-costs.py index 9c23576..aa6e3f1 100755 --- a/aws/cloudwatch-log-costs.py +++ b/aws/cloudwatch-log-costs.py @@ -29,16 +29,16 @@ for page in paginator.paginate(Namespace="AWS/Logs", MetricName="IncomingBytes") "Metric": { "Namespace": metric["Namespace"], "MetricName": metric["MetricName"], - "Dimensions": metric["Dimensions"] + "Dimensions": metric["Dimensions"], }, "Period": int(period.total_seconds()), - "Stat": "Sum" + "Stat": "Sum", }, } if not metric["Dimensions"]: continue query_names[f"q{n}"] = metric["Dimensions"][0]["Value"] - n = n+1 + n = n + 1 queries.append(query) @@ -47,10 +47,17 @@ for page in paginator.paginate(Namespace="AWS/Logs", MetricName="IncomingBytes") # otherwise we would have to chunk up the calls to GetMetricData. results = [] data_paginator = cw.get_paginator("get_metric_data") -for data_page in data_paginator.paginate(MetricDataQueries=queries, StartTime=start_time, EndTime=end_time): +for data_page in data_paginator.paginate( + MetricDataQueries=queries, StartTime=start_time, EndTime=end_time +): for result in data_page["MetricDataResults"]: if result["Values"]: - results.append({"LogGroup": query_names[result["Id"]], "IncomingBytes": result["Values"][0]}) + results.append( + { + "LogGroup": query_names[result["Id"]], + "IncomingBytes": result["Values"][0], + } + ) results.sort(key=lambda x: x["IncomingBytes"], reverse=True) @@ -62,6 +69,6 @@ for result in results: # CloudWatch logs: 5GiB free ingestion then $0.50 / GiB # Estimate a monthly cost by doubling the incoming_bytes counted over the last 14 days -incoming_gb = 2*incoming_bytes_total/(1024*1024*1024) +incoming_gb = 2 * incoming_bytes_total / (1024 * 1024 * 1024) cost = (incoming_gb - 5.0) * 0.5 print(f"Estimated monthly cost: ${cost:.2f}")