Monitoring Java Applications on GCP with Cloud Monitoring
Fast recall
Quick revision
Core answer
Observability maturity — whether the candidate understands the three pillars of observability (metrics, logs, traces) and can implement them in a Spring Boot application on GCP without standing up additional infrastructure.
Relying solely on application logs for debugging production issues, or not correlating trace IDs across log entries and distributed traces, making root cause analysis in microservices difficult.
Discuss Service Level Indicators (SLIs), error budget alerting, and how to use Cloud Monitoring's Metrics Explorer to build dashboards correlating JVM metrics with infrastructure metrics.
Interview-ready guide
Interview answer
GCP Cloud Monitoring integrates with Spring Boot through Micrometer — the micrometer-registry-stackdriver registry pushes all application metrics to Cloud Monitoring automatically, giving you JVM, HTTP, and HikariCP metrics without manual Cloud Monitoring SDK calls.
Publishing metrics with Micrometer
- Add
micrometer-registry-stackdriverand configuremanagement.metrics.export.stackdriver.project-id; Micrometer pushes all registered meters to Cloud Monitoring every 60 seconds - JVM metrics (heap usage, GC pauses, thread count), HTTP request metrics (count, latency, error rate), and HikariCP pool metrics appear automatically — no custom instrumentation needed for the common signals
Custom metrics
Counter.builder("orders.placed").register(meterRegistry).increment()adds a custom counter;Timer.builder("checkout.duration").register(meterRegistry).record(duration)adds a latency distribution- Tag metrics with labels —
tags("service", "order-service", "env", "prod")— which means Cloud Monitoring dashboards can filter and group by service and environment
Cloud Monitoring dashboards and alerting
- Create dashboards for the four golden signals: request rate (
http.server.requests.count), error rate (http.server.requests{status=5xx}), latency (http.server.requests.p99), and saturation (jvm.memory.used/jvm.memory.max) - Alerting policies on metric threshold violations send notifications to PagerDuty, Slack, or email via notification channels; configure alert conditions with
alignment_periodandcross_series_reducerto avoid alert noise from transient spikes
Cloud Logging integration
- Spring Boot JSON logs shipped to stdout are automatically collected by GKE's logging agent and Cloud Run's built-in log collection; they appear in Cloud Logging queryable with the Logging Query Language
resource.type="cloud_run_revision" AND severity="ERROR"filters errors from a specific Cloud Run service; combine with metrics alerts for correlated observability
Monitoring Java Applications on GCP with Cloud Monitoring
Direct Answer
Integrate Cloud Monitoring into Spring Boot by adding the Micrometer Google Cloud Monitoring registry, which automatically exports Actuator metrics as custom metrics. Supplement with structured logging to Cloud Logging via Logback, distributed tracing via Cloud Trace, and uptime checks or alerting policies in Cloud Monitoring to create a complete observability stack.
Common Mistakes & Pitfalls
Relying solely on application logs for debugging production issues, or not correlating trace IDs across log entries and distributed traces, making root cause analysis in microservices difficult.
Check your understanding
Answer these without looking back at the article.
- How do you use Cloud Profiler to diagnose memory leaks in a Java application?
- How do you create log-based metrics in Cloud Logging and use them in Cloud Monitoring alerts?
- What is the difference between Cloud Trace sampling rate and how should you set it for a high-traffic service?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.