개발/spring-cloud
[spring-cloud] micrometer, prometheus
방푸린
2024. 2. 8. 17:07
반응형
환경: springboot2.7.6, java17
micrometer
- jvm 기반의 애플리캐이션 metrics 제공
- springboot2 +
- premetheus 등 다양한 모니터링 시스템 지원
- (구) turbine server -> hystrix client
timer
- 짧은 지연 시간, 이벤트의 사용 빈도 측정
- 시계열로 이벤트의 시간, 호출 빈도 등 제공
- @Timed 제공
서비스 연동
1. dependency 추가
<!-- micrometer -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator </artifactId>
</dependency>
2. application.yml actuator 정보 추가
management:
endpoints:
web:
exposure:
include: info, metrics, prometheus #추가
3. @Timed 어노테이션으로 metrics 마킹
@GetMapping("/welcome")
@Timed(value = "users.welcome", longTask = true)
public String welcome(){
// return environment.getProperty("greeting.message");
return greeting.getMessage();
}
4. 추가한 metrics는 사용을 하면 /actuator/metrics 에 표기됨
4. 그리고 실제 호출정보는 /actuator/premetheus 에 남음
728x90
반응형