vpc

package
v0.29.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

README

GCP VPC Networking Collector

This collector provides pricing metrics for Google Cloud Platform (GCP) VPC networking services. It fetches real-time pricing data from the GCP Cloud Billing API and exports Prometheus metrics for cost monitoring and optimization.

Supported Services

Cloud NAT Gateway
  • Service: Network Address Translation gateway for private instances
  • Metrics:
    • cloudcost_gcp_vpc_nat_gateway_hourly_rate_usd_per_hour
    • cloudcost_gcp_vpc_nat_gateway_data_processing_usd_per_gb
  • Equivalent to: AWS NAT Gateway
  • Pricing: Global pricing applies to all regions
    • Gateway: $0.045 per hour
    • Data Processing: $0.045 per GB
VPN Gateway
  • Service: Site-to-site VPN connections
  • Metric: cloudcost_gcp_vpc_vpn_gateway_hourly_rate_usd_per_hour
  • Equivalent to: AWS VPN Gateway
  • Pricing: Regional pricing varies ($0.05-$0.08 per hour)
Private Service Connect (PSC)
  • Service: Private endpoints for accessing Google Cloud services and third-party services
  • Metrics:
    • cloudcost_gcp_vpc_private_service_connect_endpoint_hourly_rate_usd_per_hour{endpoint_type}
    • cloudcost_gcp_vpc_private_service_connect_data_processing_usd_per_gb
  • Equivalent to: AWS VPC Endpoints
  • Endpoint Types:
    • consumer: For consuming services via PSC
    • partner: For third-party service integrations
  • Pricing: Global pricing applies to all regions
    • Endpoint: $0.01 per hour per endpoint type
    • Data Processing: $0.01 per GB

Configuration

To enable the GCP VPC collector, add VPC to your GCP services configuration:

gcp:
  services: ["GCS", "GKE", "CLB", "VPC"]  # Add VPC here
  projects: "project1,project2,project3"

Or via command line:

--gcp.services=GCS,GKE,CLB,VPC

Metrics Labels

All metrics include the following labels:

  • region: GCP region (e.g., us-central1, europe-west1)
  • project: GCP project ID

Pricing Data Source

  • API: GCP Cloud Billing API
  • Refresh Interval: 24 hours (configurable via PriceRefreshInterval)
  • Services Queried: "Networking"
  • Error Handling: Logs warnings for missing pricing data

Global vs Regional Pricing

GCP uses two types of pricing for VPC services:

Global Pricing
  • Cloud NAT Gateway: Same price applies to all regions worldwide
  • Pricing data has empty Regions array in the GCP Billing API
  • The collector applies global rates to all regions automatically
Regional Pricing
  • VPN Gateway: Different prices per region
  • Pricing data includes specific region in the GCP Billing API
  • The collector uses region-specific rates when available

Example Grafana Queries

Cloud NAT Gateway Hourly Rate
cloudcost_gcp_vpc_nat_gateway_hourly_rate_usd_per_hour
Cloud NAT Data Processing Rate
cloudcost_gcp_vpc_nat_gateway_data_processing_usd_per_gb
VPN Gateway Cost by Region
cloudcost_gcp_vpc_vpn_gateway_hourly_rate_usd_per_hour
Most Expensive VPN Regions
topk(10, cloudcost_gcp_vpc_vpn_gateway_hourly_rate_usd_per_hour)
Private Service Connect Endpoint Costs by Type
cloudcost_gcp_vpc_private_service_connect_endpoint_hourly_rate_usd_per_hour
Private Service Connect Data Processing Rate
cloudcost_gcp_vpc_private_service_connect_data_processing_usd_per_gb
All VPC Costs for a Specific Project
{__name__=~"cloudcost_gcp_vpc_.*",project="my-project"}
Total VPC Networking Costs
sum(cloudcost_gcp_vpc_nat_gateway_hourly_rate_usd_per_hour) +
sum(cloudcost_gcp_vpc_vpn_gateway_hourly_rate_usd_per_hour) +
sum(cloudcost_gcp_vpc_private_service_connect_endpoint_hourly_rate_usd_per_hour)

Required Permissions

The GCP service account needs the following IAM roles:

  • roles/billing.viewer - To access Cloud Billing API
  • roles/compute.viewer - To access Compute Engine API for region information

Limitations

The following VPC services do not have pricing exposed through the GCP Billing API:

  • External IP Addresses (Static/Ephemeral with non-zero cost)
  • Cloud Router (free service, charges only apply to NAT/VPN traffic)

These services would require manual configuration or alternative pricing sources. For comprehensive cost data, consider using GCP Cloud Billing Export to BigQuery.

Note: External IP addresses may have zero cost in certain cases (e.g., attached to running instances), which is different from being unavailable in the API.

Troubleshooting

No Metrics Appearing
  1. Check if VPC is enabled in your configuration
  2. Verify GCP service account permissions
  3. Check logs for pricing API errors
  4. Ensure projects are correctly configured
Authentication Issues
  • Ensure GOOGLE_APPLICATION_CREDENTIALS environment variable is set
  • Verify service account has required billing permissions
  • Check project access permissions

Documentation

Index

Constants

View Source
const (
	// Main service patterns
	CloudNATPattern              = "cloud nat"
	NATPattern                   = "nat"
	VPNGatewayPattern            = "Cloud VPN"
	VPNUsageType                 = "VPN"
	PrivateServiceConnectPattern = "private service connect"

	// Sub-patterns for categorization
	DataProcessingPattern = "data processing"
	DataProcessedPattern  = "data processed"
	GatewayPattern        = "gateway"
	UptimePattern         = "uptime"

	// PSC endpoint type patterns
	PartnerPattern       = "partner"
	ConsumerPattern      = "consumer"
	RegionalPattern      = "regional"
	APIPattern           = "api"
	InterfacesPattern    = "interfaces"
	GKEPattern           = "gke"
	GoogleManagedPattern = "google managed"
)
View Source
const PriceRefreshInterval = 24 * time.Hour

Variables

View Source
var (
	CloudNATGatewayHourlyGaugeDesc = utils.GenerateDesc(
		cloudcostexporter.MetricPrefix,
		subsystem,
		"nat_gateway_hourly_rate_usd_per_hour",
		"Hourly cost of Cloud NAT Gateway by region and project. Cost represented in USD/hour",
		[]string{"region", "project"},
	)
	CloudNATDataProcessingGaugeDesc = utils.GenerateDesc(
		cloudcostexporter.MetricPrefix,
		subsystem,
		"nat_gateway_data_processing_usd_per_gb",
		"Data processing cost of Cloud NAT Gateway by region and project. Cost represented in USD/GB",
		[]string{"region", "project"},
	)

	VPNGatewayHourlyGaugeDesc = utils.GenerateDesc(
		cloudcostexporter.MetricPrefix,
		subsystem,
		"vpn_gateway_hourly_rate_usd_per_hour",
		"Hourly cost of VPN Gateway by region and project. Cost represented in USD/hour",
		[]string{"region", "project"},
	)

	PrivateServiceConnectEndpointHourlyGaugeDesc = utils.GenerateDesc(
		cloudcostexporter.MetricPrefix,
		subsystem,
		"private_service_connect_endpoint_hourly_rate_usd_per_hour",
		"Hourly cost of Private Service Connect endpoints by region, project, and type. Cost represented in USD/hour",
		[]string{"region", "project", "endpoint_type"},
	)
	PrivateServiceConnectDataProcessingGaugeDesc = utils.GenerateDesc(
		cloudcostexporter.MetricPrefix,
		subsystem,
		"private_service_connect_data_processing_usd_per_gb",
		"Data processing cost of Private Service Connect by region and project. Cost represented in USD/GB",
		[]string{"region", "project"},
	)
)

Functions

This section is empty.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector implements provider.Collector for GCP VPC metrics

func New

func New(ctx context.Context, config *Config, gcpClient client.Client) (*Collector, error)

New creates a new VPC collector and starts periodic pricing refresh

func (*Collector) Collect

func (c *Collector) Collect(ctx context.Context, ch chan<- prometheus.Metric) error

Collect implements the Prometheus Collector interface

func (*Collector) Describe

func (c *Collector) Describe(ch chan<- *prometheus.Desc) error

Describe sends metric descriptors to the channel

func (*Collector) Name

func (c *Collector) Name() string

Name returns the name of the collector

func (*Collector) Regions added in v0.28.1

func (c *Collector) Regions() []string

func (*Collector) Register

func (c *Collector) Register(registry provider.Registry) error

Register registers the collector with the provider registry

type Config

type Config struct {
	Projects       string
	ScrapeInterval time.Duration
	Logger         *slog.Logger
}

Config holds configuration for the VPC collector

type VPCGlobalPricing

type VPCGlobalPricing struct {
	CloudNATGatewayRates                     map[string]float64
	CloudNATDataProcessingRates              map[string]float64
	PrivateServiceConnectEndpointRates       map[string]map[string]float64
	PrivateServiceConnectDataProcessingRates map[string]float64
}

VPCGlobalPricing holds global pricing that applies to all regions

func NewVPCGlobalPricing

func NewVPCGlobalPricing() *VPCGlobalPricing

NewVPCGlobalPricing creates a new VPCGlobalPricing instance

type VPCPricingMap

type VPCPricingMap struct {
	// contains filtered or unexported fields
}

VPCPricingMap manages pricing data for all GCP VPC services across regions

func NewVPCPricingMap

func NewVPCPricingMap(logger *slog.Logger, gcpClient client.Client) *VPCPricingMap

NewVPCPricingMap creates a new VPCPricingMap instance

func (*VPCPricingMap) GetCloudNATDataProcessingRate

func (pm *VPCPricingMap) GetCloudNATDataProcessingRate(region string) (float64, error)

GetCloudNATDataProcessingRate returns the data processing rate for Cloud NAT in the specified region

func (*VPCPricingMap) GetCloudNATGatewayHourlyRate

func (pm *VPCPricingMap) GetCloudNATGatewayHourlyRate(region string) (float64, error)

GetCloudNATGatewayHourlyRate returns the hourly rate for Cloud NAT Gateway in the specified region

func (*VPCPricingMap) GetPrivateServiceConnectDataProcessingRate

func (pm *VPCPricingMap) GetPrivateServiceConnectDataProcessingRate(region string) (float64, error)

GetPrivateServiceConnectDataProcessingRate returns the data processing rate for Private Service Connect

func (*VPCPricingMap) GetPrivateServiceConnectEndpointRates

func (pm *VPCPricingMap) GetPrivateServiceConnectEndpointRates(region string) (map[string]float64, error)

GetPrivateServiceConnectEndpointRates returns endpoint rates by type for the specified region

func (*VPCPricingMap) GetRegionPricing

func (pm *VPCPricingMap) GetRegionPricing(region string) (*VPCRegionPricing, error)

GetRegionPricing returns pricing data for a specific region

func (*VPCPricingMap) GetVPNGatewayHourlyRate

func (pm *VPCPricingMap) GetVPNGatewayHourlyRate(region string) (float64, error)

GetVPNGatewayHourlyRate returns the hourly rate for VPN Gateway in the specified region

func (*VPCPricingMap) Refresh

func (pm *VPCPricingMap) Refresh(ctx context.Context) error

Refresh fetches and updates pricing data for all VPC services

type VPCRegionPricing

type VPCRegionPricing struct {
	CloudNATGatewayRates                     map[string]float64
	CloudNATDataProcessingRates              map[string]float64
	VPNGatewayRates                          map[string]float64
	PrivateServiceConnectEndpointRates       map[string]map[string]float64
	PrivateServiceConnectDataProcessingRates map[string]float64
}

VPCRegionPricing holds pricing data for all VPC services in a specific region

func NewVPCRegionPricing

func NewVPCRegionPricing() *VPCRegionPricing

NewVPCRegionPricing creates a new VPCRegionPricing instance

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL