Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the metric name configurable #2

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@


class MetricExporter:
def __init__(self, endpoint, aggregate, interval, extra_labels):
def __init__(self, endpoint, aggregate, interval, name, extra_labels):
self.endpoint = endpoint
self.aggregate = aggregate
self.interval = interval
self.name = name
self.extra_labels = extra_labels
self.labels = set([aggregate])
if extra_labels is not None:
self.labels.update(extra_labels.keys())
self.kubernetes_daily_cost_usd = Gauge(
"kubernetes_daily_cost_usd", "Kubernetes daily cost in USD aggregated by %s" % self.aggregate, self.labels)
self.name, "Kubernetes daily cost in USD aggregated by %s" % self.aggregate, self.labels)

def run_metrics_loop(self):
while True:
Expand Down
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def get_args():
help="Exporter's port (default: 9090)")
parser.add_argument("-i", "--interval", default=60, type=int,
help="Update interval in seconds (default: 60)")
parser.add_argument("-n", "--name", default="kubernetes_daily_cost_usd",
help="Name of the exposed metric (default: kubernetes_daily_cost_usd)")
parser.add_argument("-e", "--endpoint", default="http://kubecost-cost-analyzer.monitoring.svc:9003",
help="Kubecost service endpoint (default: http://kubecost-cost-analyzer.monitoring.svc:9003)")
parser.add_argument("-a", "--aggregate", default="namespace",
Expand All @@ -44,6 +46,7 @@ def main(args):
endpoint=args.endpoint,
aggregate=args.aggregate,
interval=args.interval,
name=args.name,
extra_labels=args.label
)
start_http_server(args.port)
Expand Down