OBP GwMetric API 추가
This commit is contained in:
+1
-1
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user