Skip to content

Commit

Permalink
Merge pull request #213 from hwangdaesun/feat/#206
Browse files Browse the repository at this point in the history
[BE/feat] 모니터링 환경 세팅
  • Loading branch information
hwangdaesun authored May 4, 2024
2 parents 76401a5 + 5c154f0 commit 85119b4
Show file tree
Hide file tree
Showing 21 changed files with 457 additions and 187 deletions.
11 changes: 10 additions & 1 deletion BE/exceed/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ FROM openjdk:17-oracle

ENV TZ=Asia/Seoul

# 앱을 위한 작업 디렉토리 설정
WORKDIR /app

# JAR 파일 복사
ARG JAR_FILE="./build/libs/*.jar"
COPY ${JAR_FILE} eatceed.jar

# CSV 파일 복사
COPY ./food_data.csv ./food_data.csv

EXPOSE 8080
CMD ["java", "-jar", "-Dspring.profiles.active=dev", "eatceed.jar"]

# CMD 명령어에서 CSV 파일의 위치를 절대 경로로 지정
CMD ["java", "-jar", "-Dspring.profiles.active=dev", "eatceed.jar", "./food_data.csv"]
6 changes: 6 additions & 0 deletions BE/exceed/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ dependencies {

//OpenCsv
implementation group: 'com.opencsv', name: 'opencsv', version: '5.7.1'

// Actuator
implementation 'org.springframework.boot:spring-boot-starter-actuator'

// Prometheus
implementation 'io.micrometer:micrometer-registry-prometheus'
}

tasks.named('bootBuildImage') {
Expand Down
43 changes: 38 additions & 5 deletions BE/exceed/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ services:
expose:
- "3306"
volumes:
- ./resources/gaebaljip-local-develop-environment/mariadb-conf:/etc/mysql/conf.d
- ./resources/gaebaljip-local-develop-environment/mariadb-init:/docker-entrypoint-initdb.d
- ./resources/gaebaljip-develop-environment/mariadb-conf:/etc/mysql/conf.d
- ./resources/gaebaljip-develop-environment/mariadb-init:/docker-entrypoint-initdb.d
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_ROOT_HOST=%
Expand All @@ -24,9 +24,7 @@ services:
- gaebaljip-network

eatceed-backend:
build:
context: .
dockerfile: Dockerfile
image: hwangdaesun/gaebaljip-dev:latest
container_name: gaebaljip-spring
ports:
- 8080:8080
Expand All @@ -52,6 +50,41 @@ services:
restart:
on-failure

grafana:
image: grafana/grafana:latest
container_name: grafana
restart: always
ports:
- "3000:3000"
volumes:
- grafana-data:/var/lib/grafana
- ./resources/gaebaljip-develop-environment/grafana/provisioning/:/etc/grafana/provisioning/
environment:
- GF_SERVER_ROOT_URL=localhost:3000
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD}
depends_on:
- prometheus
networks:
- gaebaljip-network

prometheus:
image: prom/prometheus:latest
container_name: prometheus
restart: always
ports:
- "9090:9090"
volumes:
- ./resources/gaebaljip-develop-environment/prometheus/config:/etc/prometheus/
- prometheus-data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
networks:
- gaebaljip-network

volumes:
grafana-data:
prometheus-data:

networks:
gaebaljip-network:
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
#추가
- job_name: "spring-actuator"
metrics_path: '/actuator/prometheus'
scrape_interval: 1s
static_configs:
- targets: ['3.37.117.77:8080']

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-server = utf8mb4
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE
USER 'gaebaljip-local'@'localhost' IDENTIFIED BY 'gaebaljip-local';
CREATE
USER 'gaebaljip-local'@'%' IDENTIFIED BY 'gaebaljip-local';

GRANT ALL PRIVILEGES ON *.* TO
'gaebaljip-local'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO
'gaebaljip-local'@'%';

CREATE
DATABASE gaebaljip DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use gaebaljip;


CREATE TABLE `MEMBER_TB`
(
`MEMBER_PK` bigint(20) NOT NULL AUTO_INCREMENT,
`CREATED_DATE` datetime(6) NOT NULL,
`UPDATED_DATE` datetime(6) NOT NULL,
`MEMBER_ACTIVITY` varchar(255) DEFAULT NULL,
`MEMBER_AGE` int(11) DEFAULT NULL,
`MEMBER_ETC` varchar(255) DEFAULT NULL,
`MEMBER_GENDER` tinyint DEFAULT NULL,
`MEMBER_HEIGHT` double DEFAULT NULL,
`MEMBER_EMAIL` varchar(255) NOT NULL UNIQUE,
`MEMBER_PASSWORD` varchar(255) NOT NULL,
`MEMBER_ROLE` varchar(255) DEFAULT NULL,
`MEMBER_WEIGHT` double DEFAULT NULL,
`MEMBER_CHECKED` bit NOT NULL,
PRIMARY KEY (`MEMBER_PK`)
) ENGINE=InnoDB;

CREATE TABLE `WEIGHT_TB`
(
`WEIGHT_PK` bigint(20) NOT NULL AUTO_INCREMENT,
`CREATED_DATE` datetime(6) NOT NULL,
`UPDATED_DATE` datetime(6) NOT NULL,
`WEIGHT_WEIGHT` double DEFAULT NULL,
`WEIGHT_TARGET_WEIGHT` double DEFAULT NULL,
`MEMBER_FK` bigint(20) DEFAULT NULL,
PRIMARY KEY (`WEIGHT_PK`),
FOREIGN KEY (`MEMBER_FK`) REFERENCES `MEMBER_TB` (`MEMBER_PK`)
) ENGINE=InnoDB;


CREATE TABLE `FOOD_TB`
(
`FOOD_PK` bigint(20) NOT NULL AUTO_INCREMENT,
`FOOD_CALORIE` double NOT NULL,
`FOOD_CARBOHYDRATE` double NOT NULL,
`FOOD_FAT` double NOT NULL,
`FOOD_MAIN_CATEGORY` varchar(255) NOT NULL,
`FOOD_NAME` varchar(255) NOT NULL,
`FOOD_PROTEIN` double NOT NULL,
`FOOD_SERVING_SIZE` double NOT NULL,
`FOOD_SUB_CATEGORY` varchar(255) NOT NULL,
PRIMARY KEY (`FOOD_PK`)
) ENGINE=InnoDB;


CREATE TABLE `MEAL_TB`
(
`MEAL_PK` bigint(20) NOT NULL AUTO_INCREMENT,
`CREATED_DATE` datetime(6) NOT NULL,
`UPDATED_DATE` datetime(6) NOT NULL,
`MEAL_TYPE` varchar(255) NOT NULL,
`MEAL_FOOD_MULTIPLE` double NOT NULL,
`MEMBER_FK` bigint(20) DEFAULT NULL,
PRIMARY KEY (`MEAL_PK`),
FOREIGN KEY (`MEMBER_FK`) REFERENCES `MEMBER_TB` (`MEMBER_PK`)
) ENGINE = InnoDB;

CREATE TABLE `MEAL_FOOD_TB`
(
`MEAL_FOOD_PK` bigint(20) NOT NULL AUTO_INCREMENT,
`CREATED_DATE` datetime(6) NOT NULL,
`UPDATED_DATE` datetime(6) NOT NULL,
`FOOD_FK` bigint(20) DEFAULT NULL,
`MEAL_FK` bigint(20) DEFAULT NULL,
PRIMARY KEY (`MEAL_FOOD_PK`),
FOREIGN KEY (`FOOD_FK`) REFERENCES `FOOD_TB` (`FOOD_PK`),
FOREIGN KEY (`MEAL_FK`)REFERENCES `MEAL_TB` (`MEAL_PK`)
) ENGINE=InnoDB;

CREATE TABLE `EAT_HABITS_TB`
(
`EAT_HABITS_PK` bigint(20) NOT NULL AUTO_INCREMENT,
`MEMBER_FK` bigint(20) DEFAULT NULL,
`CREATED_DATE` datetime(6) NOT NULL,
`FLAG` tinyint(1) NOT NULL,
`WEIGHT_PREDICTION` text NOT NULL,
`WEIGHT_ADVICE` text NOT NULL,
PRIMARY KEY (`EAT_HABITS_PK`),
FOREIGN KEY (`MEMBER_FK`) REFERENCES `MEMBER_TB` (`MEMBER_PK`)
) ENGINE = InnoDB;

CREATE TABLE `HISTORY_TB`
(
`HISTORY_PK` bigint(20) NOT NULL AUTO_INCREMENT,
`CREATED_DATE` datetime(6) NOT NULL,
`UPDATED_DATE` datetime(6) NOT NULL,
`HISTORY_ACTIVITY` varchar(255) NOT NULL ,
`HISTORY_AGE` int(11) NOT NULL,
`HISTORY_GENDER` tinyint NOT NULL,
`HISTORY_HEIGHT` double NOT NULL,
`HISTORY_WEIGHT` double NOT NULL,
`MEMBER_FK` bigint(20) DEFAULT NULL,
PRIMARY KEY (`HISTORY_PK`),
FOREIGN KEY (`MEMBER_FK`) REFERENCES `MEMBER_TB` (`MEMBER_PK`)
) ENGINE=InnoDB;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
#추가
- job_name: "spring-actuator"
metrics_path: '/actuator/prometheus'
scrape_interval: 1s
static_configs:
- targets: ['host.docker.internal:8080']
67 changes: 67 additions & 0 deletions BE/exceed/resources/gaebaljip-local-environment/setting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: '3'
services:
eatceed-mariadb:
image: mariadb:10.6
container_name: gaebaljip-local-mariadb
ports:
- 3306:3306
volumes:
- ./mariadb-conf:/etc/mysql/conf.d
- ./mariadb-init:/docker-entrypoint-initdb.d
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_ROOT_HOST=%
- TZ=Asia/Seoul

eatceed-redis:
image: redis:alpine
container_name: gaebaljip-local-redis
command: redis-server --port 6379
ports:
- 6379:6379

eatceed-adminer:
container_name: gaebaljip-local-adminer
image: adminer:4
ports:
- 18080:8080
depends_on:
- eatceed-mariadb
- eatceed-redis
links:
- eatceed-mariadb
- eatceed-redis

grafana:
image: grafana/grafana:latest
container_name: grafana
user: "$UID:$GID"
restart: always
ports:
- "3000:3000"
volumes:
- grafana-data:/var/lib/grafana
- ./grafana/provisioning/:/etc/grafana/provisioning/
environment:
- GF_SERVER_ROOT_URL=http://localhost:3000
- GF_SECURITY_ADMIN_PASSWORD=admin
depends_on:
- prometheus

prometheus:
image: prom/prometheus:latest
container_name: prometheus
restart: always
ports:
- "9090:9090"
volumes:
- ./prometheus/config:/etc/prometheus/
- prometheus-data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'

volumes:
grafana-data:
prometheus-data:

2 changes: 1 addition & 1 deletion BE/exceed/scripts/reset.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cd ../resources/gaebaljip-local-develop-environment
cd ../resources/gaebaljip-local-environment
docker-compose -f setting.yml down
docker-compose -f setting.yml up -d
sleep 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gaebaljip.exceed.config;

import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ActuatorConfig {
@Bean
public InMemoryHttpTraceRepository httpExchangeRepository() {
return new InMemoryHttpTraceRepository();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.permitAll()
.antMatchers(HttpMethod.POST, "/v1/auth/login")
.permitAll()
.antMatchers(HttpMethod.GET, "/actuator/**")
.permitAll()
.anyRequest()
.authenticated();

Expand Down
Loading

0 comments on commit 85119b4

Please sign in to comment.