Created
September 21, 2020 20:53
-
-
Save jelly/6729f29622de35ffccc20866ce1a5825 to your computer and use it in GitHub Desktop.
rebuilderd prometheus statistics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
from collections import defaultdict | |
import requests | |
# The rebuilderd instance | |
API_URL = 'https://reproducible.archlinux.org' | |
def format_metric(suite, status, total): | |
status = status.lower() | |
format_str = """# HELP rebuilderd_{suite}_{status} number of {status} packages in {suite} | |
# TYPE rebuilderd_{suite}_{status} gauge" | |
rebuilderd_{suite}_{status} {total} | |
""" | |
return format_str.format(suite=suite, status=status, total=total) | |
req = requests.get(f'{API_URL}/api/v0/pkgs/list') | |
if req.status_code != 200: | |
print(f'Failed to obtain rebuilderd data, http status code: {req.status_code}', file=sys.stderr) | |
sys.exit(1) | |
data = req.json() | |
dataset = defaultdict(dict) | |
for entry in data: | |
suite = entry['suite'] | |
status = entry['status'] | |
if suite in dataset: | |
if status in dataset[suite]: | |
dataset[suite][status] += 1 | |
else: | |
dataset[suite][status] = 1 | |
else: | |
dataset[suite] = defaultdict(dict) | |
dataset[suite][status] = 1 | |
for suite, data in dataset.items(): | |
for status, total in data.items(): | |
print(format_metric(suite, status, total)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment