{"slug": "zombie-sweep-on-google-cloud-a-daily-waste-report-on-alloydb-express-with-a-bill", "title": "Zombie Sweep on Google Cloud: A Daily Waste Report on AlloyDB Express, With a Database Bill You Can Predict", "summary": "A developer published zombie-sweep-gcp, an open-source tool that runs a daily sweep for unused Google Cloud resources using Cloud Scheduler, Workflows, Cloud Run and AlloyDB Express. Each sweep runs 20 checks from the zombiescan-gcp scanner alongside 7 of Google's Recommender idle-resource checks, stores findings in PostgreSQL, and has an ADK agent with MCP Toolbox write a daily briefing in which every number comes from SQL. The author caps the database cost by using AlloyDB Express, whose 2 compute unit and 20 GB limits put the worst-case monthly bill at $89.95 for a 1 vCPU instance, with the free tier covering the sweep's brief daily usage.", "body_md": "This article provides a step by step guide to building a daily sweep for unused Google Cloud resources with Cloud Scheduler, Workflows, Cloud Run and AlloyDB Express. Each sweep runs zombiescan's checks beside Google's Recommender, stores every finding in PostgreSQL, and an ADK agent with MCP Toolbox writes a daily briefing in which every number comes from SQL.\n\nRepository: [https://github.com/xbill9/zombie-sweep-gcp](https://github.com/xbill9/zombie-sweep-gcp)\n\nA tool that hunts for surprise cloud bills should not create one. AlloyDB Express is the database that makes that easy to promise: within its free tier the database costs $0.00 a month for this workload, and even with every limit maxed out, its bill has a ceiling you can compute before you create it.\n\nAlloyDB Express is a preview configuration of AlloyDB for PostgreSQL built for prototypes and small workloads. Three properties from its documentation decide the bill:\n\nA database that cannot grow past 2 compute units or 20 GB has a worst case. Priced from the Cloud Billing Catalog API for us-west1, with the instance never idle and storage full:\n\n| Instance | Compute, 730 hours | Storage, 20 GB | Most it can bill in a month | \n|---|---|---|---|\n| 1 vCPU (this sweep) | $83.95 | $6.00 | **$89.95** | \n| 2 vCPU | $167.90 | $6.00 | **$173.90** | \n\nThat is the ceiling for a database left busy around the clock. A daily sweep keeps it awake for minutes a day, and the free tier covers that: each month includes 50 compute units and 2 GB of storage per billing account for the first 12 months.\n\nA zombie resource still bills and no longer does any work. A stopped VM whose disks still cost money, a snapshot of a disk that was deleted, a static IP attached to nothing, a secret nobody has updated in months.\n\nThey collect in projects used for one experiment, in zones you tried once, and behind instances that were stopped and forgotten instead of deleted.\n\nPartly. Recommender has idle-resource recommenders for VMs, persistent disks, IP addresses, custom images, Cloud SQL instances and GKE clusters. This sweep queries 7 of them.\n\nzombiescan-gcp is an open-source scanner with 20 checks, among them orphaned snapshots, stale Artifact Registry repositories, stale secrets, Cloud NAT gateways serving nothing, Filestore instances nothing can mount, unused firewall rules and subnets, Cloud DNS zones and uptime checks for deleted resources. Zombie Sweep runs both sources in every sweep and compares them resource by resource, so the report shows which source found what.\n\n`beta` component for AlloyDB Express`git` and `python3` on the machine that deploys\n\n```\nCloud Scheduler  zombie-sweep-daily, 06:00 UTC\n      |\nWorkflows  zombie-sweep\n      |-- Cloud Run job  MODE=zombiescan   --+\n      |-- Cloud Run job  MODE=recommender  --+--> AlloyDB Express  (runs, findings)\n      |-- POST /briefing  (signed JWT, through IAP)          ^\n      |        Cloud Run service: ADK agent + MCP Toolbox ---+  read-only SQL\n      '-- Cloud Run job  MODE=finish  (stores the briefing, closes the run)\n```\n\nOne Cloud Run job image runs in three modes. One AlloyDB Express instance holds two tables and two views. One Cloud Run service holds the agent and its SQL tools.\n\nThe Express commands from the documentation, with this project's names:\n\n```\ngcloud beta alloydb clusters create zombie-sweep --region=us-west1 \\\n    --password=\"$DB_PASSWORD\" --enable-express\ngcloud beta alloydb instances create zombie-sweep-primary --cluster=zombie-sweep \\\n    --region=us-west1 --instance-type=PRIMARY --cpu-count=1 --enable-public-dns\nCreating cluster...\n.......done.\n\nreal    0m3.463s\nCreating instance...\n.......done.\n\nreal    0m3.147s\n```\n\nus-west1 is the only US region Express supports. The instance reports `PostgreSQL 18.4` and `max_connections 200`, both fixed by Express.\n\nIAM database login needs one database flag:\n\n```\ngcloud alloydb instances update zombie-sweep-primary --cluster=zombie-sweep \\\n    --region=us-west1 --database-flags=alloydb.iam_authentication=on\n```\n\n`runs` holds one row per sweep, keyed by the Workflows execution id, with the agent's briefing. `findings` holds one row per resource per source:\n\n```\nCREATE TABLE IF NOT EXISTS findings (\n    run_id         text NOT NULL REFERENCES runs(run_id) ON DELETE CASCADE,\n    source         text NOT NULL CHECK (source IN ('zombiescan', 'recommender')),\n    project        text NOT NULL,\n    check_id       text NOT NULL,\n    resource       text NOT NULL,\n    monthly_cost   numeric(12, 4) NOT NULL DEFAULT 0,\n    ...\n    PRIMARY KEY (run_id, source, project, check_id, resource)\n);\n```\n\nThe two sources name the same resource differently. zombiescan stores `w1`; Recommender stores `//compute.googleapis.com/projects/p/regions/us-central1/addresses/w1`. The view `findings_keyed` reduces both to (project, kind, name), and `findings_compared` adds `found_by_both`:\n\n```\nCREATE OR REPLACE VIEW findings_compared AS\nSELECT k.*,\n       EXISTS (SELECT 1 FROM findings_keyed o\n               WHERE o.run_id = k.run_id AND o.source <> k.source\n                 AND o.project = k.project AND o.kind = k.kind AND o.name = k.name) AS found_by_both\nFROM findings_keyed k;\n```\n\n`python3 sql/apply.py` applies the schema and views from a workstation through the AlloyDB Python connector.\n\n`sweep/job.py` runs one source against one project and prints one JSON line:\n\n`MODE=zombiescan` runs zombiescan-gcp's 20 checks and prices each finding from the public price list`MODE=recommender` reads the 7 idle-resource recommenders at every zone, region or global location each one uses`MODE=finish` stores the briefing and marks the run `DONE`\nEach source mode deletes and re-inserts its own rows for the run, so a retried job leaves no duplicates. In Cloud Run the job logs in to AlloyDB with IAM database authentication as its service account: no password in the job, and a `zombie_writer` role that can write findings and close runs.\n\nThe two sources run as parallel branches, each one a Cloud Run job execution through the Workflows connector:\n\n```\n- sources:\n    parallel:\n      for:\n        value: mode\n        in: [\"zombiescan\", \"recommender\"]\n        steps:\n          - run_source:\n              call: googleapis.run.v2.projects.locations.jobs.run\n```\n\nThen the workflow posts the run id to the agent's `/briefing` route and runs the job a third time with `MODE=finish` to store what came back. A failed briefing does not fail the sweep; the run closes without one.\n\nThe agent's Cloud Run service sits behind Identity-Aware Proxy, so a person opens the report page with a Google sign-in. IAP with the Google-managed OAuth client accepts a JWT signed by a service account with `aud` set to the URL, so the workflow signs one as itself and sends it as a bearer token:\n\n```\n- claims:\n    assign:\n      - now: ${int(sys.now())}\n      - claims:\n          iss: ${sys.get_env(\"WF_SA\")}\n          sub: ${sys.get_env(\"WF_SA\")}\n          aud: ${sys.get_env(\"AGENT_URL\") + \"/*\"}\n          iat: ${now}\n          exp: ${now + 900}\n- sign:\n    call: http.post\n    args:\n      url: ${\"https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/\" + sys.get_env(\"WF_SA\") + \":signJwt\"}\n      auth: {type: OAuth2}\n      body:\n        payload: ${json.encode_to_string(claims)}\n    result: jwt\n```\n\nThe workflow's service account holds Service Account Token Creator on itself only, and `roles/iap.httpsResourceAccessor` on the agent. Workflows expressions take no map literals, so the claims are built in an `assign` step first.\n\nThe agent is a FastAPI app running an ADK `LlmAgent` on Gemini through Vertex AI. Its only access to the data is MCP Toolbox for Databases, running as a second container in the same Cloud Run service on `127.0.0.1:5000`. Toolbox connects to AlloyDB with IAM login as the agent's service account, which holds a read-only role.\n\nToolbox exposes 8 SQL tools: `list_runs`, `totals`, `top_waste`, `count_findings`, `only_one_source`, `diff_vs_previous`, `finding_history` and `run_briefing`. The tool definitions live in Secret Manager and are mounted into the Toolbox container as a file.\n\nThe agent serves four routes: `GET /` for the report page, `POST /ask` for questions, `POST /briefing` for the workflow, and `GET /health`, because Cloud Run reserves `/healthz`.\n\nThe agent is told never to add, count, average or compare numbers itself. Every count and sum is a SQL tool, and `count_findings` takes filters and returns the exact answer:\n\n```\nname: count_findings\ntype: postgres-sql\nsource: findings-db\nannotations: {readOnlyHint: true}\ndescription: |\n  Exact count, total, minimum and maximum monthly cost of the findings in one\n  run that match every filter given. Any filter left out matches everything.\n  Use this for any \"how many\" or \"how much\" question; never count rows yourself.\n  min_monthly_cost is inclusive (>=).\nstatement: |\n  ...\n  SELECT (SELECT id FROM r) AS run_id, count(*) AS findings,\n         round(coalesce(sum(monthly_cost), 0), 2)::float8 AS total_monthly_cost,\n         round(min(monthly_cost), 2)::float8 AS min_monthly_cost,\n         round(max(monthly_cost), 2)::float8 AS max_monthly_cost\n  FROM findings_compared\n  WHERE run_id = (SELECT id FROM r)\n    AND ($5::float8 IS NULL OR monthly_cost >= $5::float8)\n    ...\n```\n\nThe briefing is then checked figure by figure against SQL run directly on the database, with no model involved: `.claude/skills/check-briefing/check.py` prints the briefing beside the counts, sums and per-check totals PostgreSQL computes for the same run.\n\nThe Toolbox source is declared `readOnly: true`. With that set, Toolbox keeps a `postgres-sql` tool only when the tool declares `annotations: {readOnlyHint: true}`. All 8 tools here carry it. A new tool without it does not appear in the agent's tool list.\n\n```\npython3 sql/apply.py              # schema and views\ndeploy/deploy.sh                  # service accounts, IAM, job, agent, IAP, workflow, schedule\npython3 sql/apply.py grants.sql   # database roles for the IAM users deploy.sh created\ndeploy/deploy.sh run              # one sweep now\nSUCCEEDED   {\"run_id\":\"854715f3-1beb-4f35-8f4e-30f9f02f14d3\"}\n```\n\n`deploy.sh` is idempotent and safe to run again. It also keeps only the newest version of the Toolbox secret enabled and sets an Artifact Registry cleanup policy that keeps the newest 3 images, so repeated deploys do not leave a growing pile of billable versions behind.\n\nThe schedule is `0 6 * * *` in UTC. Across 11 successful sweeps, each took 54 to 127 seconds end to end.\n\nRun `854715f3`, 2026-11-20, one project:\n\n| Source | Findings | Monthly | \n|---|---|---|\n| zombiescan | 27 | $128.86 | \n| Recommender | 1 | $7.30 | \n\nOne resource was found by both: a static IP address, `w1`, at $7.30 a month. Everything else came from zombiescan alone:\n\n| Check | Findings | Monthly | \n|---|---|---|\n| stopped-instance | 5 | $65.28 | \n| orphaned-snapshot | 5 | $53.19 | \n| stale-artifact-repository | 4 | $2.55 | \n| stale-secret | 8 | $0.54 | \n| unmanaged-gcs-bucket | 2 | $0.00 | \n| unused-firewall-rule | 2 | $0.00 | \n\nThe agent's briefing for that run, as stored in `runs.briefing`:\n\n```\nTotals by source: zombiescan has 27 findings costing 128.86 dollars a month; recommender has 1 findings costing 7.3 dollars a month.\nTop waste: snapshot-w5-opt (53.19), windows (23.94), debian13b (13.06), w1 (10.88), and w2 (10.88).\nDiff vs previous run fe2aac43-c1a1-49d4-8645-1afbd80ff204: 28 findings costing 136.16 are unchanged.\n```\n\nEvery figure in it matches the SQL computed for the same run.\n\nFrom the AlloyDB Express documentation's own comparison:\n\n|  | AlloyDB Express | AlloyDB | \n|---|---|---|\n| Compute when idle | 🥇 scales to zero | always provisioned | \n| Pricing | 🥇 usage-based, monthly free tier | provisioned hourly, 30-day trial | \n| Largest bill possible | 🥇 bounded: 2 vCPU, 20 GB | grows with the cluster | \n| Compute | 1 or 2 vCPU, one zonal instance | 🥇 up to 288 vCPUs, read pools | \n| Storage | up to 20 GB | 🥇 up to 128 TB | \n| Backups, PITR, HA | ❌ none | 🥇 yes | \n| SLA | ❌ none | 🥇 99.99% for regional HA | \n| PostgreSQL versions | 18 | 🥇 14 to 18 | \n| Terraform | ❌ not supported | 🥇 yes | \n\n`docs/cost.py` prices the sweep from the Cloud Billing Catalog API and measures usage from the project: 37 Cloud Run job executions averaging 24.4 seconds, 7 briefings averaging 31.6 seconds, and the database at 17880855 bytes. For 30 daily sweeps:\n\n| Item | List price | With the Express free tier | \n|---|---|---|\n| AlloyDB Express compute, 7.95 to 8.56 CU-hours | $0.91 to $0.98 | 🥇 $0.00 | \n| AlloyDB Express storage | $0.0050 | 🥇 $0.00 | \n| Cloud Run job, 3 executions a sweep | $0.0439 | $0.0439 | \n| Cloud Run agent, 1 briefing a sweep | $0.0491 | $0.0491 | \n| **Total, upper end** | **$1.08** | **$0.09** | \n\nAlloyDB compute hours are each sweep's duration plus the 15-minute idle period before the instance pauses. The 50 free compute units leave 41.44 a month after the sweeps: room for about 166 more wake-ups from people opening the report page or asking the agent a question.\n\nThe database line stays at $0.00 for as long as the free tier lasts, and after that it has the ceiling worked out above: $89.95 a month for this 1 vCPU instance if it never sleeps at all.\n\nFor a scheduled job that writes a few megabytes a day and is read now and then, use AlloyDB Express. It sleeps between sweeps, its storage cannot grow past 20 GB, and its largest possible bill is a number you can compute before you create it.\n\nMove to full AlloyDB when the data needs backups, high availability or an SLA. The upgrade is in place and keeps the connection string; there is no way back to Express afterwards.\n\nThe goal of this article was to run a daily sweep for unused Google Cloud resources without adding a database bill to watch. The key to the solution was AlloyDB Express, which scales to zero between sweeps, caps its own storage, and fits this workload inside its free tier, with every number in the report computed by SQL. The results on one project were:\n\nScope: one Google Cloud project in us-west1, swept daily from 2026-11-15 to 2026-11-20, one 1 vCPU AlloyDB Express instance. Costs are estimates from Cloud Billing Catalog list prices and measured run times. AlloyDB active hours assume the 15-minute idle period from the launch post. They exclude Gemini, Secret Manager, Workflows, Cloud Scheduler, Artifact Registry, Cloud Build and logging. The sweep is read-only and deletes nothing.\n\nThe strategy for using AlloyDB Express as the store for a daily waste sweep was validated with an incremental step by step approach.", "url": "https://wpnews.pro/news/zombie-sweep-on-google-cloud-a-daily-waste-report-on-alloydb-express-with-a-bill", "canonical_source": "https://dev.to/gde/zombie-sweep-on-google-cloud-a-daily-waste-report-on-alloydb-express-with-a-database-bill-you-can-305g", "published_at": "2026-11-20 20:01:04+00:00", "updated_at": "2026-11-20 20:15:42.811352+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-infrastructure"], "entities": ["Google Cloud", "AlloyDB Express", "Cloud Run", "Cloud Scheduler", "Workflows", "zombiescan-gcp", "MCP Toolbox", "Google Recommender"], "also_reported_by": [], "takeaway": "AlloyDB Express's fixed 2 compute unit and 20 GB limits cap a 1 vCPU instance at $89.95 a month worst case, and its 50 compute units plus 2 GB monthly free tier covers a sweep that wakes the database for only minutes a day.", "recommendation": {"advice": "Size a daily agent workload on AlloyDB Express against its fixed 2 vCPU/20 GB ceiling and free tier before provisioning, so the database bill is computable in advance.", "playbook": "llm-cost", "playbook_url": "https://wpnews.pro/playbooks/llm-cost"}, "alternates": {"html": "https://wpnews.pro/news/zombie-sweep-on-google-cloud-a-daily-waste-report-on-alloydb-express-with-a-bill", "markdown": "https://wpnews.pro/news/zombie-sweep-on-google-cloud-a-daily-waste-report-on-alloydb-express-with-a-bill.md", "text": "https://wpnews.pro/news/zombie-sweep-on-google-cloud-a-daily-waste-report-on-alloydb-express-with-a-bill.txt", "jsonld": "https://wpnews.pro/news/zombie-sweep-on-google-cloud-a-daily-waste-report-on-alloydb-express-with-a-bill.jsonld"}}