C.W.K.
Stream
Lesson 07 of 10 · published

모니터링 — 봐야 할 것

~12 min · monitoring, production

Level 0Scout
0 XP0/80 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

뭔가 잘못됐다고 알려주는 숫자

SQLite 는 조용함 — 데몬 X, 빌트인 metric endpoint X. Application 쪽에서 observability 빌드. 추적 가치 있는 신호:

  • DB 파일 사이즈 — 갑작스런 성장, 정체, 축소 다 의미.
  • WAL 파일 사이즈 — 큰 WAL = checkpointer 가 못 따라감; reader 가 write 막을 수도.
  • Query latency — store class wrap 해서 모든 query 시간 측정, metric backend 에 send.
  • SQLITE_BUSY count — 보이면 busy_timeout 너무 짧거나 transaction 너무 김.
  • Integrity check pass/fail — schedule, fail 에 alert.
  • Disk free — VACUUM + 백업 공간 필요; 모자라면 나쁨.
Self-reference: 피파의 /api/health endpoint 가 SQLite 사이즈, JSONL 사이즈, last-write timestamp, integrity check status 보고. WebUI 가 작은 status dot — 녹/노/빨 — 보여서 아빠가 한 눈에 데이터 레이어 건강 파악.

Code

싼 health-check endpoint·python
import os, time
from fastapi import APIRouter, Request

router = APIRouter()

@router.get('/api/health/db')
async def db_health(request: Request):
    conn = request.app.state.store.conn
    db_path = 'myapp.db'
    started = time.perf_counter()
    n = (await (await conn.execute('SELECT count(*) AS n FROM messages')).fetchone())['n']
    elapsed_ms = (time.perf_counter() - started) * 1000
    return {
        'rows': n,
        'count_ms': round(elapsed_ms, 2),
        'db_size_bytes': os.path.getsize(db_path),
        'wal_size_bytes': (
            os.path.getsize(db_path + '-wal') if os.path.exists(db_path + '-wal') else 0
        ),
    }

External links

Exercise

본인 서비스 하나에 health endpoint 추가 — DB 사이즈, WAL 사이즈, 핵심 테이블 row count, 측정 시간. 주기적 (분 마다) hit + 며칠간 값 그래프. Surprise 패턴 + 진짜 문제 의미하는지 기록.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.