Skip to content

stratastor/gcp-discovery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GCP Infrastructure Discovery Tool

A tool to discover and analyze compute and storage resources in Google Cloud Platform (GCP) projects. This tool provides rudimentary insights into virtual machines, persistent disks, snapshots, and generates cost estimates and potential savings projections.

Features

  • VM Discovery: Collects information about all VM instances including:

    • vCPU count and memory allocation
    • Machine type and family (e2, n1, n2, etc.)
    • Network configuration (IPs, NICs, network tier)
    • Operating system detection
    • Disk configuration (boot vs data disks)
    • Preemptible status
  • Disk Analysis: Detailed persistent disk information including:

    • Disk type (pd-balanced, pd-ssd, pd-standard)
    • Size and attachment status
    • Boot disk identification
    • Provisioned IOPS and throughput
  • Snapshot Tracking: Complete snapshot inventory with size and source information

  • Cost Analysis:

    • Current monthly/annual cost estimates based on GCP pricing
    • Projected savings with compression optimization
  • Multiple Export Formats:

    • Console output with formatted summary
    • CSV files for detailed analysis and reporting

Prerequisites

  1. Go 1.19 or later installed on your system
  2. GCP Project with compute resources
  3. Authentication: Run gcloud auth application-default login to authenticate
  4. Required GCP APIs: Compute Engine API must be enabled
  5. Permissions: Read-only access to:
    • compute.instances.list
    • compute.disks.list
    • compute.snapshots.list
    • compute.machineTypes.get

Installation

Option 1: Build from Source

git clone <repository-url>
cd probe
go build -o gcp_discovery gcp_discovery.go

Option 2: Run Directly

go run gcp_discovery.go <project-id>

Usage

./gcp_discovery <project-id>

Or run directly:

go run gcp_discovery.go <project-id>

Example

./gcp_discovery my-gcp-project-123

Sample Output

🔍 Discovering infrastructure for project: t-strata-475113-r6
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📊 Collecting VM instances...
   Found 1 VMs
💾 Collecting persistent disks...
   Found 1 disks
📸 Collecting snapshots...
   Found 0 snapshots

📈 INFRASTRUCTURE SUMMARY
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

🖥️  Virtual Machines:
   Total VMs:         1
   Production:        0
   Staging:           0
   Development:       0
   Other:             1
   Preemptible:       0
   Total vCPUs:       2
   Total Memory:      1 GB

💾 Persistent Disks:
   Total Disks:       1
   Total Capacity:    10 GB (0.01 TB)
   Boot Disks:        10 GB (0.01 TB)
   Data Disks:        0 GB (0.00 TB)

   By Disk Type:
   pd-balanced:       10 GB (0.01 TB)
   pd-ssd:            0 GB (0.00 TB)
   pd-standard:       0 GB (0.00 TB)

📸 Snapshots:
   Total Snapshots:   0
   Total Size:        0 GB (0.00 TB)

💰 ESTIMATED MONTHLY COSTS (GCP Pricing):
   pd-balanced:       $1.00
   pd-ssd:            $0.00
   pd-standard:       $0.00
   Snapshots:         $0.00
   ─────────────────────────
   TOTAL:             $1.00/month
   ANNUAL:            $12.00/year

🎯 PROJECTED STRATA SAVINGS (2.5x compression):
   Compressed Size:   0.00 TB (from 0.01 TB)
   New Monthly Cost:  $0.40
   Monthly Savings:   $0.60
   Annual Savings:    $7.20
   Reduction:         60.0%

💡 ADDITIONAL STRATA OPTIMIZATIONS:

   📊 Over-Provisioning Waste:
      Estimated buffer:       30% (industry typical)
      Avg utilization:        70%
      Wasted capacity:        0.90 GB (0.00 TB)
      Monthly waste cost:     $0.09
      Annual waste:           $1.08
      → Strata eliminates over-provisioning via online expansion

   👨‍💻 DevOps Operational Efficiency:
      Current weekly hours:
        - Snapshot management:    0.1 hours (1 disks × 3 min)
        - Env provisioning:       4.0 hours
        - Storage expansions:     1.0 hours
      Total weekly hours:       5.0 hours
      At $50/hour:             $252.50/week = $1093.33/month

      With Strata (90% automation):
      New weekly hours:         0.5 hours
      Monthly savings:          $983.99
      Annual savings:           $11807.91
      → Single pane management for 1 disks

✅ Discovery complete! Check the generated CSV files:
   - csv/infrastructure_summary.csv
   - csv/vms_detail.csv
   - csv/disks_detail.csv
   - csv/snapshots_detail.csv

Generated CSV Files

1. infrastructure_summary.csv

High-level metrics including total VMs, vCPUs, memory, disk capacity, and costs.

2. vms_detail.csv

Detailed VM information with columns:

  • Zone
  • VM Name
  • Machine Type
  • Machine Family
  • Status
  • vCPUs
  • Memory (GB)
  • Boot Disk (GB)
  • Data Disks (GB)
  • Total Disk Size (GB)
  • NIC Count
  • Internal IP
  • External IP
  • Network Tier
  • OS
  • Preemptible
  • Environment

3. disks_detail.csv

Comprehensive disk information:

  • Zone
  • Disk Name
  • Size (GB)
  • Type
  • Status
  • Attached To VM
  • Boot Disk (Yes/No)
  • Provisioned IOPS
  • Provisioned Throughput (MB/s)
  • Created At

4. snapshots_detail.csv

Snapshot inventory:

  • Snapshot Name
  • Source Disk
  • Size (GB)
  • Storage Bytes
  • Created At

Environment Classification

The tool automatically classifies VMs into environments based on:

  1. GCP labels (environment or env)
  2. Naming conventions (containing "prod", "staging", "dev", etc.)

Cost Estimates

Cost calculations are based on standard GCP pricing (as of 2025):

  • pd-balanced: $0.10/GB/month
  • pd-ssd: $0.17/GB/month
  • pd-standard: $0.04/GB/month
  • Snapshots: $0.026/GB/month

Note: Actual costs may vary based on region, committed use discounts, and current GCP pricing.

Machine Type Support

The tool supports automatic CPU/Memory detection for common machine families:

  • E2 series (e2-micro, e2-small, e2-medium, e2-standard-, e2-highmem-, e2-highcpu-*)
  • N1 series (n1-standard-, n1-highmem-, n1-highcpu-*)
  • N2 series (n2-standard-, n2-highmem-, n2-highcpu-*)

For custom machine types or unlisted configurations, the tool fetches specifications directly from the GCP API.

Troubleshooting

Authentication Issues

# Re-authenticate with GCP
gcloud auth application-default login

Missing Permissions

Ensure your account has at least roles/compute.viewer or equivalent read permissions.

API Not Enabled

# Enable Compute Engine API
gcloud services enable compute.googleapis.com --project=<project-id>

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

Support

For questions or issues, please open an issue in the repository.

About

GCP Infrastructure Discovery Tool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages