Skip to content

Commit

Permalink
Catch api call error
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray committed Nov 15, 2024
1 parent 3bd4ea1 commit 9181981
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "zuul-capacity"
version = "0.2.0"
version = "0.3.0"
description = "Zuul capacity exporter"
readme = "README.md"
requires-python = ">=3.12"
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions zuul-capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import argparse, openstack, logging, time, yaml
from dataclasses import dataclass
from prometheus_client import start_http_server, Gauge
from prometheus_client import start_http_server, Gauge, Counter

log = logging.getLogger("zuul-capacity")

Expand Down Expand Up @@ -49,16 +49,24 @@ def get_providers(nodepool_yaml):
providers[provider["name"]] = Provider.from_nodepool(provider)
return providers

def update_provider_metric(metrics, name, provider):
resources = get_resources(provider.cloud)
metrics["instances"].labels(cloud=name).set(len(resources))
cpu, mem = 0, 0
for resource in resources:
cpu += resource.cpu
mem += resource.mem
metrics["cpu"].labels(cloud=name).set(cpu)
metrics["mem"].labels(cloud=name).set(mem)

def update_providers_metric(metrics, providers):
for (name, provider) in providers.items():
resources = get_resources(provider.cloud)
metrics["instances"].labels(cloud=name).set(len(resources))
cpu, mem = 0, 0
for resource in resources:
cpu += resource.cpu
mem += resource.mem
metrics["cpu"].labels(cloud=name).set(cpu)
metrics["mem"].labels(cloud=name).set(mem)
try:
update_provider_metric(metrics, name, provider)
except Exception as e:
log.exception("Couldn't get provider", name, e)
metrics["error"].labels(cloud=name).inc()


def usage():
parser = argparse.ArgumentParser()
Expand All @@ -74,6 +82,7 @@ def main():
instances = Gauge('zuul_instances_total', 'Instance count', ['cloud']),
mem = Gauge('zuul_instances_mem', 'Memory usage', ['cloud']),
cpu = Gauge('zuul_instances_cpu', 'VCPU usage', ['cloud']),
error = Counter("zuul_provider_error", 'API call error', ['cloud'])
)

providers = get_providers(args.nodepool)
Expand Down

0 comments on commit 9181981

Please sign in to comment.