|
42 | 42 | ["repository"], |
43 | 43 | ) |
44 | 44 |
|
| 45 | +gh_traffic_top_paths = Gauge( |
| 46 | + "github_traffic_top_paths", |
| 47 | + "Number of visits to top paths", |
| 48 | + ["repository", "path", "title"], |
| 49 | +) |
| 50 | + |
| 51 | +gh_traffic_top_unique_paths = Gauge( |
| 52 | + "github_traffic_top_unique_paths", |
| 53 | + "Number of unique visits to top paths", |
| 54 | + ["repository", "path", "title"], |
| 55 | +) |
| 56 | + |
| 57 | +gh_traffic_top_referrers = Gauge( |
| 58 | + "github_traffic_top_referrers", |
| 59 | + "Number of visits from top referrers", |
| 60 | + ["repository", "referrer"], |
| 61 | +) |
| 62 | + |
| 63 | +gh_traffic_top_unique_referrers = Gauge( |
| 64 | + "github_traffic_top_unique_referrers", |
| 65 | + "Number of unique visits from top referrers", |
| 66 | + ["repository", "referrer"], |
| 67 | +) |
| 68 | + |
45 | 69 | gh_traffic_stars = Gauge( |
46 | 70 | "github_traffic_stars", |
47 | 71 | "Number of stars", |
@@ -98,7 +122,33 @@ def job_function(): |
98 | 122 | toShow['stars'] = repo.stargazers_count |
99 | 123 | except Exception as e: |
100 | 124 | logger.error(f"Failed to get stars on {repo_name}: {e}") |
101 | | - |
| 125 | + try: |
| 126 | + # Top Paths |
| 127 | + total_count = 0 |
| 128 | + total_unique_count = 0 |
| 129 | + for path in repo.get_top_paths(): |
| 130 | + gh_traffic_top_paths.labels(repo_name, path.path, path.title).set(path.count) |
| 131 | + total_count = total_count + path.count |
| 132 | + gh_traffic_top_unique_paths.labels(repo_name, path.path, path.title).set(path.uniques) |
| 133 | + total_unique_count = total_unique_count + path.uniques |
| 134 | + toShow['sum(top_paths)'] = total_count |
| 135 | + toShow['sum(top_unique_paths)'] = total_unique_count |
| 136 | + except Exception as e: |
| 137 | + logger.error(f"Failed to get top paths on {repo_name}: {e}") |
| 138 | + try: |
| 139 | + # Top Referrers |
| 140 | + total_count = 0 |
| 141 | + total_unique_count = 0 |
| 142 | + for referrer in repo.get_top_referrers(): |
| 143 | + gh_traffic_top_referrers.labels(repo_name, referrer.referrer).set(referrer.count) |
| 144 | + total_count = total_count + referrer.count |
| 145 | + gh_traffic_top_unique_referrers.labels(repo_name, referrer.referrer).set(referrer.uniques) |
| 146 | + total_unique_count = total_unique_count + referrer.uniques |
| 147 | + toShow['sum(top_referrers)'] = total_count |
| 148 | + toShow['sum(top_unique_referrers)'] = total_unique_count |
| 149 | + except Exception as e: |
| 150 | + logger.error(f"Failed to get top referrers on {repo_name}: {e}") |
| 151 | + |
102 | 152 | logger.info('Gather insights', extra={"context": toShow}) |
103 | 153 |
|
104 | 154 |
|
|
0 commit comments