C.W.K.
Stream
Lesson 02 of 05 · published

상태 헤더 — 모든 걸 말해주는 3 숫자

~15 min · status-header, metrics, color

Level 0Greenhorn
0 XP0/53 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

헤더가 가장 먼저, 가장 자주 보는 부분. "다 정상이야?" 를 1초 안에 답해야.

3 숫자

지표정상황색적색
Active session1–2 (너)3–4 (노트북 + 폰 + 태블릿)5+ 또는 모르는 IP 의 session
실패 시도 (지난 시간)01–35+ (probable brute force)
Blacklisted IP01–25+ (뭔가 네 노리는 중)

색 인코딩

색 써, 근데 색만 의존 X. 각 배지에 아이콘 (✅ ⚠️ 🚨) 과 카운트도 — colorblind / dark-mode / 폰 glance 시나리오 다 작동.

Code

각 지표 뒤의 쿼리·python
def dashboard_stats():
    active = db.execute(
        "SELECT COUNT(*) FROM security_sessions WHERE expires_at > ?",
        (now(),)
    ).fetchone()[0]

    fails_1h = db.execute("""
      SELECT COUNT(*) FROM security_attempts
      WHERE success = 0 AND attempted_at > ?
    """, (now() - 3600,)).fetchone()[0]

    blacklisted = db.execute(
        "SELECT COUNT(*) FROM security_blacklist"
    ).fetchone()[0]

    status = "green"
    if fails_1h >= 5 or blacklisted >= 5:
        status = "red"
    elif fails_1h >= 1 or blacklisted >= 1:
        status = "yellow"

    return {"active": active, "fails_1h": fails_1h,
            "blacklisted": blacklisted, "status": status}

External links

Exercise

dashboard_stats() 구현하고 3 숫자를 /admin/security 페이지의 색칠된 배지로 렌더. fails_1h 올리려고 security_attempts 에 수동 row 삽입하고 상태가 녹 → 황 → 적 으로 flip 보고 테스트. 임계값은 트래픽에 맞게 튜닝 가능.

Progress

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

댓글 0

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

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