Skip to content

Commit

Permalink
make metric name configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
gluckzhang committed Dec 8, 2023
1 parent cf9a1d2 commit 4109a2b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@


class MetricExporter:
def __init__(self, polling_interval_seconds, aws_access_key, aws_access_secret, aws_assumed_role_name, group_by, targets):
def __init__(self, polling_interval_seconds, metric_name, aws_access_key, aws_access_secret, aws_assumed_role_name, group_by, targets):
self.polling_interval_seconds = polling_interval_seconds
self.metric_name = metric_name
self.targets = targets
self.aws_access_key = aws_access_key
self.aws_access_secret = aws_access_secret
Expand All @@ -27,7 +28,7 @@ def __init__(self, polling_interval_seconds, aws_access_key, aws_access_secret,
for group in group_by["groups"]:
self.labels.add(group["label_name"])
self.aws_daily_cost_usd = Gauge(
"aws_daily_cost_usd", "Daily cost of an AWS account in USD", self.labels)
self.metric_name, "Daily cost of an AWS account in USD", self.labels)

def run_metrics_loop(self):
while True:
Expand Down
1 change: 1 addition & 0 deletions exporter_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
exporter_port: $EXPORTER_PORT|9090 # the port that exposes cost metrics
polling_interval_seconds: $POLLING_INTERVAL_SECONDS|28800 # by default it is 8 hours because for daily cost, AWS only updates the data once per day
metric_name: aws_daily_cost_usd # change the metric name if needed

aws_access_key: $AWS_ACCESS_KEY # for prod deployment, DO NOT put the actual value here
aws_access_secret: $AWS_ACCESS_SECRET # for prod deployment, DO NOT put the actual value here
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def get_configs():
def main(config):
app_metrics = MetricExporter(
polling_interval_seconds=config["polling_interval_seconds"],
metric_name=config["metric_name"],
aws_access_key=config["aws_access_key"],
aws_access_secret=config["aws_access_secret"],
aws_assumed_role_name=config["aws_assumed_role_name"],
Expand Down

0 comments on commit 4109a2b

Please sign in to comment.