Skip to main content

A BigQuery Cost Analysis CLI Tool

Project description

QueryGuard CLI 🛡️

The Forensic Auditor for your BigQuery Bill.

CI Python 3.12+ License: MIT Code Style: Black

QueryGuard (bqg) is a CLI tool that hunts down expensive BigQuery queries across your entire Google Cloud organization. It connects to the INFORMATION_SCHEMA, calculates exact costs based on regional pricing, and flags high-risk patterns like SELECT * or missing LIMIT clauses.

Stop guessing who spent the budget. Know.


demo


⚡ Features

  • 🌍 Global Auto-Discovery: Automatically scans your project to find active regions and queries them in parallel. No more guessing if data is in us-central1 or europe-west3.

  • 💸 Forensic Cost Analysis: Calculates costs based on the exact datacenter pricing (e.g., pricing Zurich queries at $8.75/TiB vs. US queries at $6.25/TiB).

  • 🚩 Risk Detection: Instantly flags bad habits:

    • SELECT * usage
    • Queries without LIMIT
    • Heavy scans (>100 GB)
    • Wrapper scripts vs. actual compute
  • 🤖 Bot Filtering: Use --humans-only to filter out service accounts and Looker bots, focusing strictly on manual engineering errors.

  • 🚀 High Performance: Uses multi-threaded execution to audit dozens of regions in seconds.


📦 Installation

Option 1: Using Pip

pip install queryguard-cli

Option 2: From Source (Poetry)

# Clone the repo
git clone git@github.com:mark-de-haan/query-guard-cli.git

# Navigate
cd queryguard-cli

# Install locally
poetry install

🚀 Quick Start

Ensure you are authenticated with Google Cloud:

gcloud auth application-default login

Run a forensic scan on your primary project for the last 7 days:

bqg scan --project my-gcp-project

Global scanning

Audit every active region globally to find hidden costs:

bqg scan --project my-gcp-project --global

🛠 Usage Guide

The scan Command

Flag Short Description
--project -p Required. The GCP Project ID to audit.
--global -g Auto-discover active regions and scan them all in parallel.
--region -r Scan a specific region (e.g., europe-west1). Ignored if --global is set.
--days -d Lookback window in days (Default: 7).
--humans-only Hides service accounts (e.g., gserviceaccount, monitoring) to find manual errors.
--limit -l Number of expensive queries to display (Default: 10).

Examples

Find who is running expensive queries manually:

bqg scan -p my-data-warehouse --global --humans-only --days 30

Audit a specific region for a deep dive

bqg scan -p my-data-warehouse -r europe-west3

🤝 Contributing

Contributions are welcome! Please check the issues page.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feat/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feat/AmazingFeature)
  5. Open a Pull Request

📄 License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

queryguard_cli-0.2.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

queryguard_cli-0.2.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file queryguard_cli-0.2.0.tar.gz.

File metadata

  • Download URL: queryguard_cli-0.2.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.0 CPython/3.12.12 Linux/6.11.0-1018-azure

File hashes

Hashes for queryguard_cli-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4ede4c7ae55f1138ec326b75bcd4575c95f4df25d4b337cbe13059f289e0302f
MD5 4c85bf3a402d26e92f60a41afd560e5c
BLAKE2b-256 2ff6d9767c1b20bbdbacc1835b5bb229d3441571358d79b4fc6ed3e3480439e4

See more details on using hashes here.

File details

Details for the file queryguard_cli-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: queryguard_cli-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.0 CPython/3.12.12 Linux/6.11.0-1018-azure

File hashes

Hashes for queryguard_cli-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7311c5e826fb3939ec54500f4a52497db008b5d03bbb1622812da8b63bdaf36
MD5 8a839b813227f7145645ddbae986c7fe
BLAKE2b-256 ed199d9f4a90ac9e0e3966cf0b326e75e1ca30a80474c5da2209eabefc9bc1be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page