You've already forked gitea_exporter
mirror of
https://github.com/Lunik/gitea_prometheus_exporter.git
synced 2025-07-30 08:23:06 +03:00
@ -48,6 +48,7 @@ def module(app):
|
||||
GAUGES['repo_branches']._metrics.clear()
|
||||
GAUGES['repo_forks']._metrics.clear()
|
||||
GAUGES['repo_issues']._metrics.clear()
|
||||
|
||||
for repo in gitea_metrics['repos']:
|
||||
GAUGES['repo'].labels(name=repo.name, owner=repo.owner.username).set(1)
|
||||
GAUGES['repo_size'].labels(name=repo.name, owner=repo.owner.username, unit="bytes").set(repo.size)
|
||||
|
@ -1,22 +1,15 @@
|
||||
from gitea import *
|
||||
|
||||
def get_repo_commit_count(gitea, repo):
|
||||
page_endpoint = Repository.REPO_COMMITS % (repo.owner.username, repo.name)
|
||||
|
||||
response = gitea.requests.get(gitea.url + "/api/v1" + page_endpoint + "?limit=1", headers=gitea.headers, params={})
|
||||
|
||||
if 'X-Total' in response.headers:
|
||||
return int(response.headers.get('X-Total'))
|
||||
else:
|
||||
return 0
|
||||
from lib.gitea import Gitea
|
||||
|
||||
def gitea_export(app):
|
||||
metrics = dict()
|
||||
|
||||
print("========== Scraping Start ==========")
|
||||
|
||||
try:
|
||||
gitea = Gitea(app.config['MODULE_CONFIG']['url'], app.config['MODULE_CONFIG']['auth']['token'])
|
||||
gitea.get_version()
|
||||
print(gitea.get_version())
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("[WARNING] Unable to initiate connection with gitea.")
|
||||
return metrics
|
||||
|
||||
@ -34,7 +27,6 @@ def gitea_export(app):
|
||||
print("[WARNING] Unable to retrieve 'Gitea Users'.")
|
||||
metrics['orgs'] = dict()
|
||||
|
||||
|
||||
metrics['repos'] = []
|
||||
|
||||
try:
|
||||
@ -54,7 +46,7 @@ def gitea_export(app):
|
||||
try:
|
||||
for repo in metrics['repos']:
|
||||
repo.branches_count = len(repo.get_branches()) if not repo.empty else 0
|
||||
repo.commits_count = get_repo_commit_count(gitea, repo) if not repo.empty else 0
|
||||
repo.commits_count = repo.get_commit_count() if not repo.empty else 0
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("[WARNING] Unable to retrieve 'Gitea repos git infos'.")
|
||||
|
Reference in New Issue
Block a user