三大支柱:日志、指标与追踪
探索可观测性的三种不同但互为补充的信号:日志、指标和追踪。了解它们各自的优势以及协同工作的方式。
三大支柱:日志、指标与追踪 是 CoddyKit 上的免费 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Observability's Core Pillars
Observability rests on three pillars: logs, metrics, and traces. Each gives a different view, and together they paint a full picture of your system.
Logs: The Event Diary
Logs are your system's diary — text records of discrete events like a login or an error. They tell you exactly what happened and when.
What Logs Tell Us
Logs are gold for debugging and auditing. When something breaks, they hand you the error message, stack trace, and context right up to the failure.
Logs in Action (Code)
Even a print statement is a primitive log. Real apps use logging libraries for structure, but this snippet shows the basic idea of log output.
public class LogDemo {
public static void main(String[] args) {
System.out.println("INFO: Application started.");
int userCount = 10;
System.out.println("DEBUG: Current users: " + userCount);
// Imagine an error occurring here
System.out.println("ERROR: Failed to connect to database.");
}
}Metrics: Measuring Performance
Metrics are numbers measured over time — CPU, memory, request rate, error count. They tell you how much or how often, stored as time-series data.
Metrics for Trends & Health
Metrics reveal trends and health. A sudden request drop or CPU spike shows up instantly, making them perfect for spotting bottlenecks and firing alerts.
Metrics in Action (Concept)
Real metrics need libraries, but the core idea is simple: a counter that increments and gets reported periodically. This snippet sketches that out.
public class MetricDemo {
static int successfulRequests = 0;
static int failedRequests = 0;
public static void processRequest(boolean success) {
if (success) {
successfulRequests++;
} else {
failedRequests++;
}
// In a real system, these counts would be
// reported to a metrics system periodically.
}
public static void main(String[] args) {
processRequest(true);
processRequest(true);
processRequest(false);
System.out.println("Simulated request counts:");
System.out.println("Successful: " + successfulRequests);
System.out.println("Failed: " + failedRequests);
}
}Traces: Following a Request
A trace follows one request end-to-end across services. It's built from spans — each span an operation — revealing timing and relationships between components.
Traces for Distributed Systems
Traces are essential for microservices. When a request is slow, a trace pinpoints exactly which service or DB call caused the delay, even hops away.
Pillars: Stronger Together
The pillars are strongest together: traces show the path and timing, logs add context per span, metrics give aggregate trends. Correlate all three for the full view.
Check Your Understanding
Let's check what you've learned about the three pillars of observability.
Recap: The Observability Pillars
You've met all three pillars: logs for debugging, metrics for trends, traces for distributed request journeys. Next: why observability is so crucial today.
常见问题解答
「三大支柱:日志、指标与追踪」课时是免费的吗?
是的 — 「三大支柱:日志、指标与追踪」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课程的其余内容,请升级到 CoddyKit PRO。 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课程共包含 4 节课。
「三大支柱:日志、指标与追踪」这节课中我会学到什么?
探索可观测性的三种不同但互为补充的信号:日志、指标和追踪。了解它们各自的优势以及协同工作的方式。 你通过在浏览器中直接运行的动手代码来练习 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry),全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 需要有经验吗?
无需任何先前经验。CoddyKit 上的 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「三大支柱:日志、指标与追踪」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课中编写并运行代码吗?
能。每节 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 什么是系统可观测性
- 三大支柱:日志、指标与追踪
- 可观测性为何至关重要
- 监控与可观测性:已知与未知