alarm: proxy_cloudfront reads max quota from config
This commit is contained in:
parent
16c1d26e3b
commit
3da5abce92
1 changed files with 17 additions and 9 deletions
|
@ -1,4 +1,3 @@
|
|||
import datetime
|
||||
from typing import Tuple
|
||||
|
||||
import boto3
|
||||
|
@ -14,17 +13,26 @@ from app.terraform import BaseAutomation
|
|||
|
||||
|
||||
def _cloudfront_quota() -> None:
|
||||
alarm = get_or_create_alarm(
|
||||
BRN.from_str(f"brn:{current_app.config['GLOBAL_NAMESPACE']}:0:mirror:cloudfront:quota/distributions"),
|
||||
"quota-usage"
|
||||
)
|
||||
alarm.last_updated = datetime.datetime.utcnow()
|
||||
# It would be nice to learn this from the Service Quotas API, however
|
||||
# at the time of writing this comment, the current value for this quota
|
||||
# is not available from the API. It just doesn't return anything.
|
||||
max_count = int(current_app.config.get('AWS_CLOUDFRONT_MAX_DISTRIBUTIONS', 200))
|
||||
deployed_count = len(Proxy.query.filter(
|
||||
Proxy.destroyed.is_(None)).all())
|
||||
message = f"{deployed_count} distributions deployed"
|
||||
if deployed_count > 370:
|
||||
message = f"{deployed_count} distributions deployed of {max_count} quota"
|
||||
alarm = get_or_create_alarm(
|
||||
BRN(
|
||||
group_id=0,
|
||||
product="mirror",
|
||||
provider="cloudfront",
|
||||
resource_type="quota",
|
||||
resource_id="distributions"
|
||||
),
|
||||
"quota-usage"
|
||||
)
|
||||
if deployed_count > max_count * 0.9:
|
||||
alarm.update_state(AlarmState.CRITICAL, message)
|
||||
elif deployed_count > 320:
|
||||
elif deployed_count > max_count * 0.75:
|
||||
alarm.update_state(AlarmState.WARNING, message)
|
||||
else:
|
||||
alarm.update_state(AlarmState.OK, message)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue