การเฝ้าติดตามด้วย Prometheus และ Grafana
ตั้งค่า Prometheus สำหรับรวบรวมเมตริก และ Grafana สำหรับแสดงผล เพื่อเฝ้าติดตามประสิทธิภาพของคลัสเตอร์และแอปพลิเคชัน
การเฝ้าติดตามด้วย Prometheus และ Grafana เป็นบทเรียน Docker & Kubernetes for Developers ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Docker & Kubernetes for Developers และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Docker & Kubernetes for Developers มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Why Monitor Kubernetes?
When running applications in Kubernetes, it's crucial to know how they're performing. Are your pods healthy? Is the cluster overloaded? Monitoring gives you these answers.
In this lesson, we'll explore two powerful tools: Prometheus for collecting metrics and Grafana for visualizing them.
Prometheus: The Metrics Brain
Prometheus is an open-source monitoring system that collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts.
- It uses a pull model: Prometheus scrapes (pulls) metrics from HTTP endpoints.
- It stores data as time-series data, meaning values are recorded over time.
How Prometheus Gathers Data
Prometheus gathers metrics from various sources:
- Exporters: Specialized tools that expose existing metrics in a Prometheus-readable format (e.g.,
node_exporterfor host metrics,kube-state-metricsfor Kubernetes object metrics). - Instrumented applications: Applications can directly expose a
/metricsendpoint.
Prometheus then scrapes these endpoints.
Prometheus in Kubernetes Context
Deploying Prometheus in Kubernetes often involves using Helm charts or the Prometheus Operator. These help automate the setup and configuration.
Key for Kubernetes monitoring is service discovery. Prometheus can automatically find and scrape pods or services by using Kubernetes API integration, often configured via ServiceMonitor or PodMonitor custom resources.
Grafana: Your Dashboard Hub
While Prometheus collects and stores metrics, Grafana is the visualization layer. It allows you to:
- Create rich, interactive dashboards.
- Query multiple data sources (like Prometheus).
- Set up alerts based on visualized data.
Grafana makes complex data easy to understand at a glance.
Connecting Grafana to Prometheus
To visualize Prometheus data in Grafana, you first need to add Prometheus as a data source.
Inside Grafana, you'll specify the URL of your Prometheus server. Once connected, you can use Grafana's interface to write queries using PromQL (Prometheus Query Language) to retrieve specific metrics.
Crafting a Grafana Dashboard
Building a dashboard in Grafana is straightforward:
- Create a new dashboard.
- Add a new panel.
- Select Prometheus as the data source.
- Write a PromQL query (e.g.,
sum(rate(node_cpu_seconds_total{mode="idle"}[5m])) by (instance)to see idle CPU usage). - Choose a visualization type (graph, gauge, table, etc.).
You can combine many panels to create a comprehensive view.
Essential Kubernetes Metrics
What should you monitor in Kubernetes?
- Node Health: CPU, memory, disk usage, network I/O.
- Pod Status: Restarts, CPU/memory usage, network traffic.
- API Server: Request latency, error rates.
- Controller/Scheduler: Queue lengths, operation durations.
These metrics provide insights into your cluster's overall health and performance.
Understanding Your Dashboards
Dashboards aren't just pretty pictures; they're powerful diagnostic tools. Learn to:
- Spot trends: Is resource usage consistently increasing?
- Identify anomalies: Sudden spikes or drops often indicate issues.
- Correlate events: Did a deployment cause a performance degradation?
Effective monitoring helps you proactively address problems before they impact users.
Monitoring Tools Check
Which of the following are primary functions of Prometheus and Grafana in a Kubernetes monitoring setup?
Summary & Beyond
You've learned that Prometheus is excellent for collecting and storing time-series metrics, while Grafana provides powerful, customizable dashboards for visualizing this data.
Together, they form a robust monitoring solution for Kubernetes, helping you understand your cluster's health and application performance. Next, explore advanced PromQL, setting up alerts, and integrating with other tools!
เรียนรู้ Docker & Kubernetes for Developers ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 12
- บทเรียน
- 48
คำถามที่พบบ่อย
บทเรียน “การเฝ้าติดตามด้วย Prometheus และ Grafana” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การเฝ้าติดตามด้วย Prometheus และ Grafana” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Docker & Kubernetes for Developers ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Docker & Kubernetes for Developers มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การเฝ้าติดตามด้วย Prometheus และ Grafana”
ตั้งค่า Prometheus สำหรับรวบรวมเมตริก และ Grafana สำหรับแสดงผล เพื่อเฝ้าติดตามประสิทธิภาพของคลัสเตอร์และแอปพลิเคชัน คุณปฏิบัติ Docker & Kubernetes for Developers ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Docker & Kubernetes for Developers หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Docker & Kubernetes for Developers บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “การเฝ้าติดตามด้วย Prometheus และ Grafana” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Docker & Kubernetes for Developers นี้ได้ไหม
ได้ บทเรียน Docker & Kubernetes for Developers ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- กลยุทธ์การบันทึกล็อกใน Kubernetes
- การเฝ้าติดตามด้วย Prometheus และ Grafana
- การแก้ไขปัญหา K8s ที่พบบ่อย
- การตรวจสอบสถานะ: โพรบการทำงาน ความพร้อมใช้งาน และการเริ่มต้น