OBP GwMetric API 추가

This commit is contained in:
Rinjae
2025-12-16 19:37:04 +09:00
parent 914c9047e6
commit 64aeedde2e
8 changed files with 260 additions and 26 deletions
@@ -28,7 +28,7 @@ public class EmptyJsonResponseAdviceController implements ResponseBodyAdvice<Obj
@PostConstruct
public void init() {
logger.info("========== EmptyJsonResponseAdviceController 로딩됨 ==========");
logger.debug("========== EmptyJsonResponseAdviceController 로딩됨 ==========");
}
@Override
@@ -0,0 +1,58 @@
package com.eactive.eai.rms.common.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import java.util.Map;
/**
* 서버 시작 시 등록된 HTTP 엔드포인트 목록을 로그로 출력
*/
@Component
public class EndpointLogger implements ApplicationListener<ContextRefreshedEvent> {
private static final Logger log = LoggerFactory.getLogger(EndpointLogger.class);
private boolean logged = false;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
// 중복 출력 방지 (parent/child context)
if (logged) {
return;
}
ApplicationContext ctx = event.getApplicationContext();
try {
RequestMappingHandlerMapping mapping = ctx.getBean(RequestMappingHandlerMapping.class);
Map<RequestMappingInfo, HandlerMethod> methods = mapping.getHandlerMethods();
log.debug("========== Registered HTTP Endpoints ({}) ==========", methods.size());
methods.entrySet().stream()
.sorted((e1, e2) -> e1.getKey().toString().compareTo(e2.getKey().toString()))
.forEach(entry -> {
RequestMappingInfo info = entry.getKey();
HandlerMethod method = entry.getValue();
log.debug("{} -> {}.{}",
info.getPatternsCondition(),
method.getBeanType().getSimpleName(),
method.getMethod().getName());
});
log.debug("========== End of Endpoints ==========");
logged = true;
} catch (Exception e) {
log.warn("Failed to log endpoints: {}", e.getMessage());
}
}
}
@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.nio.charset.StandardCharsets;
@@ -27,7 +28,7 @@ public class ObpGwMetricController implements InterceptorSkipController {
private static final Logger log = LoggerFactory.getLogger(ObpGwMetricController.class);
private static final DateTimeFormatter PATH_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd_HH:mm:ss");
DateTimeFormatter.ofPattern("yyyy-MM-dd_HH:mm:ss");
private final ObpGwMetricManService obpGwMetricManService;
@@ -39,15 +40,18 @@ public class ObpGwMetricController implements InterceptorSkipController {
* 특정 시간대의 GwMetric 데이터 조회
*
* @param datetime 조회 시간대 (형식: yyyy-MM-dd_HH:mm:ss)
* @param pretty true면 JSON 들여쓰기 적용
* @return JSON Array
*/
@RequestMapping(
value = "/kjb/gw-metrics/{datetime}",
value = "/kjb/gw-metrics/{datetime}.json",
produces = "application/json;charset=utf-8"
)
@ResponseBody
public String getGwMetrics(@PathVariable("datetime") String datetime) {
log.debug("GwMetric 조회 요청: datetime={}", datetime);
public String getGwMetrics(
@PathVariable("datetime") String datetime,
@RequestParam(value = "pretty", required = false) Boolean pretty) {
log.debug("GwMetric 조회 요청: datetime={}, pretty={}", datetime, pretty);
long startTime = System.currentTimeMillis();
try {
@@ -59,11 +63,7 @@ public class ObpGwMetricController implements InterceptorSkipController {
List<ObpGwMetricDTO> metrics = obpGwMetricManService.findByTimeslice(timeslice);
// JSON 변환 (GSON)
Gson gson = new GsonBuilder()
.serializeNulls()
.create();
String json = gson.toJson(metrics);
String json = toJson(metrics, pretty);
// 응답 크기 계산 (UTF-8 기준)
int jsonBytes = json.getBytes(StandardCharsets.UTF_8).length;
@@ -85,15 +85,18 @@ public class ObpGwMetricController implements InterceptorSkipController {
* 특정 시간대 이후의 GwMetric 데이터 조회
*
* @param datetime 조회 시작 시간대 (형식: yyyy-MM-dd_HH:mm:ss)
* @param pretty true면 JSON 들여쓰기 적용
* @return JSON Array (해당 시간대 이후의 모든 지표)
*/
@RequestMapping(
value = "/kjb/gw-metrics/after-timeslice/{datetime}",
value = "/kjb/gw-metrics/after-timeslice/{datetime}.json",
produces = "application/json;charset=utf-8"
)
@ResponseBody
public String getGwMetricsAfterTimeslice(@PathVariable("datetime") String datetime) {
log.debug("GwMetric after-timeslice 조회 요청: datetime={}", datetime);
public String getGwMetricsAfterTimeslice(
@PathVariable("datetime") String datetime,
@RequestParam(value = "pretty", required = false) Boolean pretty) {
log.debug("GwMetric after-timeslice 조회 요청: datetime={}, pretty={}", datetime, pretty);
long startTime = System.currentTimeMillis();
try {
@@ -105,11 +108,7 @@ public class ObpGwMetricController implements InterceptorSkipController {
List<ObpGwMetricAfterDTO> metrics = obpGwMetricManService.findByTimesliceAfter(timeslice);
// JSON 변환 (GSON)
Gson gson = new GsonBuilder()
.serializeNulls()
.create();
String json = gson.toJson(metrics);
String json = toJson(metrics, pretty);
// 응답 크기 계산 (UTF-8 기준)
int jsonBytes = json.getBytes(StandardCharsets.UTF_8).length;
@@ -127,6 +126,21 @@ public class ObpGwMetricController implements InterceptorSkipController {
}
}
/**
* 객체를 JSON 문자열로 변환
*
* @param object 변환할 객체
* @param pretty true면 들여쓰기 적용
* @return JSON 문자열
*/
private String toJson(Object object, Boolean pretty) {
GsonBuilder builder = new GsonBuilder().serializeNulls();
if (Boolean.TRUE.equals(pretty)) {
builder.setPrettyPrinting();
}
return builder.create().toJson(object);
}
/**
* 바이트 크기를 읽기 쉬운 형식으로 변환
* 예: 1024 -> "1.0 KB", 1048576 -> "1.0 MB"
+80 -8
View File
@@ -1,9 +1,81 @@
# HotSwapAgent 설정
# Spring 관련
Spring.reload=true
# Hibernate 관련
Hibernate.reload=true
# 로그 레벨
logLevel=INFO
# 자동 Hot Swap 활성화
# ============================================================
# HotswapAgent Configuration for eapim-admin (Spring Legacy)
# ============================================================
# \uC790\uB3D9 \uD56B\uC2A4\uC651 \uD65C\uC131\uD654
autoHotswap=true
# \uB85C\uAE45 \uB808\uBCA8 (TRACE, DEBUG, INFO, WARNING, ERROR)
LOGGER.level=INFO
# ============================================================
# \uBA85\uC2DC\uC801 \uD50C\uB7EC\uADF8\uC778 \uBE44\uD65C\uC131\uD654 (\uC27C\uD45C \uAD6C\uBD84)
# ============================================================
disabledPlugins=org.hotswap.agent.plugin.ibatis.IBatisPlugin,org.hotswap.agent.plugin.mybatis.MyBatisPlugin
# ============================================================
# Core Plugin \uD65C\uC131\uD654
# ============================================================
# Spring Framework (\uD544\uC218) - Bean \uC7AC\uB4F1\uB85D
spring.enabled=true
spring.basePackagePrefix=com.eactive.
# Hibernate/JPA - \uC5D4\uD2F0\uD2F0 \uBCC0\uACBD \uAC10\uC9C0
hibernate.enabled=true
# Logback - \uB85C\uADF8 \uC124\uC815 \uB9AC\uB85C\uB4DC
logback.enabled=true
# Proxy - AOP \uD504\uB85D\uC2DC \uC7AC\uC0DD\uC131
proxy.enabled=true
# ============================================================
# \uBE44\uD65C\uC131\uD654 Plugin (\uBBF8\uC0AC\uC6A9 \uB610\uB294 \uCDA9\uB3CC \uBC29\uC9C0)
# ============================================================
# iBatis (Spring\uC758 SqlMapClientFactoryBean\uACFC \uCDA9\uB3CC)
ibatis.enabled=false
mybatis.enabled=false
jsf.enabled=false
seam.enabled=false
wicket.enabled=false
mojarra.enabled=false
omnifaces.enabled=false
el.enabled=false
weld.enabled=false
owb.enabled=false
cdi.enabled=false
resteasy.enabled=false
jersey1.enabled=false
jersey2.enabled=false
# ============================================================
# Watch Resources (\uB9AC\uC18C\uC2A4 \uBCC0\uACBD \uAC10\uC9C0)
# ============================================================
# \uD074\uB798\uC2A4\uD328\uC2A4 \uC678 \uCD94\uAC00 \uAC10\uC2DC \uACBD\uB85C (XML \uC124\uC815 \uB4F1)
watchResources=src/main/resources,WebContent/WEB-INF
# ============================================================
# Spring \uC804\uC6A9 \uC124\uC815
# ============================================================
# \uCEF4\uD3EC\uB10C\uD2B8 \uC2A4\uCE94 \uBCA0\uC774\uC2A4 \uD328\uD0A4\uC9C0
spring.scanBasePackage=com.eactive.eai,com.eactive.apim
# \uD504\uB85D\uC2DC \uC7AC\uC0DD\uC131 (AOP, @Transactional \uC0AC\uC6A9 \uC2DC \uD544\uC218)
spring.proxyRegeneration=true
# Bean \uC815\uC758 \uBCC0\uACBD \uC2DC \uB9AC\uB85C\uB4DC
spring.reloadBeanDefinition=true
# ============================================================
# \uB514\uBC84\uAE45 (\uBB38\uC81C \uBC1C\uC0DD \uC2DC \uD65C\uC131\uD654)
# ============================================================
# \uC0C1\uC138 \uB85C\uADF8 \uCD9C\uB825 (\uD544\uC694\uC2DC DEBUG\uB85C \uBCC0\uACBD)
# LOGGER.level=DEBUG
# \uD074\uB798\uC2A4 \uBCC0\uACBD \uCD94\uC801
# LOGGER.org.hotswap.agent.plugin.spring=DEBUG