Skip to content
devmtnaingPublic

About

Personal monitoring for personal projects

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

17 Commits

Folders and files

Repository files navigation

cloudlab

A homelab you don't own the hardware for.

The homelab pattern — one control plane watching everything — works because the workloads sit on machines in your house, so the control plane can both observe them and act on them. Rented infrastructure removes the second half: nothing you write can install an agent into Vercel's build fleet or restart a container on Railway's scheduler. So this aggregates instead of orchestrating. One small host you do own collects from everything you don't, and pushes it to one place.

Point Grafana Cloud at your servers and your Railway projects, from one config file.

  • Service-level health, not just host health. You list the systemd units that matter (nginx, postgresql, wireguard) and their up/down state becomes a metric you can alert on — plus a catch-all that fires when any unit on the box fails.
  • External checks for things you can't instrument. You can't install an agent inside Railway or Vercel, so the only way to know a service answers is to ask it from outside. List URLs in CHECKS and one host probes them on a timer — no extra service, no container, using the agent that's already there.
  • Inventory and spend from provider APIs. What exists and what it costs — droplets nobody remembers creating, a Vercel deploy that failed, a Cloudflare zone left in development mode, the month's bill so far. One poller per provider, on a timer, read-only tokens.
  • What the month costs. The one axis a homelab never needs: its running cost is one electricity bill, yours is several invoices that change without telling you. DigitalOcean usage is read from its API; fixed subscriptions are declared in config.sh, because no other provider here exposes spend to a token.
  • Railway logs on any Railway plan. Railway's log drain is a paid feature. This polls the Railway CLI from a server you already run and tails the result into Loki — no plan upgrade, no change to your apps. That includes the edge HTTP logs, which make request rate, error rate and latency queryable.

Nothing is hardcoded. Hosts, units, tokens and cadence all come from config.sh and .env.

your servers ─────┐
                  │
Railway CLI ──────┤
                  ├── Alloy agent ──→ Grafana Cloud (Prometheus + Loki)
public URLs ──────┤   metrics + logs
   (probed)       │
                  │
provider APIs ────┘
   (polled)

Everything the collector gathers leaves through the one agent already on the host. Nothing else needs Grafana credentials, and there is no second thing to keep running.

Requirements

  • A Grafana Cloud account — the free tier is plenty. One server ≈ 300 of the 10,000 included metric series.
  • Debian/Ubuntu servers, reachable over SSH as root or a passwordless-sudo user.
  • Locally: bash, ssh, scp, curl. No Terraform, Docker, Ansible, jq or yq.
  • For Railway: a project token per Railway project.

Install

1. Collect your Grafana Cloud credentials

You need five values. The quickest way to get all of them at once: in your Grafana stack go to Connections → Add new connection → Linux Server → Configuration details. The snippet it generates contains every value — copy them out and discard the snippet itself, since this repo replaces it.

From the snippet Goes to
prometheus.remote_write → url GC_PROM_URL
its basic_auth.username GC_PROM_USER
loki.write → url GC_LOKI_URL
its basic_auth.username GC_LOKI_USER
the password (same in both) GC_TOKEN

The two usernames are different numeric instance IDs. Pasting the same one twice is the most common setup mistake — ./bin/verify-credentials checks for it.

You also need one more credential, so dashboards can be installed for you rather than imported by hand. In your stack: Administration → Users and access → Service accounts → Add service account, role Editor, then Add service account token.

Value Goes to
your stack root, e.g. https://yourstack.grafana.net GRAFANA_URL
the glsa_… token GRAFANA_TOKEN

This is deliberately a different credential from the five above: those push data into the backend, this one writes to the Grafana instance. Leave it out and everything still works — you just import dashboards/*.json by hand.

Finally, for alert rules: grafana.com → your stack → Security → Access Policies → Create, scopes rules:read and rules:write, then add a token. That becomes GC_RULES_TOKEN in .env.

Three tokens is not accidental. Only GC_TOKEN is copied to your servers, and it can only append data — so a compromised host cannot delete metrics, edit a dashboard, or switch off the alert that would have caught it. See DESIGN.md → Safety.

If you're using Railway, also grab a project token per project: Railway dashboard → your project → Settings → Tokens. Use a project token rather than an account token, so a compromised collector can't reach your whole Railway account.

2. Clone and initialise

git clone https://github.com/YOUR-USERNAME/cloudlab.git
cd cloudlab

./bin/init          # creates .env and config.sh from the examples

3. Fill in your credentials

Put the five Grafana values — and any Railway tokens — into .env, then check them before touching a server:

$EDITOR .env
./bin/verify-credentials

This installs nothing. It probes both endpoints and pushes one test log line, so a wrong URL or a token missing a scope fails here rather than half-way through an install.

4. Describe your servers

./bin/discover-units my-server      # prints a ready-to-paste HOSTS line
$EDITOR config.sh

discover-units is read-only: it inspects the host, guesses the provider, and lists running services with OS plumbing filtered out. Trim its suggestion to the services whose health you actually care about.

5. Install

./bin/setup

That installs every host, the Railway shippers, then — for whichever credentials you supplied — pushes dashboards/*.json into Grafana and alerts/*.yaml into the Cloud rule store. Both are idempotent, so re-running updates in place instead of piling up copies. To push just one of them after an edit:

./bin/install-dashboards
./bin/install-alerts

install-alerts is also authoritative: delete a file from alerts/ and the matching rule group is removed from Grafana Cloud on the next run.

Alert rules fire but do not notify — routing is a one-time manual step under Alerting → Contact points. Every rule ships with the label source=cloudlab, so one notification policy can match all of them.

That's the whole install. Nothing is left to click.

Three dashboards ship in dashboards/:

Dashboard Shows
Cloudlab — Overview Everything, one page. Start here.
Cloudlab — Cost Month to date, projection against budget, where it goes
Fleet — Hosts & Units Hosts reporting, watched unit state, disk, memory, CPU, TCP
Railway — Services Overview Request rate, errors, latency percentiles, slowest paths

Cloudlab — Overview is the single pane: a top row that answers is anything wrong, then endpoints, pollers, Vercel deployments and Cloudflare zones, then inventory and spend — and links out to each provider's console, because that is where fixing anything actually happens. Vercel deploys appear as annotations on the time axis, so a spike lines up with whatever caused it.

Grafana's own Linux Server integration dashboards are still there if you want them (Connections → Linux Server → Dashboards) and they go deeper on host internals — but they know nothing about the systemd units you listed in config.sh, which is the part this repo exists for. Fleet — Hosts & Units covers that, and its panels line up one-to-one with the rules in alerts/, so what pages you and what you look at afterwards agree.

Configuration

config.sh — your infrastructure (gitignored):

HOSTS=(
  "web-01|hetzner|caddy,postgresql"
  "vpn-edge|digitalocean|wireguard,fail2ban,ssh"
)

COLLECTOR_HOST="web-01"

CHECKS=(
  "my-api|https://api.example.com/health|railway"
  "marketing|https://example.com|vercel"
  "vpn-port|198.51.100.10:443|digitalocean|tcp_connect"
)

RAILWAY_SERVICES=(
  "my-api|production|RAILWAY_TOKEN_MY_API|deploy,http"
)
Field Meaning
ssh-target Anything ssh accepts — a ~/.ssh/config alias or user@host
provider Free-text label, so you can filter by platform in Grafana
units systemd services to watch (.service optional; alloy added for you)
address Full URL for HTTP checks; host:port for tcp_connect
module http_2xx (default), http_redirect, tcp_connect, icmp
token-env-var The name of the variable in .env holding that token
feeds deploy (app stdout), http (edge request logs)

COLLECTOR_HOST is the one host that does work not tied to a single server — probing endpoints and polling Railway. It replaces RAILWAY_COLLECTOR_HOST, which is still read if you have it set.

.env — secrets only (gitignored). Never written into a committed file; the installer places them on each host at mode 0600.

Scrape interval, poll cadence and memory budgets have sensible defaults. They're documented in config.example.sh if you want to change them.

Commands

Command Does
./bin/init Creates .env and config.sh from the examples
./bin/discover-units <host> Read-only: suggests a HOSTS line for a server
./bin/verify-credentials Probes Grafana Cloud. Installs nothing
./bin/setup Everything — hosts, Railway, dashboards, alerts
./bin/install-host [target] One host, or all of them
./bin/install-railway Railway shippers on the collector host
./bin/install-providers Provider API pollers on the collector host
./bin/install-dashboards [name] Pushes dashboards/*.json into Grafana
./bin/install-alerts Pushes alerts/*.yaml into the Cloud rule store
./bin/uninstall-host <target> Removes everything this repo put on one host

All idempotent. Re-run after editing config.sh.

Removing a host

Deleting a host from HOSTS stops this repo managing it — it does not stop the agent. Nothing scrapes your servers from outside, so a forgotten agent keeps pushing and keeps consuming active series with no sign of it anywhere. Remove it from config.sh, then:

./bin/uninstall-host old-box

It takes one host at a time, never the whole fleet, prints exactly what it will delete, and asks you to type the hostname back. Add --yes to skip the prompt in a script.

How it works

On each server, the installer puts Grafana Alloy in place — an agent that collects and pushes out. It sends host metrics and systemd unit health to Prometheus, and journal logs to Loki. Credentials live in /etc/default/alloy; the config itself is rendered from a template per host and contains no secrets.

For Railway, one of your servers acts as a collector. A systemd timer runs railway logs --json every 60s per service, writes to /var/log/railway/, and the same Alloy agent tails those files into Loki.

So the droplet does double duty: it monitors itself and collects for Railway.

One consequence worth knowing: your servers produce real metrics, while Railway produces logs only — request rate and latency are derived from the HTTP log feed at query time. That means Railway data is bound by Loki retention and can't be backfilled.

What you get

up{job="integrations/node_exporter"}
node_systemd_unit_state{name="postgresql.service", state="active"}
node_systemd_system_running                    # 0 = a unit on the host failed
{job="railway", service="my-api"}
{job="railway", log_kind="http"} | json | httpStatus >= 500

dashboards/fleet-hosts.json renders those first three as stat tiles, a sortable unit-state table, and disk/memory/CPU/TCP over time — filterable by provider and host. dashboards/railway-overview.json renders request rate, error rate, latency percentiles and slowest paths, broken out per service.

Seven alert rules in alerts/ cover the same ground: see DESIGN.md → Alert rules.

More

DESIGN.md — why it's built this way, the failure modes behind each decision, alert rules, known limits and troubleshooting.

Licence

MIT — see LICENSE.

About

Personal monitoring for personal projects

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages