I TURNED MY SELF-HOSTED GIT INTO A LIVE WAR ROOM: Gitea Prometheus Metrics + Grafana, Gated and Graphed

I TURNED MY SELF-HOSTED GIT INTO A LIVE WAR ROOM: Gitea Prometheus Metrics + Grafana, Gated and Graphed
Dark server room with a glowing Grafana-style dashboard, a green git-branch glyph and Prometheus flame accents

I self-host all my git on git.lightgui.com — twelve repositories, one user, zero outside dependencies. Until now it ran blind: if Gitea slowed down, ate memory, or stopped scraping, the first sign would have been a failed push. That ends today. Gitea 28.4.0 now exports Prometheus metrics behind a bearer token, a pinned Prometheus 3.16.0 scrapes it every 15 seconds, and a Grafana 13.0 dashboard — Gitea Overview — shows the whole thing behind the same htpasswd gate as the traffic stats. Every number in this article was read off the live server while writing it.

The stack, exactly as built

PieceVersion / detail
Gitea28.4.0, Docker container gitea, data in /opt/gitea, HTTP on host port 3000, SSH on 2222, SQLite, live at git.lightgui.com
Prometheusprom/prometheus:v3.16.0, container monitoring-prometheus, localhost-only on :9090
Grafanagrafana/grafana:13.0, container monitoring-grafana, on :3001
ProxyNginx Proxy Manager proxy host 18, metrics.hotconfig.com → 172.93.49.176:3001, gated by access list 2
Hosthot_newyork, 172.93.49.176 — everything lives in /opt/monitoring/

Step 1: switch on Gitea metrics

Gitea ships a Prometheus endpoint, but it is off by default and, once on, it demands a bearer token — no token, no metrics. Two lines in /opt/gitea/data/gitea/conf/app.ini do it:

[metrics]
ENABLED = true
TOKEN = <your-token-here>

Generate the token with openssl rand -hex 32 and store it mode 600 at /root/.gitea-metrics-token. Never put a real token in a compose file, a dashboard, or an article — this one included. Then restart Gitea and prove the gate works both ways:

docker restart gitea
curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:3000/metrics
# 401 — no token, no metrics
curl -s -o /dev/null -w "%{http_code}\n" -H "Authorization: Bearer $(cat /root/.gitea-metrics-token)" http://127.0.0.1:3000/metrics
# 200

The whole enable-and-verify flow is saved on the server as /root/enable-gitea-metrics.sh — it generates the token if missing, appends the [metrics] section, restarts Gitea, checks both status codes, and counts the metric families. Live result on this box: 66 metric families, 27 of them gitea_* series.

Step 2: the Prometheus + Grafana stack

One Compose file, two pinned images, no latest tags anywhere. This is /opt/monitoring/docker-compose.yml, verbatim:

services:
  prometheus:
    image: prom/prometheus:v3.16.0
    container_name: monitoring-prometheus
    restart: unless-stopped
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
    ports:
      - "127.0.0.1:9090:9090"
    volumes:
      - /opt/monitoring/prometheus:/etc/prometheus:ro
      - /opt/monitoring/secrets/gitea-token:/run/secrets/gitea-token:ro
      - /opt/monitoring/data/prometheus:/prometheus
  grafana:
    image: grafana/grafana:13.0
    container_name: monitoring-grafana
    restart: unless-stopped
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD__FILE=/run/secrets/grafana-admin-pass
      - GF_SERVER_ROOT_URL=https://metrics.hotconfig.com/
      - GF_SERVER_DOMAIN=metrics.hotconfig.com
      - GF_USERS_ALLOW_SIGN_UP=false
    ports:
      - "3001:3000"
    volumes:
      - /opt/monitoring/data/grafana:/var/lib/grafana
      - /opt/monitoring/grafana/provisioning:/etc/grafana/provisioning:ro
      - /opt/monitoring/grafana/dashboards:/var/lib/grafana/dashboards:ro
      - /opt/monitoring/secrets/grafana-admin-pass:/run/secrets/grafana-admin-pass:ro

Two details matter. First, Prometheus is localhost-only (127.0.0.1:9090) — its UI and API are not on the public internet; Grafana reaches it over the internal Docker network. Second, the token mount is the fix that cost a failed start: the first attempt mounted the Gitea token under the read-only /etc/prometheus directory, and Prometheus refused to start. The working layout mounts the token at /run/secrets/gitea-token instead — a copy of /root/.gitea-metrics-token, mode 600, owned by the prometheus user (uid 65534). If your Prometheus container exits immediately after adding a bearer token file, check where you mounted it before you check anything else.

The scrape config, /opt/monitoring/prometheus/prometheus.yml:

global:
  scrape_interval: 15s
scrape_configs:
  - job_name: gitea
    bearer_token_file: /run/secrets/gitea-token
    static_configs:
      - targets: ["172.93.49.176:3000"]
        labels:
          instance: "git.lightgui.com"
  - job_name: prometheus
    static_configs:
      - targets: ["localhost:9090"]

Grafana is provisioned, not clicked together: a Prometheus datasource (http://prometheus:9090, default, uid prometheus) and a dashboard provider watching /var/lib/grafana/dashboards with a 30-second refresh, so editing the dashboard JSON on disk re-provisions it automatically.

Step 3: the Grafana admin password

Grafana's default admin / admin login is dead on this box — the admin password is generated, stored mode 600 at /root/.grafana-admin-pass, and injected through GF_SECURITY_ADMIN_PASSWORD__FILE. Generate your own the same way and never commit it anywhere:

openssl rand -base64 24 | tr -d '\n' > /root/.grafana-admin-pass
chmod 600 /root/.grafana-admin-pass
cp /root/.grafana-admin-pass /opt/monitoring/secrets/grafana-admin-pass
chown 472:472 /opt/monitoring/secrets/grafana-admin-pass
chmod 600 /opt/monitoring/secrets/grafana-admin-pass

The copy step is not optional decoration: Grafana runs as uid 472, and a root-owned 600 file is unreadable to it. The password file the container sees must be 472-owned. Sign-ups are disabled (GF_USERS_ALLOW_SIGN_UP=false), so the admin account is the only way in.

Step 4: the dashboard — and the honest limit

The Gitea Overview dashboard (/d/gitea-overview/gitea-overview, JSON at /opt/monitoring/grafana/dashboards/gitea.json) is built only from metrics that actually exist. Here is the part most write-ups would skip: Gitea 28.4.0 exposes no HTTP-request metrics, no git clone/fetch counters, and no database metrics. There is no panel for clone traffic because there is no metric for it, and inventing one would be lying with a graph. The dashboard says so in its own text panel, and points at the GoAccess report (traffic.hotconfig.com/git.html) for clone and download traffic instead. What Gitea does expose is entity counts plus Go runtime and process metrics — and that is what the dashboard shows.

PanelQueryLive value
Repositoriesgitea_repositories12
Active usersgitea_users{state="active"}1
Releasesgitea_releases2
Watchesgitea_watches12
Starsgitea_stars0
Open issuesgitea_issues_open0
Attachmentsgitea_attachments10
Public keysgitea_publickeys1
Scrape target upup{job="gitea"}1

The timeseries panels track entities over time, process memory (process_resident_memory_bytes ≈ 228 MiB, heap go_memstats_heap_alloc_bytes ≈ 103 MiB), CPU as rate(process_cpu_seconds_total{job="gitea"}[5m]) (about 0.8 cores at the moment of writing — it moves with activity; earlier readings sat near 0.3), goroutines (65) and open file descriptors (19), network I/O as rate(process_network_receive_bytes_total[5m]) / rate(process_network_transmit_bytes_total[5m]) — the closest available proxy for traffic, since it includes the HTTP git operations Gitea serves — and the scrape rate itself, rate(promhttp_metric_handler_requests_total[5m]). The database is SQLite, so there are no database metrics to show either; that is a property of the setup, not a gap in the dashboard.

Step 5: the proxy gate

Grafana is not exposed raw. Nginx Proxy Manager proxy host 18 forwards metrics.hotconfig.com to 172.93.49.176:3001 with access_list_id: 2 — the same traffic-stats htpasswd gate that already protects traffic.hotconfig.com. The generated 18.conf carries the auth block:

auth_basic            "Authorization required";
auth_basic_user_file  /data/access/2;

Verified live: no credentials → 401, wrong credentials → 401. No existing proxy host and no existing access list was touched — host 18 is new, and the traffic-stats gate is shared, not modified. The creation script is /root/npm-metrics-proxy.sh on the server.

Step 6: DNS and the certificate — the unfinished step

Here is the part that is not done yet, stated plainly: metrics.hotconfig.com currently has no DNS A record (NXDOMAIN, verified). The Let's Encrypt request failed because there is nothing for the HTTP-01 challenge to resolve to, so there is no public HTTPS yet — Grafana is reachable on :3001 locally and through the proxy only once DNS exists. The prerequisite is one record:

metrics.hotconfig.com  A  172.93.49.176

Once that record exists, the resume step is a single script on the server, /root/npm-metrics-cert.sh. It refuses to run while DNS is still missing, then requests the Let's Encrypt certificate through the NPM API, attaches it to proxy host 18 with force-SSL, and verifies the auth_basic block survived in the regenerated 443 block — the gate must not silently drop when the certificate lands. Run it after the A record propagates:

/root/npm-metrics-cert.sh

Verification, all live

  • Prometheus targets: gitea up, prometheus up, zero scrape errors.
  • /metrics without a token → 401; with the Bearer token → 200; 66 metric families, 27 gitea_* series.
  • Grafana /login on :3001 → 200, and the admin login works; default admin/admin is dead.
  • https://git.lightgui.com/ → 200 — Gitea itself was never disturbed by any of this.
  • https://traffic.hotconfig.com/ without credentials → 401, unchanged; the shared gate still works.
  • metrics.hotconfig.com DNS → NXDOMAIN; certificate pending on the A record, resume script ready.

Twelve repos, one user, one dashboard — and now the git server watches itself. The moment something changes — a repo count that should not move, memory climbing, a scrape target going down — it shows up on a graph instead of surfacing as a failed push at midnight.

References: Gitea · Prometheus · Grafana · git.lightgui.com

Linux Rocks Every Day