모니터링 및 로깅
로그 시스템
hereby 플랫폼은 Pino 로거를 사용하며, 구조화된 JSON 로그를 출력합니다.
로그 레벨
| 레벨 | 용도 |
|---|---|
debug | 상세 디버깅 정보 |
info | 일반 운영 정보 (기본값) |
warn | 경고 (즉시 조치 불필요) |
error | 오류 (조치 필요) |
로그 레벨 변경
환경 변수로 로그 레벨을 설정합니다:
bash
# .env
LOG_LEVEL=info # debug, info, warn, errorDocker 컨테이너 로그
로그 확인
bash
# 전체 로그
docker-compose logs
# 특정 서비스 실시간 로그
docker-compose logs -f postgres
docker-compose logs -f redis
# 최근 100줄만
docker-compose logs --tail=100 postgresAPI 서버 로그
bash
# API 서버 로그 확인
pnpm --filter @hereby/api dev 2>&1 | tee api.log헬스 체크
PostgreSQL
bash
# 연결 테스트
docker exec hereby_postgres pg_isready -U hereby_admin
# 상태 확인
docker exec hereby_postgres psql -U hereby_admin -d hereby_platform -c "SELECT 1;"Redis
bash
# 연결 테스트
docker exec hereby_redis redis-cli ping
# 응답: PONG
# 메모리 사용량
docker exec hereby_redis redis-cli info memoryDocker 컨테이너 상태
bash
# 전체 컨테이너 상태
docker-compose ps
# 리소스 사용량 (CPU, 메모리)
docker stats --no-stream성능 모니터링
PostgreSQL 성능
sql
-- 느린 쿼리 로깅 활성화 (postgresql.conf)
-- log_min_duration_statement = 1000 -- 1초 이상 쿼리 로깅
-- 캐시 히트율 확인
SELECT
sum(heap_blks_read) as heap_read,
sum(heap_blks_hit) as heap_hit,
round(sum(heap_blks_hit) / (sum(heap_blks_hit) + sum(heap_blks_read))::numeric, 4) as ratio
FROM pg_statio_user_tables;
-- 인덱스 사용률 확인
SELECT
relname,
idx_scan as index_scans,
seq_scan as sequential_scans
FROM pg_stat_user_tables
ORDER BY seq_scan DESC
LIMIT 10;디스크 사용량
bash
# 데이터베이스 크기
docker exec hereby_postgres psql -U hereby_admin -d hereby_platform \
-c "SELECT pg_size_pretty(pg_database_size('hereby_platform'));"
# Docker 볼륨 크기
docker system df -v알림 설정
디스크 공간 모니터링 스크립트
bash
#!/bin/bash
# scripts/check-disk.sh
THRESHOLD=80
USAGE=$(df / | tail -1 | awk '{print $5}' | sed 's/%//')
if [ "$USAGE" -gt "$THRESHOLD" ]; then
echo "WARNING: 디스크 사용량 ${USAGE}%가 임계값 ${THRESHOLD}%를 초과했습니다"
# 알림 전송 로직 추가
fiPostgreSQL 연결 수 모니터링
bash
#!/bin/bash
# scripts/check-connections.sh
MAX_CONNECTIONS=100
CURRENT=$(docker exec hereby_postgres psql -U hereby_admin -d hereby_platform \
-t -c "SELECT count(*) FROM pg_stat_activity;")
if [ "$CURRENT" -gt "$MAX_CONNECTIONS" ]; then
echo "WARNING: DB 연결 수 ${CURRENT}가 임계값을 초과했습니다"
fi