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

Feat/#66 : 모니터링 툴 연동 및 출력 값 프론트 화면에 맞추어 수정 #69

Merged
merged 14 commits into from
Feb 19, 2025
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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ dependencies {

// file extension
implementation 'commons-io:commons-io:2.11.0'

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

tasks.named('test') {
Expand Down
77 changes: 77 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ services:
networks:
- app-network

prometheus:
image: prom/prometheus
container_name: prometheus
volumes:
- ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
networks:
- app-network
depends_on:
- application

grafana:
image: grafana/grafana
container_name: grafana
depends_on:
- prometheus
volumes:
- ./monitoring/grafana/datasources.yml:/etc/grafana/provisioning/datasources/datasources.yml
ports:
- "3000:3000"
networks:
- app-network

application:
container_name: book-mile-app
build:
Expand All @@ -42,12 +66,65 @@ services:
env_file:
- .env
command: [ "java", "-jar", "/app.jar" ]
volumes:
- ./logs:/var/log/book-mile
networks:
- app-network

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.5.1
container_name: elasticsearch
environment:
- discovery.type=single-node
- xpack.security.enabled=false
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ports:
- "9200:9200"
volumes:
- elasticsearch_data:/usr/share/elasticsearch/data
networks:
- app-network

kibana:
image: docker.elastic.co/kibana/kibana:8.5.1
container_name: kibana
depends_on:
- elasticsearch
ports:
- "5601:5601"
networks:
- app-network

logstash:
image: docker.elastic.co/logstash/logstash:8.5.1
container_name: logstash
volumes:
- ./monitoring/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
ports:
- "5044:5044"
depends_on:
- elasticsearch
networks:
- app-network

filebeat:
image: docker.elastic.co/beats/filebeat:8.5.1
container_name: filebeat
user: root
command: filebeat -e -strict.perms=false
volumes:
- ./monitoring/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
- ./logs:/var/log/book-mile
depends_on:
- logstash
networks:
- app-network

volumes:
mysql_data:
redis_data:
elasticsearch_data:

networks:
app-network:
Expand Down
325 changes: 325 additions & 0 deletions logs/app.log

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions monitoring/filebeat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/book-mile/*.log
fields:
service: book-mile
json.keys_under_root: false
json.add_error_key: true

output.logstash:
hosts: ["logstash:5044"]
7 changes: 7 additions & 0 deletions monitoring/grafana/datasources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
20 changes: 20 additions & 0 deletions monitoring/logstash.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
input {
beats {
port => 5044
}
}

filter {
json {
source => "message"
remove_field => ["@version", "host"]
}
}

output {
elasticsearch {
hosts => ["http://elasticsearch:9200"]
index => "spring-logs-%{+YYYY.MM.dd}"
}
stdout { codec => rubydebug }
}
17 changes: 17 additions & 0 deletions monitoring/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
global:
scrape_interval: 15s

scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

- job_name: 'spring-boot-app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['host.docker.internal:8080']
#- targets: ['book-mile-app:8080']

- job_name: 'node-exporter'
static_configs:
- targets: ['node-exporter:9100']
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class BestSellerResponseDto {
private String author;
private String publisher;
private String cover;
private String isbn13;
private int customerReviewRank;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class NewBookResponseDto {
private String author;
private String publisher;
private String cover;
private String isbn13;
private int customerReviewRank;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BookDetailServiceImpl implements BookDetailService {

@Override
public List<BookDetailResponseDto> detailBooks(BookDetailRequestDto bookDetailRequestDto) {
String url = String.format("%s?ttbkey=%s&ItemIdType=ISBN13&ItemId=%s&output=js&Version=20131101",
String url = String.format("%s?ttbkey=%s&ItemIdType=ISBN13&ItemId=%s&Cover=Big&output=js&Version=20131101",
API_URL, TTB_KEY, bookDetailRequestDto.getIsbn13());

ResponseEntity<BookDetailApiResponse> response = restTemplate.getForEntity(url, BookDetailApiResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class BookListServiceImpl implements BookListService {
@Override
public List<BookListResponseDto> searchBooks(BookListRequestDto requestDto) {
// 알라딘 API 요청 URL 구성
String url = String.format("%s?ttbkey=%s&Query=%s&QueryType=%s&MaxResults=%d&Sort=%s&output=js&Version=20131101",
String url = String.format("%s?ttbkey=%s&Query=%s&QueryType=%s&MaxResults=%d&Sort=%s&Cover=Big&output=js&Version=20131101",
API_URL, TTB_KEY, requestDto.getQuery(), requestDto.getQueryType(), requestDto.getMaxResults(), requestDto.getSort());

// JSON 응답을 BookSearchApiResponse로 매핑
Expand All @@ -46,7 +46,7 @@ public List<BookListResponseDto> searchBooks(BookListRequestDto requestDto) {

@Override
public List<BestSellerResponseDto> getBestSellerList() {
String url = String.format("%s?ttbkey=%s&QueryType=Bestseller&MaxResults=10&start=1&SearchTarget=Book&output=js&Version=20131101",
String url = String.format("%s?ttbkey=%s&QueryType=Bestseller&MaxResults=12&start=1&SearchTarget=Book&Cover=Big&output=js&Version=20131101",
BOOKLIST_API_URL, TTB_KEY);

ResponseEntity<BestSellerApiResponse> response = restTemplate.getForEntity(url, BestSellerApiResponse.class);
Expand All @@ -62,7 +62,7 @@ public List<BestSellerResponseDto> getBestSellerList() {

@Override
public List<NewBookResponseDto> getNewBookList() {
String url = String.format("%s?ttbkey=%s&QueryType=ItemNewSpecial&MaxResults=10&start=1&SearchTarget=Book&output=js&Version=20131101",
String url = String.format("%s?ttbkey=%s&QueryType=ItemNewSpecial&MaxResults=12&start=1&SearchTarget=Book&Cover=Big&output=js&Version=20131101",
BOOKLIST_API_URL, TTB_KEY);

ResponseEntity<NewBookApiResponse> response = restTemplate.getForEntity(url, NewBookApiResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ public class GroupDetailResponseDto {
private String goalContent;
private String masterNickname;
private String masterImage;
private Long bookId;

@Builder
private GroupDetailResponseDto(Long groupId, String groupName, String groupDescription, int maxMembers, int currentMembers,
GroupStatus status, BookResponseDto book, String goalType,
String goalContent, String masterNickname, String masterImage) {
String goalContent, String masterNickname, String masterImage, Long bookId) {
this.groupId = groupId;
this.groupName = groupName;
this.groupDescription = groupDescription;
Expand All @@ -38,6 +39,7 @@ private GroupDetailResponseDto(Long groupId, String groupName, String groupDescr
this.goalContent = goalContent;
this.masterNickname = masterNickname;
this.masterImage = masterImage;
this.bookId = bookId;
}

public static GroupDetailResponseDto toDto(Group group, int currentMembers, User masterUser) {
Expand All @@ -53,6 +55,7 @@ public static GroupDetailResponseDto toDto(Group group, int currentMembers, User
.goalContent(group.getGoalContent())
.masterNickname(masterUser.getNickname())
.masterImage(masterUser.getImage())
.bookId(group.getBook().getId())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers("/api/v1/users/email", "/api/v1/users/email/verify").permitAll()
.requestMatchers("/api/v1/oauth2/test").permitAll()
.requestMatchers( "/oauth2/**", "/login/oauth2/code/**").permitAll()
.requestMatchers("/actuator/**").permitAll()
.anyRequest().authenticated())
.addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new JwtExceptionHandlerFilter(), JwtAuthenticationFilter.class)
Expand Down