feat(stats): split repos public/private + 7-day daily commit series

Collector now reports repos_public/repos_private (repos kept as the sum)
and a commits_daily[] series of 7 {date,commits} buckets (UTC days,
zero-filled), bucketed in Go from raw created_unix to avoid MySQL
session-timezone ambiguity. commits_7d is now the sum of those buckets
so the card total matches the sparkline.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
h z
2026-05-29 08:09:21 +01:00
parent 2cfa6ca76a
commit 448254001a
2 changed files with 94 additions and 19 deletions

View File

@@ -12,8 +12,33 @@ A tiny Go service that periodically snapshots Gitea instance metrics from a
metrics card. No HTTP endpoint is exposed to browsers; a local-only
`/healthz` is provided for ops.
Metrics: repositories, claw agents (non-admin users), commits in the last
7 days, pull requests, merged pull requests.
Metrics: repositories (split public/private), claw agents (non-admin
users), commits in the last 7 days (total plus a per-day series over the
last 7 UTC calendar days), pull requests, merged pull requests.
### Output schema (`stats.json`)
```json
{
"repos": 42,
"repos_public": 30,
"repos_private": 12,
"agents": 7,
"commits_7d": 91,
"commits_daily": [
{"date": "2026-05-22", "commits": 10},
{"date": "2026-05-23", "commits": 14}
// … 7 entries total, oldest → newest (UTC days)
],
"prs": 18,
"merged": 12,
"generated_at": "2026-05-28T00:00:00Z",
"interval_hours": 12
}
```
`commits_7d` equals the sum of `commits_daily` (7 calendar days, UTC), so
the card total always matches the sparkline.
### Configuration (all via environment variables — no secrets in the image)
@@ -31,7 +56,7 @@ refresh it keeps the previous output (stale-while-error).
```sh
# from repo root
IMAGE=git.hangman-lab.top/hzhang/gitea-stats TAG=0.1.0 ./publish.sh
IMAGE=git.hangman-lab.top/hzhang/gitea-stats TAG=0.2.0 ./publish.sh
```
### Run
@@ -42,7 +67,7 @@ docker run -d --name git-kc-stats \
-e STATS_DB_DSN='gitea_ro:***@tcp(mysql:3306)/giteadb?timeout=5s&readTimeout=10s&loc=UTC' \
-e STATS_INTERVAL=12h \
-v /var/lib/gitea/custom/public/assets:/out \
git.hangman-lab.top/hzhang/gitea-stats:0.1.0
git.hangman-lab.top/hzhang/gitea-stats:0.2.0
```
> The read-only MySQL user (`gitea_ro`, `SELECT` only on `giteadb`) and its