Skip to content

Commit 4db7f2a

Browse files
authored
Merge pull request #81 from Sysone-Final/feature/SYSONE-73-monitoring
Feature/sysone 73 monitoring
2 parents 6989272 + 56e517e commit 4db7f2a

5 files changed

Lines changed: 184 additions & 195 deletions

File tree

src/main/java/org/example/finalbe/domains/monitoring/dto/DataCenterStatisticsDto.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ public class DataCenterStatisticsDto {
8383
private Integer criticalAlerts; // Critical 알람 수
8484
private Integer warningAlerts; // Warning 알람 수
8585

86-
// 전력 통계
87-
private Double totalPowerUsage; // 총 전력 사용량 (kW)
88-
private Double avgPowerUsagePerRack; // 랙당 평균 전력 사용량 (kW)
8986

9087
// 서버실별 요약 (선택적)
9188
private List<ServerRoomSummaryDto> serverRoomSummaries;

src/main/java/org/example/finalbe/domains/monitoring/service/AggregatedMonitoringScheduler.java

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.springframework.stereotype.Service;
1313

1414
import java.util.List;
15+
import java.util.concurrent.CompletableFuture;
16+
import java.util.concurrent.Executor;
1517
import java.util.stream.Collectors;
1618

1719
/**
@@ -29,16 +31,13 @@ public class AggregatedMonitoringScheduler {
2931
private final DataCenterMonitoringService dataCenterMonitoringService;
3032
private final SseService sseService;
3133
private final AlertEvaluationService alertEvaluationService;
34+
private final Executor taskExecutor;
3235

33-
/**
34-
* 서버실 통계 갱신 스케줄러
35-
* ✅ DB에서 활성 서버실을 동적으로 조회하여 처리
36-
*/
37-
@Scheduled(fixedDelayString = "${monitoring.scheduler.statistics-interval:5000}")
36+
@Scheduled(fixedRateString = "${monitoring.scheduler.statistics-interval:5000}")
3837
public void updateServerRoomStatistics() {
3938
log.debug("=== ServerRoom 통합 모니터링 시작 ===");
39+
long totalStartTime = System.currentTimeMillis();
4040

41-
// ✅ DB에서 활성 서버실 목록 동적 조회
4241
List<Long> serverRoomIds = serverRoomRepository.findAllByDelYn(DelYN.N)
4342
.stream()
4443
.map(serverRoom -> serverRoom.getId())
@@ -49,40 +48,41 @@ public void updateServerRoomStatistics() {
4948
return;
5049
}
5150

52-
log.debug("처리 대상 서버실: {} (총 {}개)", serverRoomIds, serverRoomIds.size());
53-
54-
int successCount = 0;
55-
int failCount = 0;
56-
57-
for (Long serverRoomId : serverRoomIds) {
58-
try {
59-
ServerRoomStatisticsDto statistics = serverRoomMonitoringService
60-
.calculateServerRoomStatistics(serverRoomId);
61-
62-
sseService.sendToServerRoom(serverRoomId, "serverroom-statistics", statistics);
63-
64-
// ✅ 알림 평가 호출
65-
alertEvaluationService.evaluateServerRoomStatistics(statistics);
51+
// ✅ 병렬 처리
52+
List<CompletableFuture<Void>> futures = serverRoomIds.stream()
53+
.map(serverRoomId -> CompletableFuture.runAsync(() -> {
54+
long startTime = System.currentTimeMillis();
55+
try {
56+
ServerRoomStatisticsDto statistics = serverRoomMonitoringService
57+
.calculateServerRoomStatistics(serverRoomId);
58+
59+
sseService.sendToServerRoom(serverRoomId, "serverroom-statistics", statistics);
60+
alertEvaluationService.evaluateServerRoomStatistics(statistics);
61+
62+
long duration = System.currentTimeMillis() - startTime;
63+
if (duration > 3000) {
64+
log.warn("⚠️ ServerRoom {} 통계 계산 느림: {}ms", serverRoomId, duration);
65+
}
66+
} catch (Exception e) {
67+
log.error("❌ ServerRoom {} 통합 모니터링 실패: {}", serverRoomId, e.getMessage());
68+
}
69+
}, taskExecutor))
70+
.collect(Collectors.toList());
6671

67-
successCount++;
68-
} catch (Exception e) {
69-
log.error("ServerRoom {} 통합 모니터링 실패: {}", serverRoomId, e.getMessage());
70-
failCount++;
71-
}
72-
}
72+
// 모든 작업 완료 대기
73+
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
7374

74-
log.debug("ServerRoom 통합 모니터링 완료 - 성공: {}, 실패: {}", successCount, failCount);
75+
long totalDuration = System.currentTimeMillis() - totalStartTime;
76+
log.info("📊 ServerRoom 통합 모니터링 완료 - 총 소요시간: {}ms", totalDuration);
7577
}
76-
7778
/**
7879
* 데이터센터 통계 갱신 스케줄러
79-
* ✅ DB에서 활성 데이터센터를 동적으로 조회하여 처리
80+
* ✅ fixedRate로 변경: 정확히 5초마다 실행
8081
*/
81-
@Scheduled(fixedDelayString = "${monitoring.scheduler.datacenter-interval:5000}")
82+
@Scheduled(fixedRateString = "${monitoring.scheduler.datacenter-interval:5000}")
8283
public void updateDataCenterStatistics() {
8384
log.debug("=== DataCenter 통합 모니터링 시작 ===");
8485

85-
// ✅ DB에서 활성 데이터센터 목록 동적 조회
8686
List<Long> dataCenterIds = dataCenterRepository.findAllByDelYn(DelYN.N)
8787
.stream()
8888
.map(dataCenter -> dataCenter.getId())
@@ -104,8 +104,6 @@ public void updateDataCenterStatistics() {
104104
.calculateDataCenterStatistics(dataCenterId);
105105

106106
sseService.sendToDataCenter(dataCenterId, "datacenter-statistics", statistics);
107-
108-
// ✅ 알림 평가 호출
109107
alertEvaluationService.evaluateDataCenterStatistics(statistics);
110108

111109
successCount++;

src/main/java/org/example/finalbe/domains/monitoring/service/DataCenterMonitoringService.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,7 @@ public DataCenterStatisticsDto calculateDataCenterStatistics(Long dataCenterId)
317317
.mapToInt(Integer::intValue)
318318
.sum();
319319

320-
// 10. 전력 통계 집계
321-
Double totalPowerUsage = serverRoomStats.stream()
322-
.map(ServerRoomStatisticsDto::getTotalPowerUsage)
323-
.filter(val -> val != null)
324-
.mapToDouble(Double::doubleValue)
325-
.sum();
326-
327-
Double avgPowerUsagePerRack = totalRacks > 0 ? totalPowerUsage / totalRacks : 0.0;
320+
// ❌ 10. 전력 통계 집계 - 삭제됨
328321

329322
// 11. 서버실별 요약 생성
330323
List<DataCenterStatisticsDto.ServerRoomSummaryDto> serverRoomSummaries = serverRoomStats.stream()
@@ -394,9 +387,9 @@ public DataCenterStatisticsDto calculateDataCenterStatistics(Long dataCenterId)
394387
.totalAlerts(totalAlerts)
395388
.criticalAlerts(criticalAlerts)
396389
.warningAlerts(warningAlerts)
397-
// 전력 통계
398-
.totalPowerUsage(totalPowerUsage)
399-
.avgPowerUsagePerRack(avgPowerUsagePerRack)
390+
// 전력 통계 삭제됨
391+
// .totalPowerUsage(totalPowerUsage)
392+
// .avgPowerUsagePerRack(avgPowerUsagePerRack)
400393
// 서버실별 요약
401394
.serverRoomSummaries(serverRoomSummaries)
402395
.build();

0 commit comments

Comments
 (0)