Skip to content

Commit

Permalink
[BE] Spring Actuator 관련 설정을 추가한다. (#941)
Browse files Browse the repository at this point in the history
  • Loading branch information
shin-jisong authored Nov 6, 2024
1 parent 296d35d commit 863e466
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/bang-ggood/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-gson:0.11.2'

annotationProcessor 'org.projectlombok:lombok'

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'

runtimeOnly 'com.h2database:h2'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand Down
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());
}
}
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();
}
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();
}

0 comments on commit 863e466

Please sign in to comment.