Short-circuit before building a query we don't use
This commit is contained in:
parent
7c24308039
commit
c60d6b9891
1 changed files with 3 additions and 4 deletions
7
aws/cloudwatch-log-costs.py
Executable file → Normal file
7
aws/cloudwatch-log-costs.py
Executable file → Normal file
|
@ -23,6 +23,8 @@ queries = []
|
||||||
paginator = cw.get_paginator("list_metrics")
|
paginator = cw.get_paginator("list_metrics")
|
||||||
for page in paginator.paginate(Namespace="AWS/Logs", MetricName="IncomingBytes"):
|
for page in paginator.paginate(Namespace="AWS/Logs", MetricName="IncomingBytes"):
|
||||||
for metric in page["Metrics"]:
|
for metric in page["Metrics"]:
|
||||||
|
if not metric["Dimensions"]:
|
||||||
|
continue
|
||||||
query = {
|
query = {
|
||||||
"Id": f"q{n}",
|
"Id": f"q{n}",
|
||||||
"MetricStat": {
|
"MetricStat": {
|
||||||
|
@ -35,8 +37,6 @@ for page in paginator.paginate(Namespace="AWS/Logs", MetricName="IncomingBytes")
|
||||||
"Stat": "Sum",
|
"Stat": "Sum",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if not metric["Dimensions"]:
|
|
||||||
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)
|
||||||
|
@ -62,13 +62,12 @@ for data_page in data_paginator.paginate(
|
||||||
results.sort(key=lambda x: x["IncomingBytes"], reverse=True)
|
results.sort(key=lambda x: x["IncomingBytes"], reverse=True)
|
||||||
|
|
||||||
incoming_bytes_total = 0
|
incoming_bytes_total = 0
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
incoming_bytes_total += result["IncomingBytes"]
|
incoming_bytes_total += result["IncomingBytes"]
|
||||||
print("{LogGroup}: {IncomingBytes}".format(**result))
|
print("{LogGroup}: {IncomingBytes}".format(**result))
|
||||||
|
|
||||||
# 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)
|
||||||
|
# CloudWatch logs: 5GiB free ingestion then $0.50 / GiB
|
||||||
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