From 381aa161e069f84d4783ede420fbea486f3369cd Mon Sep 17 00:00:00 2001 From: kaffa Date: Thu, 9 Apr 2026 06:12:29 +0900 Subject: [PATCH] =?UTF-8?q?anomaly-detect:=20=EB=B9=84=EC=9A=A9=20?= =?UTF-8?q?=EB=A1=9C=EA=B9=85=20=EC=B6=94=EA=B0=80=20(48eb489)=20=EB=B0=8F?= =?UTF-8?q?=20=EC=A7=91=EA=B3=84=20=EB=AA=85=EB=A0=B9=20=EB=AC=B8=EC=84=9C?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - cycle usage 로그 형식과 집계 명령어 - OpenRouter /activity API 지연 caveat - management key Vault 위치 - 월 비용 예상 추가 --- infra/anomaly-detect.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/infra/anomaly-detect.md b/infra/anomaly-detect.md index cebfa9d..6a4c90d 100644 --- a/infra/anomaly-detect.md +++ b/infra/anomaly-detect.md @@ -90,6 +90,7 @@ LLM 프롬프트가 무시되어도 실수로 사설망이 ban되지 않음. - `af2873d` — `simulate.py` mock 기반 smoke test (5/5 시나리오 PASS) - `d7789ad` — `DRY_RUN=0` 활성화 (E2E 검증 후) - `23c67bd` — 스케일 업 (`MAX_BAN_PER_CYCLE` 100→2000, LAPI chunk POST, exec_logsql 200KB, 2000 IP 시나리오 추가 — 6/6 PASS) +- `48eb489` — 사이클당 token/cost 누적 로깅 (`cycle usage: ... cost=$X`) ### E2E 검증 (2026-04-08) @@ -108,6 +109,32 @@ LLM 프롬프트가 무시되어도 실수로 사설망이 ban되지 않음. - **injected 로그 잔재**: E2E 테스트 중 주입한 270 rows가 vlogs retention 기간 동안 남음. `sim_e2e` 마커 필드로 식별 가능. 다음 cycle에서 다시 탐지될 수 있으나 dedup 24h으로 재ban 차단됨. - **재테스트 시**: 테스트 후 반드시 `cscli decisions delete -s anomaly-detect/` + `/var/lib/anomaly-detect/dedup.json` 업데이트 (해당 IP 추가하거나 리셋) +### 비용 모니터링 + +매 사이클 journalctl에 한 줄 요약 출력 (`48eb489` 이후): + +``` +cycle usage: turns=5 prompt=9142 completion=2670 total=11812 cost=$0.001866 +``` + +집계 명령: + +```bash +# 오늘 누적 +ssh incus-hp2 "incus exec anomaly-detect -- bash -c ' + journalctl -u anomaly-detect.service --since today --no-pager | + grep -oE \"cost=\\\$[0-9.]+\" | + awk -F\\\$ \"{sum+=\\\$2} END {printf \\\"today: \\\$%.6f (%d cycles)\\n\\\", sum, NR}\" +'" + +# 사이클별 상세 +ssh incus-hp2 "incus exec anomaly-detect -- journalctl -u anomaly-detect.service --since today --no-pager | grep 'cycle usage'" +``` + +**OpenRouter `/activity` API의 지연** (~2-3주)으로 실시간 비용 조회는 여기(journalctl) 경로를 써야 한다. dashboard는 https://openrouter.ai/activity 에서 UI 확인 가능 (더 빠름). management(provisioning) 키는 Vault `secret/ai/openrouter` → `PROVISIONING_KEY` 에 저장됨. + +**월 비용 예상**: 평시 사이클당 ~$0.001-0.002, 5분 주기 × 288/일 × 30일 = **~$10-15/월**. DDoS 발생 시 사이클당 $0.01 수준 (massive_ddos 시나리오 기준)까지 튈 수 있으나 일시적. + [[crowdsec-safeline#~~ddos-detect (AI 행위 분석)~~ — 폐기 (2026-04-08)|폐기된 ddos-detect]] 후속. [[victorialogs|VictoriaLogs]]에 적재된 K3s 서울 APISIX access log를 5분마다 분석하여 봇/공격성 IP를 [[crowdsec-safeline|CrowdSec]]에 자동 ban으로 등록한다. ## 위치 / 사양