Skip to content

Commit

Permalink
Merge pull request #6 from opensourceelectrolux/feat-custom-metric-name
Browse files Browse the repository at this point in the history
feat: support defining a custom metric name
  • Loading branch information
gluckzhang authored Mar 14, 2024
2 parents f702c15 + 4d5c464 commit f664d4b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@


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

def run_metrics_loop(self):
while True:
Expand Down
3 changes: 2 additions & 1 deletion 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
metric_name: azure_daily_cost_usd # change the metric name if needed

group_by:
enabled: true
Expand All @@ -19,4 +20,4 @@ target_azure_accounts:
- TenantId: PUT_YOUR_AZURE_TENANT_ID_HERE
Subscription: PUT_YOUR_AZURE_SUBSCRIPTION_ID_HERE
ProjectName: myproject
EnvironmentName: dev
EnvironmentName: dev
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def get_configs():
def main(config, secrets):
app_metrics = MetricExporter(
polling_interval_seconds=config["polling_interval_seconds"],
metric_name=config["metric_name"],
group_by=config["group_by"],
targets=config["target_azure_accounts"],
secrets=secrets
Expand Down

0 comments on commit f664d4b

Please sign in to comment.