-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BE] Spring Actuator 관련 설정을 추가한다. (#941)
- Loading branch information
1 parent
296d35d
commit 863e466
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
24 changes: 24 additions & 0 deletions
24
backend/bang-ggood/src/main/java/com/bang_ggood/global/config/MonitoringConfig.java
This file contains 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,24 @@ | ||
package com.bang_ggood.global.config; | ||
|
||
import com.bang_ggood.global.repository.MonitoringChecklistRepository; | ||
import com.bang_ggood.global.repository.MonitoringUserRepository; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import jakarta.annotation.PostConstruct; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
public class MonitoringConfig { | ||
|
||
private final MeterRegistry meterRegistry; | ||
private final MonitoringUserRepository monitoringUserRepository; | ||
private final MonitoringChecklistRepository monitoringChecklistRepository; | ||
|
||
@PostConstruct | ||
public void initMetrics() { | ||
meterRegistry.gauge("total.user.count", this, value -> monitoringUserRepository.countActiveUsers()); | ||
meterRegistry.gauge("total.checklist.count", this, | ||
value -> monitoringChecklistRepository.countActiveChecklists()); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...g-ggood/src/main/java/com/bang_ggood/global/repository/MonitoringChecklistRepository.java
This file contains 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,11 @@ | ||
package com.bang_ggood.global.repository; | ||
|
||
import com.bang_ggood.checklist.domain.Checklist; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface MonitoringChecklistRepository extends JpaRepository<Checklist, Long> { | ||
|
||
@Query("SELECT COUNT(c) FROM Checklist c WHERE c.deleted = false") | ||
long countActiveChecklists(); | ||
} |
11 changes: 11 additions & 0 deletions
11
...d/bang-ggood/src/main/java/com/bang_ggood/global/repository/MonitoringUserRepository.java
This file contains 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,11 @@ | ||
package com.bang_ggood.global.repository; | ||
|
||
import com.bang_ggood.user.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface MonitoringUserRepository extends JpaRepository<User, Long> { | ||
|
||
@Query("SELECT COUNT(u) FROM User u WHERE u.deleted = false") | ||
long countActiveUsers(); | ||
} |