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

fix: Metrics bug #80

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions backup_github/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
backup_time,
git_size,
meta_size,
rate_limit_count,
registry,
success,
)
Expand All @@ -24,7 +25,8 @@ def main():
parsed_args = None
try:
parsed_args = parse_args(sys.argv[1:])

success.labels(parsed_args.organization).set(0)
rate_limit_count.labels(parsed_args.organization).set(0)
backup = Backup(
parsed_args.token,
parsed_args.organization,
Expand All @@ -51,7 +53,7 @@ def main():
logging.error(e)
success.labels(parsed_args.organization).set(0)
finally:
sizes = count_sizes(parsed_args.output_dir)
sizes = count_sizes(parsed_args.output_dir, parsed_args.organization)
git_size.labels(parsed_args.organization).set(sizes["git"])
meta_size.labels(parsed_args.organization).set(sizes["meta"])
backup_time.labels(parsed_args.organization).set(int(time()))
Expand Down
8 changes: 5 additions & 3 deletions backup_github/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ def filter_save(struct, fields, path):
save_json(path, backup)


def count_sizes(output_dir):
def count_sizes(output_dir, organization):
git = 0
repo_dir = f"{output_dir}/repos"
repo_dir = f"{output_dir}/{organization}/repos"
if len(list(os.walk(repo_dir))) == 0:
return {"git": 0, "meta": 0}
repos = list(os.walk(repo_dir))[0][1]
for repository in repos:
git += sum(
p.stat().st_size
for p in Path(f"{repo_dir}/{repository}/content").rglob("*")
)
meta = sum(p.stat().st_size for p in Path(output_dir).rglob("*")) - git
meta = sum(p.stat().st_size for p in Path(repo_dir).rglob("*")) - git
return {"git": git, "meta": meta}