Spring Boot 4 Complete Guide · บทเรียน

เมตริกและแดชบอร์ดด้วย Micrometer และ Prometheus

เปิดเผยเมตริกของแอปพลิเคชันด้วย Micrometer ดึงข้อมูลด้วย Prometheus และแสดงแนวโน้มเป็นภาพใน Grafana เพื่อการสังเกตระบบอย่างครบถ้วน

บทเรียน 4 จาก 413 ขั้นตอน

เมตริกและแดชบอร์ดด้วย Micrometer และ Prometheus เป็นบทเรียน Spring Boot 4 Complete Guide ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Spring Boot 4 Complete Guide และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Spring Boot 4 Complete Guide มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Beyond Logs and Traces

Logs tell you what happened and traces show request paths, but metrics reveal trends over time: request rates, error percentages, memory use. They complete the observability picture.

What Is Micrometer?

Micrometer is a metrics facade, like SLF4J but for metrics. You instrument once and export to many backends such as Prometheus or Datadog.

Wiring in Prometheus

Add the Prometheus registry dependency and Actuator exposes a scrape endpoint automatically.

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

Exposing the Endpoint

Enable the Prometheus endpoint so metrics are served at /actuator/prometheus in a format Prometheus understands.

management.endpoints.web.exposure.include=health,prometheus

The Three Core Meter Types

Most metrics fall into three types.

  • Counter — only goes up (requests served)
  • Gauge — goes up and down (queue size)
  • Timer — measures durations

Creating a Counter

Register a counter and increment it when an event occurs.

Counter c = registry.counter("orders.placed");
c.increment();

Timing Code

A Timer records how long operations take, giving you latency percentiles.

Timer t = registry.timer("checkout.duration");
t.record(() -> processCheckout());

Tags for Dimensionality

Add tags (labels) to slice metrics by endpoint, status, or region. Avoid high-cardinality tags like user IDs, which explode storage.

registry.counter("http.requests", "status", "200").increment();

How Prometheus Scrapes

Prometheus periodically pulls the /actuator/prometheus endpoint and stores time-series data, which you can then query with PromQL.

Visualizing with Grafana

Grafana connects to Prometheus as a data source and renders dashboards. Spring Boot has ready-made dashboards for JVM and HTTP metrics.

Alerting on Metrics

Define alert rules, for example error rate above 5 percent, so the team is notified before users complain. Metrics turn into proactive operations.

Quick Check

Test your understanding of metrics and observability.

Recap

You exposed metrics via Micrometer and the Prometheus Actuator endpoint, learned counters, gauges, and timers, used tags wisely, and visualized and alerted with Prometheus and Grafana.

เริ่มต้นได้ฟรี

เรียนรู้ Java ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
21
บทเรียน
84

คำถามที่พบบ่อย

บทเรียน “เมตริกและแดชบอร์ดด้วย Micrometer และ Prometheus” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “เมตริกและแดชบอร์ดด้วย Micrometer และ Prometheus” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Spring Boot 4 Complete Guide ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Spring Boot 4 Complete Guide มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “เมตริกและแดชบอร์ดด้วย Micrometer และ Prometheus”

เปิดเผยเมตริกของแอปพลิเคชันด้วย Micrometer ดึงข้อมูลด้วย Prometheus และแสดงแนวโน้มเป็นภาพใน Grafana เพื่อการสังเกตระบบอย่างครบถ้วน คุณปฏิบัติ Spring Boot 4 Complete Guide ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Spring Boot 4 Complete Guide หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Spring Boot 4 Complete Guide บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “เมตริกและแดชบอร์ดด้วย Micrometer และ Prometheus” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Spring Boot 4 Complete Guide นี้ได้ไหม

ได้ บทเรียน Spring Boot 4 Complete Guide ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. พื้นฐานการจัดการคลัสเตอร์ด้วย Kubernetes
  2. การติดตามแบบกระจายด้วย Sleuth และ Zipkin
  3. การตรวจสอบสถานะและรูปแบบความทนทาน
  4. เมตริกและแดชบอร์ดด้วย Micrometer และ Prometheus
← กลับไปที่ Spring Boot 4 Complete Guide