Skip to content
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

[BE] Spring Actuator 관련 설정을 추가한다. #941

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
Loading