-
Notifications
You must be signed in to change notification settings - Fork 1
hikari, tomcat 모니터링 코드 추가 #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e72c534
[Fix]Test 코드 수정
hykim02 1dbbc56
[Fix]public 접근지정자 private으로 변경(캡슐화)
hykim02 b91f4a7
[Refactor]CafeteriaServiceV2 단일 책임 원칙 적용하여 클래스 분리
hykim02 f19aa3d
Update Java CI-CD.yml
hykim02 7f9a50e
merge conflict 해결
hykim02 0c7cd50
merge conflict 해결 중
hykim02 dd851d2
[Refactor]CampusServiceV2 클래스 분리
hykim02 c098a0c
merge conflict
hykim02 2a7290c
Merge branch 'main' of https://github.com/GNU-connect/Server-JavaSpring
hykim02 fbca9f3
[Refactor]DietServiceV2 서비스 클래스 분리
hykim02 4e67e9e
merge
hykim02 a4eb0a9
[fix]caheable 주석 처리 - 잠깐 보류
hykim02 e70e82b
[fix]Cafeteria Cacheable 주석처리
hykim02 9b7b803
Merge branch 'main' into main
hykim02 00f3532
[Refactor]캐시 적용 및 중복로직 최적화
hykim02 6f829d9
[Refactor]캐시 적용 및 중복 로직 최적화
hykim02 931b37c
Merge remote-tracking branch 'origin/main'
hykim02 cbd71ef
[fix]userService에서 발생한 hikariCP connection error 찾는 중
hykim02 bd75fde
Merge branch 'main' into main
hykim02 0165d50
[Test]HikariCP 멀티스레드 환경 테슽
hykim02 14c8c57
[Fix]conflict 해결
hykim02 f5d6eea
Merge branch 'GNU-connect:main' into main
hykim02 17ab978
merge 충돌
hykim02 a5704cb
[Fix]파일명 수정
hykim02 c1f0134
[Fix]파일명 수정
hykim02 e1916ba
Merge branch 'GNU-connect:main' into main
hykim02 4797300
[Feat]hikari, tomcat monitoring code
hykim02 95b7613
[Fix]redis db 수정 위해 cacheable 주석처리
hykim02 eef3202
[Fix]code rabbit 반영
hykim02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/Jinus/monitor/HikariCPMonitor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.example.Jinus.monitor; | ||
|
|
||
| import com.zaxxer.hikari.HikariDataSource; | ||
| import com.zaxxer.hikari.HikariPoolMXBean; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class HikariCPMonitor { | ||
|
|
||
| private final HikariDataSource dataSource; | ||
|
|
||
| @Autowired | ||
| public HikariCPMonitor(HikariDataSource dataSource) { | ||
| this.dataSource = dataSource; | ||
| } | ||
|
|
||
| @Scheduled(fixedRate = 1000) // 10초마다 상태 출력 | ||
| public void logHikariStatus() { | ||
| if (dataSource != null) { | ||
| HikariPoolMXBean poolMXBean = dataSource.getHikariPoolMXBean(); | ||
|
|
||
|
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add null check for poolMXBean While there's a null check for the dataSource, there's no check for poolMXBean before accessing its methods, which could lead to a NullPointerException. if (dataSource != null) {
HikariPoolMXBean poolMXBean = dataSource.getHikariPoolMXBean();
+
+ if (poolMXBean == null) {
+ log.warn("HikariPoolMXBean is null, cannot monitor connection pool");
+ return;
+ } |
||
| int total = poolMXBean.getTotalConnections(); | ||
| int active = poolMXBean.getActiveConnections(); | ||
| int idle = poolMXBean.getIdleConnections(); | ||
| int waiting = poolMXBean.getThreadsAwaitingConnection(); | ||
|
|
||
| System.out.printf( | ||
| "[HikariCP 상태] 전체: %d / 사용 중: %d / 유휴: %d / 대기 중: %d%n", | ||
| total, active, idle, waiting | ||
| ); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
47 changes: 47 additions & 0 deletions
47
src/main/java/com/example/Jinus/monitor/TomcatThreadMonitor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package com.example.Jinus.monitor; | ||
|
|
||
| import org.apache.catalina.connector.Connector; | ||
| import org.apache.coyote.ProtocolHandler; | ||
| import org.apache.coyote.AbstractProtocol; | ||
| import org.apache.tomcat.util.threads.ThreadPoolExecutor; | ||
| import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; | ||
| import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.util.concurrent.Executor; | ||
|
|
||
| @Component | ||
| public class TomcatThreadMonitor { | ||
|
|
||
| private final ServletWebServerApplicationContext context; | ||
|
|
||
| public TomcatThreadMonitor(ServletWebServerApplicationContext context) { | ||
| this.context = context; | ||
| } | ||
|
|
||
| @Scheduled(fixedRate = 1000) // 10초마다 출력 | ||
| public void logTomcatThreadPoolStatus() { | ||
| if (context.getWebServer() instanceof TomcatWebServer tomcatWebServer) { | ||
| Connector connector = tomcatWebServer.getTomcat().getConnector(); | ||
| ProtocolHandler handler = connector.getProtocolHandler(); | ||
|
|
||
| if (handler instanceof AbstractProtocol<?> protocol) { | ||
| Executor executor = protocol.getExecutor(); | ||
|
|
||
| if (executor instanceof ThreadPoolExecutor threadPoolExecutor) { | ||
| int max = threadPoolExecutor.getMaximumPoolSize(); | ||
| int poolSize = threadPoolExecutor.getPoolSize(); | ||
| int active = threadPoolExecutor.getActiveCount(); | ||
| long taskCount = threadPoolExecutor.getTaskCount(); | ||
| long completedTaskCount = threadPoolExecutor.getCompletedTaskCount(); | ||
|
|
||
| System.out.printf( | ||
| "[Tomcat 스레드] MaxPoolSize: %d, PoolSize: %d, 활성: %d, TaskCount: %d, 완료: %d%n", | ||
| max, poolSize, active, taskCount, completedTaskCount | ||
| ); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
src/main/java/com/example/Jinus/service/userInfo/CollegeService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,16 @@ | ||
| package com.example.Jinus.service.userInfo; | ||
|
|
||
| import com.example.Jinus.entity.userInfo.CollegeEntity; | ||
| import com.example.Jinus.repository.userInfo.CollegeRepository; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| public class CollegeService { | ||
| private static final Logger logger = LoggerFactory.getLogger(CollegeService.class); | ||
| private final CollegeRepository collegeRepository; | ||
|
|
||
| public CollegeService(CollegeRepository collegeRepository) { | ||
| this.collegeRepository = collegeRepository; | ||
| // logger.info("CollegeService 실행"); | ||
| } | ||
|
|
||
| public String getCollegeName(int collegeId) { | ||
| // logger.info("getCollegeName 실행"); | ||
| CollegeEntity collegeEntity = collegeRepository.findById(collegeId).orElse(null); | ||
| // logger.info("collegeEntity: {}", collegeEntity); | ||
|
|
||
| if (collegeEntity != null) { | ||
| // logger.info("collegeEng: {}", collegeEntity.getCollegeEng()); | ||
| return collegeEntity.getCollegeEng(); // 학과 영어 이름 리턴(테이블 찾기 위함) | ||
| } else { | ||
| logger.debug("CollegeService: collge를 찾을 수 없습니다."); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| public boolean checkEtcValue(int collegeId) { | ||
| CollegeEntity collegeEntity = collegeRepository.findById(collegeId).orElse(null); | ||
| return collegeEntity.isEtcValue(); | ||
| } | ||
|
|
||
| // collegeId에 해당하는 campusId 찾기 | ||
| public int getCampusId(int collegeId) { | ||
| // logger.info("getCampusId 실행"); | ||
| int campusId = collegeRepository.findCampusId(collegeId); | ||
| // logger.info("campusId: {}", campusId); | ||
|
|
||
| return campusId; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.