0Pricing
Erlang OTP: Distributed & Fault-Tolerant Systems Programming · 강의

메트릭 및 모니터링 연동

메트릭 수집을 구현하고 Prometheus 및 Grafana와 같은 외부 모니터링 시스템을 연동하여 시스템을 관찰할 수 있게 합니다.

메트릭 및 모니터링 연동은(는) CoddyKit의 무료 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Observability with Metrics

Welcome to Metrics & Monitoring Integration! In modern systems, understanding what's happening inside your application is crucial. This is called observability.

Observability relies on three pillars:

  • Logs: Records of discrete events.
  • Traces: End-to-end request flows across services.
  • Metrics: Aggregated numerical data points over time.

This lesson focuses on metrics, which give you a high-level view of system health and performance trends.

Why Metrics Matter

Metrics are numerical measurements collected at regular intervals. They help you answer questions like:

  • How many requests per second is my service handling?
  • What's the average response time?
  • How much memory is my Erlang VM using?
  • Are there any errors occurring?

By tracking these over time, you can spot trends, identify bottlenecks, and react to issues proactively.

Types of Metrics

There are several common types of metrics:

  • Counters: A single value that only ever goes up (e.g., total requests, errors).
  • Gauges: A single value that can go up or down (e.g., current active users, CPU usage).
  • Histograms: Sample observations (like request durations) and count them in configurable buckets, often providing sum and count.
  • Summaries: Similar to histograms but calculate configurable quantiles (e.g., 99th percentile latency) on the client side.

Erlang's Built-in Statistics

Erlang provides some basic system statistics out of the box through the erlang:statistics/1 function. These are useful for fundamental VM health checks.

You can get data like:

  • scheduler_wall_time: CPU time spent by schedulers.
  • io: Total I/O operations.
  • memory: Memory usage details.

While useful, these often aren't enough for application-specific insights. We need custom metrics.

Custom Metric Collection

For application-specific metrics, you'll often create your own. A common pattern is to use a gen_server process to manage and update metric values, ensuring atomic updates.

Try running this example of a simple counter managed by a gen_server:

-module(main).
-export([main/0]).

% --- simple_counter.erl (simplified for single file demo) ---
% A simple GenServer to maintain a counter
-behaviour(gen_server).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).

% GenServer callbacks
init([]) -> {ok, 0}.
handle_call(get_value, _From, State) -> {reply, State, State}.
handle_cast(increment, State) -> {noreply, State + 1}.
handle_cast(stop, _State) -> {stop, normal, ok}.
handle_info(_Info, State) -> {noreply, State}.
terminate(_Reason, _State) -> ok.
code_change(_OldVsn, State, _Extra) -> {ok, State}.

% Client API for our counter
start_counter() -> gen_server:start({local, my_counter}, ?MODULE, [], []).
increment_counter() -> gen_server:cast(my_counter, increment).
get_counter_value() -> gen_server:call(my_counter, get_value).
stop_counter() -> gen_server:cast(my_counter, stop).
% --- End simple_counter.erl ---

main() ->
    io:format("Starting a simple counter process...~n"),
    {ok, _Pid} = start_counter(),
    io:format("Initial counter value: ~p~n", [get_counter_value()]),

    increment_counter(),
    io:format("After 1 increment: ~p~n", [get_counter_value()]),

    increment_counter(),
    increment_counter(),
    io:format("After 3 increments: ~p~n", [get_counter_value()]),

    stop_counter(),
    io:format("Counter process stopped.~n").

The Telemetry Library

For more advanced and standardized metric collection in Erlang/Elixir, the Telemetry library is widely used. It provides a common way to emit events from your application.

Instead of manually updating a counter, you can:

  • Define telemetry events (e.g., [:my_app, :request, :start], [:my_app, :request, :stop]).
  • Attach handlers to these events to process and aggregate metrics.

This decouples event emission from metric collection, making your system more flexible.

Exposing Metrics

Once you collect metrics, you need to make them available to external monitoring systems. This usually involves an exporter.

An exporter is a component (often an HTTP server) that:

  • Gathers current metric values from your application.
  • Formats them into a standard format (e.g., Prometheus text format).
  • Serves them via an HTTP endpoint (e.g., /metrics).

Monitoring systems then 'scrape' this endpoint to collect the data.

Prometheus: A Pull-Based System

Prometheus is a popular open-source monitoring system. It works on a pull model: instead of your application pushing metrics, Prometheus regularly 'scrapes' (pulls) metrics from configured targets (your application's exporter endpoints).

It then stores these metrics as time-series data, allowing you to query and analyze trends over time. Prometheus is excellent for operational monitoring and alerting.

Prometheus Text Format

Erlang applications integrate with Prometheus by exposing an HTTP endpoint that serves metrics in the Prometheus text exposition format. This is a simple, human-readable format.

Here's an example of what Prometheus expects to scrape:

# HELP my_app_requests_total Total number of requests processed.
# TYPE my_app_requests_total counter
my_app_requests_total 1234

# HELP my_app_active_users Current number of active users.
# TYPE my_app_active_users gauge
my_app_active_users 50

# HELP my_app_request_duration_seconds Request duration in seconds.
# TYPE my_app_request_duration_seconds histogram
my_app_request_duration_seconds_bucket{le="0.1"} 100
my_app_request_duration_seconds_bucket{le="0.5"} 250
my_app_request_duration_seconds_bucket{le="1.0"} 350
my_app_request_duration_seconds_bucket{le="+Inf"} 400
my_app_request_duration_seconds_sum 150.0
my_app_request_duration_seconds_count 400

Grafana for Visualization

While Prometheus stores and queries metrics, Grafana is the go-to tool for visualizing them. Grafana connects to various data sources (like Prometheus) and allows you to build interactive dashboards.

With Grafana, you can:

  • Create graphs, charts, and tables.
  • Combine data from multiple metrics.
  • Set up alerts based on visual thresholds.
  • Share dashboards with your team.

Monitoring Integration Check

You've learned about collecting and exposing metrics, and how Prometheus and Grafana work together. Let's test your understanding!

Recap & Next Steps

Great job! You've covered the essentials of metrics and monitoring integration:

  • The importance of observability and the role of metrics.
  • How to collect custom metrics in Erlang, including using gen_server processes.
  • The concept of exporters and the Prometheus text format.
  • How Prometheus acts as a pull-based time-series database.
  • How Grafana provides powerful visualization for your metrics.

With these tools, you can gain deep insights into your Erlang applications!

자주 묻는 질문

“메트릭 및 모니터링 연동” 강의는 무료인가요?

네 — “메트릭 및 모니터링 연동” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의 전체를 잠금 해제할 수 있습니다. Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

“메트릭 및 모니터링 연동”에서 뭘 배우나요?

메트릭 수집을 구현하고 Prometheus 및 Grafana와 같은 외부 모니터링 시스템을 연동하여 시스템을 관찰할 수 있게 합니다. 브라우저에서 직접 실행하는 실습 코드로 Erlang OTP: Distributed & Fault-Tolerant Systems Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Erlang OTP: Distributed & Fault-Tolerant Systems Programming을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Erlang OTP: Distributed & Fault-Tolerant Systems Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“메트릭 및 모니터링 연동” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. Erlang 프로파일링 기법
  2. 분산 시스템 추적 및 디버깅
  3. 메트릭 및 모니터링 연동
  4. 메모리 분석과 가비지 컬렉션 튜닝
← Erlang OTP: Distributed & Fault-Tolerant Systems Programming(으)로 돌아가기