Video in progress

Which metrics do you collect first to monitor a service in production?

Four main signals: latency (response time, especially p95/p99), traffic (RPS), errors (the share of failures) and saturation (how full the CPU, memory and connection pool are). These show most problems.

📖 Answer

In the Google SRE book these are called the "four golden signals", and they're a good list to start with.

In Spring Boot they're almost ready-made: Actuator + Micrometer + Prometheus.

management:
  endpoints:
    web:
      exposure:
        include: health, prometheus
  metrics:
    distribution:
      percentiles-histogram:
        http.server.requests: true

After that you draw RPS, errors and percentiles in Grafana from the http_server_requests_seconds metric.

For saturation, look separately at:

  • HikariCP: hikaricp_connections_pending — if threads are waiting for a connection, the pool is too small;
  • JVM heap and GC pauses;
  • queue length (consumers can't keep up).

Set alerts on symptoms, not causes: not "CPU 80%" but "errors above 1% for 5 minutes" or "p99 above 1 second". High CPU isn't a problem by itself; the user noticing slowness is.