1
0
mirror of https://github.com/Lunik/gitea_prometheus_exporter.git synced 2025-07-30 08:23:06 +03:00

remove external library

Signed-off-by: Lunik <lunik@tiwabbit.fr>
This commit is contained in:
Lunik
2021-03-29 19:58:07 +02:00
parent d2e70d2f7c
commit 9c4d222765
9 changed files with 193 additions and 15 deletions

View File

@ -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)

View File

@ -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'.")