# Google Cloud

> Reads only Google Cloud answers: which data has arrived, resources by type, region and project, idle resources, label coverage, utilization, budgets, and what LevelFour's service account can read.

Source: https://docs.levelfour.ai/resources/google-cloud


These methods read what LevelFour knows about your Google Cloud estate beyond the bill: resources, utilization, budgets and access. Cost, recommendations and savings for Google Cloud use the same methods as every other provider, with `gcp` as the provider ID; [Costs](/resources/costs#google-cloud-credits) covers the credits basis they take. Any key can call these reads. The examples show the Go SDK and plain HTTP.

> **Note**
>
> Your LevelFour contact turns on the resource inventory, utilization metrics, budgets and the access check for your organization. Until then those reads come back empty. [Get data availability](#get-data-availability) says which ones hold data.

## Methods

| Method                                              | Returns                                                                                                |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| [Get data availability](#get-data-availability)     | Which Google Cloud datasets hold data for your organization                                            |
| [Get inventory breakdown](#get-inventory-breakdown) | Resource counts by type, region or project                                                             |
| [Get waste signals](#get-waste-signals)             | Resources that bill while doing nothing                                                                |
| [Get label hygiene](#get-label-hygiene)             | How many resources carry the labels you care about                                                     |
| [Get utilization](#get-utilization)                 | Utilization bands for VMs, Cloud SQL and GKE, one resource's daily series, and which projects answered |
| [Get budgets](#get-budgets)                         | Your Cloud Billing budgets, with spend from the billing export                                         |
| [Get access](#get-access)                           | What LevelFour's service account can read                                                              |

## Get data availability

Returns, for each Google Cloud dataset LevelFour reads, whether it holds data for your organization. The dashboard's Google Cloud board shows a card only when the dataset behind it holds data, so this is the same answer the board uses.

**Go**

```go  
availability, err := client.GoogleCloud.GetDataAvailability(ctx)
```

**HTTP**

```bash  
curl -s "https://api.levelfour.ai/api/v1/providers/gcp/data-availability" \
  -H "Authorization: Bearer $LEVELFOUR_API_KEY"
```

## Get inventory breakdown

Counts your Google Cloud resources, grouped by `type` (default), `region` or `project`.

**Go**

```go  
byRegion, err := client.GoogleCloud.GetInventoryBreakdown(ctx,
    &levelfour.GetInventoryBreakdownAPIV1ProvidersGcpInventoryBreakdownGetRequest{
        By: levelfour.GetInventoryBreakdownAPIV1ProvidersGcpInventoryBreakdownGetRequestBy("region").Ptr(),
    },
)
```

**HTTP**

```bash  
curl -s "https://api.levelfour.ai/api/v1/providers/gcp/inventory/breakdown?by=region" \
  -H "Authorization: Bearer $LEVELFOUR_API_KEY"
```

## Get waste signals

Returns resources that bill while doing nothing: stopped VMs whose disks still bill, unattached disks, reserved addresses nothing uses, and snapshots older than 90 days.

**Go**

```go  
waste, err := client.GoogleCloud.GetWasteSignals(ctx)
```

**HTTP**

```bash  
curl -s "https://api.levelfour.ai/api/v1/providers/gcp/inventory/waste-signals" \
  -H "Authorization: Bearer $LEVELFOUR_API_KEY"
```

## Get label hygiene

Returns how many resources carry each label key, and how many carry none. Pass `keys` to measure the keys your allocation depends on. System labels, the ones starting `goog-`, never count as labeled.

**Go**

```go  
hygiene, err := client.GoogleCloud.GetLabelHygiene(ctx,
    &levelfour.GetLabelHygieneAPIV1ProvidersGcpInventoryLabelHygieneGetRequest{
        Keys: []string{"team", "env"},
    },
)
```

**HTTP**

```bash  
curl -s "https://api.levelfour.ai/api/v1/providers/gcp/inventory/label-hygiene?keys=team&keys=env" \
  -H "Authorization: Bearer $LEVELFOUR_API_KEY"
```

## Get utilization

Three reads cover utilization from Cloud Monitoring. The summary puts VMs, Cloud SQL instances and GKE workloads into utilization bands over the last 30 days. The series is one resource's daily values. Coverage says which projects and metrics Cloud Monitoring answered for, so a missing band reads as missing data rather than as idle.

**Go**

```go  
summary, err := client.GoogleCloud.GetUtilizationSummary(ctx)

series, err := client.GoogleCloud.GetUtilizationSeries(ctx,
    &levelfour.GetUtilizationSeriesAPIV1ProvidersGcpUtilizationSeriesGetRequest{
        ResourceID: "projects/acme-prod/zones/us-central1-a/instances/web-1",
        Metric:     levelfour.String("memory_utilization"),
        Days:       levelfour.Int(90),
    },
)

coverage, err := client.GoogleCloud.GetUtilizationCoverage(ctx)
```

**HTTP**

```bash  
curl -s -G "https://api.levelfour.ai/api/v1/providers/gcp/utilization/series" \
  --data-urlencode "resource_id=projects/acme-prod/zones/us-central1-a/instances/web-1" \
  --data-urlencode "metric=memory_utilization" \
  --data-urlencode "days=90" \
  -H "Authorization: Bearer $LEVELFOUR_API_KEY"
```

| Series parameter | Type     | Description                                                                                                              |
| ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
| `resource_id`    | `string` | Required. The resource the summary names                                                                                 |
| `metric`         | `string` | `cpu_utilization` (default), `memory_utilization` for VMs running the Ops Agent, or `memory_request_utilization` for GKE |
| `days`           | `int`    | 1 to 400 (defaults to 30)                                                                                                |

## Get budgets

Returns your Cloud Billing budgets, each with the spend LevelFour reads from the billing export against it. A budget whose scope the export cannot reproduce exactly is marked approximate. Reading budgets needs the optional `roles/billing.viewer` grant from the [billing connect command](/connectors/gcp/billing-export#connect-the-export-to-levelfour).

**Go**

```go  
budgets, err := client.GoogleCloud.GetBudgets(ctx)
```

**HTTP**

```bash  
curl -s "https://api.levelfour.ai/api/v1/providers/gcp/budgets" \
  -H "Authorization: Bearer $LEVELFOUR_API_KEY"
```

## Get access

Returns what LevelFour's service account can read in Google Cloud, checked against Google's own permission test, beside what the connect command reported it applied. Use it when a read comes back empty to see whether a grant is missing.

**Go**

```go  
access, err := client.GoogleCloud.GetAccess(ctx)
```

**HTTP**

```bash  
curl -s "https://api.levelfour.ai/api/v1/providers/gcp/access" \
  -H "Authorization: Bearer $LEVELFOUR_API_KEY"
```

## Next

* [Connect Google Cloud](/connectors/gcp) is the connection these reads depend on
* [Costs](/resources/costs) has Google Cloud spend, the credits basis, cost by labels and invoice months
* [API reference](/api-reference/google-cloud) is every parameter and response field
