You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# HELP my_order_total order
# TYPE my_order_total counter
my_order_total{class="hello.order.v1.OrderServiceV1",method="order",} 1.0
my_order_total{class="hello.order.v1.OrderServiceV1",method="cancel",} 1.0
메트릭 이름이 my.order => my_order_total 로 변경된 것을 확인할 수 있다.
프로메테우스는 . => _ 로 변경한다.
카운터는 마지막에 _total 을 붙인다. 프로메테우스는 관례상 카운터 이름의 끝에 _total 을 붙인다.
method 라는 tag , 레이블을 기준으로 데이터가 분류되어 있다.
그라파나 등록 - 주문수, 취소수
앞서 만들어둔 hello-dashboard 에 주문수, 취소수 그래프를 추가하자
Panel options
Title : 주문수
PromQL
increase(my_order_total{method="order"}[1m])
Legend : {{method}}
increase(my_order_total{method="cancel"}[1m])
Legend : {{method}}
참고: 카운터는 계속 증가하기 때문에 특정 시간에 얼마나 증가했는지 확인하려면 increase() , rate() 같은 함수와 함께 사용하는 것이 좋다.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
메트릭 등록3 - Timer
Timer
OrderService
OrderServiceV0
OrderConfigV0
OrderController
ActuatorApplication
메트릭 등록1 - 카운터
MeterRegistry
Counter(카운터)
주문수 취소수 서비스에 카운터 메트릭을 적용해보자.
OrderServiceV1
정리하면 각각의 메서드를 하나 호출할 때 마다 카운터가 증가한다.
OrderConfigV1
ActuatorApplication - 수정
프로메테우스 포멧 메트릭 확인
그라파나 등록 - 주문수, 취소수
Panel options
PromQL
참고: 카운터는 계속 증가하기 때문에 특정 시간에 얼마나 증가했는지 확인하려면 increase() , rate() 같은 함수와 함께 사용하는 것이 좋다.
메트릭 등록2 - @counted
OrderServiceV2
OrderConfigV2
ActuatorApplication
액츄에이터 메트릭 확인
프로메테우스 포멧 메트릭 확인
그라파나 대시보드 확인
메트릭 등록3 - Timer
Timer
OrderServiceV3
걸리는 시간을 확인하기 위해 주문은 0.5초, 취소는 0.2초 대기하도록 했다. 추가로 가장 오래 걸린 시간을 확인하기 위해 sleep() 에서 최대 0.2초를 랜덤하게 더 추가했다. (모두 0.5초로 같으면 가장 오래 걸린 시간을 확인하기 어렵다.)
OrderConfigV3
ActuatorApplication - 변경
여기서 평균 실행 시간도 계산할 수 있다.
그라파나 등록 - 주문수 v3
패널 옵션
PromQL
참고: 카운터는 계속 증가하기 때문에 특정 시간에 얼마나 증가했는지 확인하려면 increase() , rate() 같은 함수와 함께 사용하는 것이 좋다.
그라파나 등록 - 최대 실행시간
패널 옵션
PromQL
그라파나 등록 - 평균 실행시간
패널 옵션
PromQL
메트릭 등록4 - @timed
OrderServiceV4
OrderConfigV4
ActuatorApplication - 변경
프로메테우스 포멧 메트릭 확인
그라파나 대시보드 확인
메트릭 등록5 - 게이지
Guage(게이지)
참고: 카운터와 게이지를 구분할 때는 값이 감소할 수 있는가를 고민해보면 도움이 된다.
이번에는 재고 수량을 통해 게이지를 등록하는 방법을 알아보자
가장 단순한 방법은 다음과 같이 등록하는 것이다.
StockConfigV1
ActuatorApplication - 변경
프로메테우스 포멧 메트릭 확인
그라파나 등록 - 재고
패널 옵션
PromQL
게이지 단순하게 등록하기
StockConfigV2
ActuatorApplication - 변경
정리
Micrometer 사용법 이해
메트릭은 100% 정확한 숫자를 보는데 사용하는 것이 아니다. 약간의 오차를 감안하고 실시간으로 대략의 데이터를 보
는 목적으로 사용한다.
마이크로미터 핵심 기능
Counter, Gauge, Timer, Tags
MeterRegistry
마이크로미터 기능을 제공하는 핵심 컴포넌트
스프링을 통해서 주입 받아서 사용하고, 이곳을 통해서 카운터, 게이지 등을 등록한다.
Counter(카운터)
Gauge(게이지)
Timer
Tag, 레이블
Beta Was this translation helpful? Give feedback.
All reactions