github-traffic
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSkill: GitHub Traffic
Skill: GitHub 流量统计
Fetch and analyze GitHub repository traffic data — page views, git clones, referral sources, popular pages, and star growth. Optionally generate trend charts as PNG images.
Prerequisites:
CLI must be installed and authenticatedgh- Push (write) access to the target repository is required — GitHub's Traffic API does not work with read-only access
is optional (for PNG chart generation; falls back to ASCII if unavailable)matplotlib
获取并分析GitHub仓库流量数据——页面浏览量、Git克隆量、来源网站、热门页面以及星标增长情况。可选择生成PNG格式的趋势图表。
前置要求:
- 必须安装并完成
CLI的身份验证gh- 需要目标仓库的推送(写入)权限——GitHub Traffic API不支持只读权限
为可选依赖(用于生成PNG图表;若未安装则自动回退到ASCII格式图表)matplotlib
When to Use
适用场景
- The user asks about repository traffic, page views, clone counts, or where visitors come from
- The user wants to see traffic trends over time (weekly, monthly, quarterly)
- The user wants to generate traffic report charts for sharing or documentation
- The user wants to periodically snapshot traffic data to build long-term history
- 用户询问仓库流量、页面浏览量、克隆次数或访客来源
- 用户希望查看一段时间内的流量趋势(每周、每月、每季度)
- 用户希望生成可用于分享或文档的流量报告图表
- 用户希望定期快照流量数据以构建长期历史记录
Important: GitHub Traffic API Limitations
重要提示:GitHub Traffic API 限制
GitHub only provides the last 14 days of traffic data. To track trends over longer periods (30 days, 90 days, etc.), the script stores each fetch in a local history file (). Regular snapshots are required to build up history.
~/.github-traffic/<repo>_traffic.jsonRecommended: set up a cron job or CI schedule to run the snapshot command periodically:
bash
undefinedGitHub仅提供最近14天的流量数据。若要跟踪更长周期(30天、90天等)的趋势,脚本会将每次获取的数据存储到本地历史文件中()。需要定期执行快照来积累历史数据。
~/.github-traffic/<repo>_traffic.json推荐方案:设置cron任务或CI调度,定期运行快照命令:
bash
undefinedDaily snapshot via cron (no output, just stores data)
通过cron每日执行快照(无输出,仅存储数据)
0 9 * * * python /path/to/scripts/github_traffic.py owner/repo --snapshot
---0 9 * * * python /path/to/scripts/github_traffic.py owner/repo --snapshot
---Default Workflow
默认工作流程
bash
python /path/to/skills/github-traffic/scripts/github_traffic.py <owner/repo>This will:
- Fetch current traffic data via
gh api - Save a snapshot to for historical tracking
~/.github-traffic/ - Display a formatted summary (views, clones, referrers, popular pages)
bash
python /path/to/skills/github-traffic/scripts/github_traffic.py <owner/repo>该命令会执行以下操作:
- 通过获取当前流量数据
gh api - 将快照保存到目录用于历史追踪
~/.github-traffic/ - 显示格式化的汇总信息(浏览量、克隆量、来源网站、热门页面)
Generating Charts
生成图表
bash
undefinedbash
undefinedGenerate PNG trend chart (last 30 days, default)
生成PNG趋势图表(默认显示最近30天数据)
python .../github_traffic.py owner/repo --chart
python .../github_traffic.py owner/repo --chart
Last 7 days
显示最近7天数据
python .../github_traffic.py owner/repo --chart --days 7
python .../github_traffic.py owner/repo --chart --days 7
Last 90 days (needs accumulated history)
显示最近90天数据(需要已积累的历史数据)
python .../github_traffic.py owner/repo --chart --days 90
python .../github_traffic.py owner/repo --chart --days 90
ASCII chart (no matplotlib needed)
生成ASCII格式图表(无需安装matplotlib)
python .../github_traffic.py owner/repo --ascii
The PNG chart includes up to 3 panels:
1. **Page Views** — total views and unique visitors (area chart)
2. **Git Clones** — total clones and unique cloners (bar + line chart)
3. **Star Growth** — star count over time (line chart, shown when multiple snapshots exist)
---python .../github_traffic.py owner/repo --ascii
PNG图表最多包含3个面板:
1. **页面浏览量**——总浏览量和独立访客数(面积图)
2. **Git克隆量**——总克隆次数和独立克隆用户数(柱状图+折线图)
3. **星标增长**——星标数量随时间的变化(折线图,仅当存在多次快照时显示)
---Script Options
脚本选项
| Flag | Default | Description |
|---|---|---|
| required | Repository in |
| off | Generate PNG trend chart |
| off | Force ASCII bar chart output |
| | Number of days to include in chart |
| | Directory for historical data storage |
| | Output path for chart image |
| off | Fetch and store data only (no display) |
| 标识 | 默认值 | 说明 |
|---|---|---|
| 必填 | 仓库格式为 |
| 关闭 | 生成PNG格式趋势图表 |
| 关闭 | 强制输出ASCII格式柱状图 |
| | 图表中包含的天数 |
| | 历史数据存储目录 |
| | 图表输出路径 |
| 关闭 | 仅获取并存储数据(不显示结果) |
Examples
使用示例
bash
undefinedbash
undefinedQuick traffic summary
快速查看流量汇总
python .../github_traffic.py zilliztech/memsearch
python .../github_traffic.py zilliztech/memsearch
Weekly trend chart
生成周度趋势图表
python .../github_traffic.py zilliztech/memsearch --chart --days 7
python .../github_traffic.py zilliztech/memsearch --chart --days 7
Monthly trend chart, custom output path
生成月度趋势图表,自定义输出路径
python .../github_traffic.py zilliztech/memsearch --chart --days 30 --output ./reports/traffic.png
python .../github_traffic.py zilliztech/memsearch --chart --days 30 --output ./reports/traffic.png
Just store a snapshot (for cron jobs)
仅存储快照(用于cron任务)
python .../github_traffic.py zilliztech/memsearch --snapshot
python .../github_traffic.py zilliztech/memsearch --snapshot
ASCII chart when matplotlib is not available
当未安装matplotlib时生成ASCII格式图表
python .../github_traffic.py zilliztech/memsearch --ascii --days 14
---python .../github_traffic.py zilliztech/memsearch --ascii --days 14
---History & Long-Term Tracking
历史记录与长期追踪
Each run merges the current 14-day window into a persistent JSON file at . The file contains:
~/.github-traffic/<owner>_<repo>_traffic.json- Daily views: date → {views, unique}
- Daily clones: date → {clones, unique}
- Star snapshots: date → star count
- Fetch metadata: timestamp, 14-day totals, stars, forks
To build meaningful 30/90-day charts, run the script at least every 14 days (daily is ideal). Gaps longer than 14 days will show as missing data in charts.
每次运行脚本时,会将当前14天的窗口数据合并到持久化JSON文件中,文件路径为。该文件包含:
~/.github-traffic/<owner>_<repo>_traffic.json- 每日浏览量:日期 → {views, unique}
- 每日克隆量:日期 → {clones, unique}
- 星标快照:日期 → 星标数量
- 获取元数据:时间戳、14天总计数据、星标数、复刻数
若要生成有意义的30/90天图表,至少每14天运行一次脚本(每日运行最佳)。若两次运行间隔超过14天,图表中会显示数据缺失。
Permissions
权限说明
The GitHub Traffic API requires push access to the repository. This means:
- Repository owners and admins: full access
- Collaborators with write/maintain role: full access
- Read-only users and forkers: no access (API returns 403)
If you get a permission error, check your and ensure your token has the scope.
gh auth statusrepoGitHub Traffic API需要仓库的推送权限。这意味着:
- 仓库所有者和管理员:拥有完整访问权限
- 拥有写入/维护角色的协作者:拥有完整访问权限
- 只读用户和复刻仓库用户:无访问权限(API返回403错误)
若遇到权限错误,请检查并确保你的token拥有权限范围。
gh auth statusrepoTroubleshooting
故障排查
| Problem | Solution |
|---|---|
| "Must have push access" error | You need write access to the repo. Check |
| Chart shows only 14 days | GitHub only provides 14-day windows. Run |
| matplotlib not found | Install with |
| No data for some dates | GitHub may not report days with zero traffic. These gaps are normal. |
| 问题 | 解决方案 |
|---|---|
| “必须拥有推送权限”错误 | 你需要仓库的写入权限。请检查 |
| 图表仅显示14天数据 | GitHub仅提供14天的窗口数据。定期运行 |
| 未找到matplotlib | 使用 |
| 部分日期无数据 | GitHub可能不会报告流量为零的日期。此类数据缺失属于正常情况。 |