# Cloud Monitoring

> Run Cloud Monitoring locally with LocalCloud: connection settings, supported workflows, known limits, and code examples.
>
> Source: https://local.cloud/services/cloud-monitoring/

Cloud Monitoring stores time-series metrics and supports observability for applications and infrastructure. LocalCloud provides documented metric writes, queries, and configuration metadata.

## Typical uses

Use when application health is expressed as numeric measurements over time, with labels identifying resources or components. Test metric ingestion and time-window queries with deterministic points.

Examples

- Custom application metrics
- Metric and alert-configuration tests

Connection

Environment variable

`CLOUD_MONITORING_EMULATOR_HOST=localhost:5380`

Runtime details

- **Endpoints:** gRPC :5380
- **Minimum tier:** Community
- **Persistence:** metadata
- **Implementation:** Local Facade

## Example usage

Service ID: `monitoring`. Starts by default. Use an already running LocalCloud runtime for the examples below.

Export the local project and mapped endpoints in your client process, then use the client settings below. [First-time setup](https://local.cloud/docs/)

```bash
# Export GOOGLE_CLOUD_PROJECT and CLOUD_MONITORING_EMULATOR_HOST
eval "$(localcloud env)"
```

REST gateway examples use the generated HTTP address in `SERVICE_USAGE_EMULATOR_HOST`; native SDKs can use a different protocol.

Java · REST:

### Java · REST

### List custom metric descriptors

List custom metric definitions; Cloud Monitoring describes the measurements used to track application health.

Call the Google Cloud REST API with the JDK HTTP client. Requires JDK 17+. Results reflect resources already created in your local project.

Discovery check · reads existing local state.

#### Save as Hello.java

```java
import java.net.URI;
import java.net.http.*;
import java.time.Duration;
import java.util.Objects;

public class Hello {
  public static void main(String[] args) throws Exception {
    var project = Objects.requireNonNull(System.getenv("GOOGLE_CLOUD_PROJECT"));
    var endpoint = Objects.requireNonNull(System.getenv("SERVICE_USAGE_EMULATOR_HOST"));
    var url = URI.create(endpoint.replaceAll("/+$", "") + "/v3/projects/" + project + "/metricDescriptors?filter=metric.type%3Dstarts_with%28%22custom.googleapis.com%22%29");
    var request = HttpRequest.newBuilder(url).timeout(Duration.ofSeconds(30)).GET().build();
    var client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
    var response = client.send(request, HttpResponse.BodyHandlers.ofString());
    if (response.statusCode() >= 400) {
      throw new IllegalStateException(response.statusCode() + ": " + response.body());
    }
    System.out.println(response.body());
  }
}
```

#### Run the example

```bash
java Hello.java
```

#### Verify the result

The request succeeds. An empty list or no printed rows is valid before matching resources exist. Continue with the documented workflows for a resource test.

HTTP:

### HTTP

### List custom metric descriptors

List custom metric definitions; Cloud Monitoring describes the measurements used to track application health.

Query the REST API with curl.

Discovery check · reads existing local state.

#### Run in your terminal

```bash
curl --fail-with-body "${SERVICE_USAGE_EMULATOR_HOST%/}/v3/projects/${GOOGLE_CLOUD_PROJECT}/metricDescriptors?filter=metric.type%3Dstarts_with%28%22custom.googleapis.com%22%29"
```

#### Verify the result

The request succeeds. An empty list or no printed rows is valid before matching resources exist. Continue with the documented workflows for a resource test.

Verify a resource workflow by creating isolated state, performing the operation, and reading the result back. Run cleanup even after a failure; delete only test-owned resources.

Connection failed? Check `localcloud status --verbose`, enabled services, and client exports. Stop accidental Google Cloud calls; correct local routing before retrying.

## Documented workflows

- ### Time-series writes, filtered reads, and derived metric descriptors

    Write points with explicit metric and resource labels, then inspect the derived metric descriptor. List points using supported equality filters, time intervals, views, and pagination, and assert returned values.

- ### Notification-channel metadata

    Create and update a notification-channel resource, then read back its metadata. Use this to test configuration without sending notifications.

- ### Alert-policy create/get/list/update/delete APIs

    Create an alert policy with conditions and channel references, update it, and compare the returned fields over REST or gRPC. Evaluate alerts and notification delivery in a separate cloud test.

## Service boundaries

- Aggregation and order\_by are ignored; filters support AND-joined equality on metric/resource type and labels
- Validate alert evaluation, notifications, uptime execution, and dashboards in Google Cloud

## Code examples and integrations

- [Build an integration test loop](https://local.cloud/gcp-integration-testing/): Start the runtime, verify readiness, exercise your SDK, and clean up test state.

Agent testing

## Use Cloud Monitoring with an AI agent

Before the agent changes application logic, have it create local Cloud Monitoring state, read it back with the project SDK, and note which feature the check covered. That first local call catches accidental production routing and needs no GCP account, service-account key, or billing project.

### Configure this repo

```
Set up this repository to use LocalCloud for local GCP development. First read https://local.cloud/ai/agents.md, then inspect this repo, identify the GCP services and SDK language, configure emulator environment variables, and run the narrowest integration test against localhost. Do not use real GCP credentials or production endpoints.
```

Production endpoints, auth, IAM, quotas, regional behavior, and final release validation still need the target Google Cloud project.

[Agent resources](https://local.cloud/ai/) has more prompts and the AGENTS.md template.

## Related guides

- [Compatibility](https://local.cloud/compatibility/): compare all 27 service guides.
- [Configuration](https://local.cloud/docs/configuration/): service selection and runtime settings.
- [Official Cloud Monitoring documentation](https://docs.cloud.google.com/monitoring/docs/monitoring-overview): service concepts and cloud usage.
