Ruff format
This commit is contained in:
parent
a0edf5d9e9
commit
7c24308039
1 changed files with 13 additions and 6 deletions
|
@ -29,16 +29,16 @@ for page in paginator.paginate(Namespace="AWS/Logs", MetricName="IncomingBytes")
|
||||||
"Metric": {
|
"Metric": {
|
||||||
"Namespace": metric["Namespace"],
|
"Namespace": metric["Namespace"],
|
||||||
"MetricName": metric["MetricName"],
|
"MetricName": metric["MetricName"],
|
||||||
"Dimensions": metric["Dimensions"]
|
"Dimensions": metric["Dimensions"],
|
||||||
},
|
},
|
||||||
"Period": int(period.total_seconds()),
|
"Period": int(period.total_seconds()),
|
||||||
"Stat": "Sum"
|
"Stat": "Sum",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if not metric["Dimensions"]:
|
if not metric["Dimensions"]:
|
||||||
continue
|
continue
|
||||||
query_names[f"q{n}"] = metric["Dimensions"][0]["Value"]
|
query_names[f"q{n}"] = metric["Dimensions"][0]["Value"]
|
||||||
n = n+1
|
n = n + 1
|
||||||
queries.append(query)
|
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.
|
# otherwise we would have to chunk up the calls to GetMetricData.
|
||||||
results = []
|
results = []
|
||||||
data_paginator = cw.get_paginator("get_metric_data")
|
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"]:
|
for result in data_page["MetricDataResults"]:
|
||||||
if result["Values"]:
|
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)
|
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
|
# CloudWatch logs: 5GiB free ingestion then $0.50 / GiB
|
||||||
# Estimate a monthly cost by doubling the incoming_bytes counted over the last 14 days
|
# 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
|
cost = (incoming_gb - 5.0) * 0.5
|
||||||
print(f"Estimated monthly cost: ${cost:.2f}")
|
print(f"Estimated monthly cost: ${cost:.2f}")
|
||||||
|
|
Loading…
Reference in a new issue