This repository was archived by the owner on Sep 6, 2025. It is now read-only.
forked from percona/rds_exporter
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathentry.py
More file actions
77 lines (59 loc) · 2.39 KB
/
entry.py
File metadata and controls
77 lines (59 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
import os
import boto3
import yaml
import subprocess
AWS_REGION = os.getenv('AWS_REGION', 'eu-west-1')
ENVIRONMENT = os.getenv('ENVIRONMENT', 'staging')
# These dbinstances are scraped by rds-prom-exporter
# embedded into service's chart.
# No need to scrape them via kube-prometheus.
BLACKLIST = [
"delivery-regions-db000-live",
"delivery-regions-db000-staging",
"subscriptions-query-service-db002-live",
"subscriptions-query-service-db002-staging",
"wms-adapter-service-db000-live",
"wms-adapter-service-db000-staging",
"distribution-center-dashboards-db000-live",
"distribution-center-dashboards-db000-staging",
]
client = boto3.client('rds', region_name=AWS_REGION)
def get_db_instances(page_size=20):
marker = ""
pool = []
while True:
for instance in pool:
yield instance
if marker is None:
break
result = client.describe_db_instances(MaxRecords=page_size,
Marker=marker)
marker = result.get("Marker")
pool = result.get("DBInstances")
def get_rds_tags(instance_arn):
response = client.list_tags_for_resource(
ResourceName=instance_arn
)
return { tag['Key']: tag['Value'] for tag in response['TagList'] }
def is_applicable(instance):
instance_name = instance['DBInstanceIdentifier']
instance_arn = instance['DBInstanceArn']
if instance_name in BLACKLIST:
return False
instance_tags = get_rds_tags(instance_arn)
instance_environment_tag = instance_tags.get('Environment', '')
return (instance_name.lower().endswith(ENVIRONMENT.lower()) or instance_environment_tag.lower() == ENVIRONMENT.lower())
if __name__ == "__main__":
em_enabled_instances = {'instances': []}
for instance in get_db_instances():
if instance.get('MonitoringInterval', 0) > 0:
if is_applicable(instance):
instance_name = instance['DBInstanceIdentifier']
instance = {'instance': instance_name, 'region': AWS_REGION}
em_enabled_instances['instances'].append(instance)
with open('/rds_exporter/config.yml', 'w') as yaml_file:
yaml.dump(em_enabled_instances, yaml_file, default_flow_style=False)
rds_exporter = '/rds_exporter/rds_exporter \
--config.file=/rds_exporter/config.yml'
subprocess.run(rds_exporter, shell=True)