[Scouter APM 연동]
- core/scouter.py: Scouter HTTP API 클라이언트
- get_summary(): 전체 WAS 모니터링 현황 (CPU/TPS/응답시간/위험서버)
- get_server_metrics(): 특정 서버 실시간 메트릭
- get_alert_list(): Scouter 경보 목록
- get_xlog_recent(): 최근 트랜잭션 X-Log
- routers/scouter.py: REST API 엔드포인트 (6개)
- GET /api/scouter/status, /servers, /servers/{hash}/metrics
- GET /api/scouter/servers/{hash}/services, /xlog, /alerts
- POST /api/scouter/agent/deploy: SSH로 scouter-agent.jar 자동 배포
[스케줄러]
- scheduler.py: Scouter 경보 수집 (5분마다)
- CPU > 80% 또는 에러율 > 5% 서버 자동 감지 → GUARDiA 알림
[Docker Compose]
- docker-compose.yml: scouteross/scouter-server:2.20.0 서비스 추가
- 포트 6100 (UDP/TCP 에이전트 수집) + 6180 (HTTP API)
[설치 스크립트]
- setup/scouter/download_scouter.sh: 에이전트/서버 다운로드
- scouter-agent.jar + agent.conf.template 생성
- setup_ubuntu.sh: Scouter 서버 설치 단계 추가 (14단계로 확장)
- --test 검증: Scouter API + Gitea HTTP 검사 추가
환경변수: SCOUTER_HOST, SCOUTER_HTTP_PORT=6180, SCOUTER_USER, SCOUTER_PASSWORD
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
299 lines
12 KiB
Python
299 lines
12 KiB
Python
from contextlib import asynccontextmanager
|
||
|
||
from fastapi import FastAPI
|
||
from fastapi.responses import FileResponse
|
||
from fastapi.staticfiles import StaticFiles
|
||
|
||
from database import init_db
|
||
from fastapi.middleware.cors import CORSMiddleware
|
||
|
||
from routers import (
|
||
approvals, assign, audit, auth, cmdb, dashboard, kb, nlcmd, rating, tasks, work,
|
||
institutions, shell_scripts, timetable, attachments, notifications,
|
||
messenger, ssh, projects, vibe,
|
||
ssl_manager, pm, incidents, oncall, batch,
|
||
si_projects, si_wbs, si_requirements, si_issues,
|
||
si_risks, si_milestones, si_change_requests, si_tests,
|
||
agents,
|
||
analytics,
|
||
ws as ws_router,
|
||
timeline,
|
||
code_review,
|
||
anomaly,
|
||
chatbot,
|
||
kb_agent,
|
||
orchestrator,
|
||
predictive,
|
||
change,
|
||
problem,
|
||
capacity,
|
||
catalog,
|
||
ldap,
|
||
pam,
|
||
vuln_scan,
|
||
report,
|
||
metrics,
|
||
finops,
|
||
tenant_mgmt,
|
||
gateway,
|
||
license as license_router,
|
||
learning,
|
||
push as push_router,
|
||
scouter as scouter_router,
|
||
)
|
||
|
||
|
||
@asynccontextmanager
|
||
async def lifespan(app: FastAPI):
|
||
# 디렉토리 생성
|
||
from pathlib import Path
|
||
(Path(__file__).parent / "uploads" / "sr_files").mkdir(parents=True, exist_ok=True)
|
||
(Path(__file__).parent / "uploads" / "workspaces").mkdir(parents=True, exist_ok=True)
|
||
|
||
await init_db()
|
||
from database import SessionLocal
|
||
from core.seed import seed_all
|
||
async with SessionLocal() as db:
|
||
await seed_all(db)
|
||
|
||
# 라이선스 상태 확인 (시작 시) — TRIAL 키는 GUARDIA_LICENSE_KEY 없이도 동작
|
||
from routers.license import get_license_status
|
||
async with SessionLocal() as db:
|
||
lic_status = await get_license_status(db)
|
||
if lic_status.get("valid"):
|
||
edition = lic_status["edition"]
|
||
days = lic_status["days_remaining"]
|
||
cust = lic_status["customer"]
|
||
if lic_status.get("is_trial"):
|
||
print(f"[LICENSE] TRIAL 체험판 활성 (D-{days}) - {cust}")
|
||
else:
|
||
print(f"[LICENSE] {edition} 라이선스 활성 ({days}일 남음) - {cust}")
|
||
if lic_status.get("expiry_warning"):
|
||
print(f"[LICENSE] 만료 {days}일 남음 - 갱신을 준비하세요.")
|
||
elif lic_status.get("expired"):
|
||
print("[LICENSE] 라이선스가 만료되었습니다. 갱신이 필요합니다.")
|
||
else:
|
||
print("[LICENSE] 라이선스 미등록 - /license 에서 무료 체험을 시작하거나 키를 등록하세요.")
|
||
|
||
# A-1: WebSocket ↔ SSE 통합 패치
|
||
from routers.ws import _integrate_with_sse_bus
|
||
_integrate_with_sse_bus()
|
||
|
||
# 백그라운드 스케줄러 시작
|
||
from core.scheduler import start_scheduler, init_batch_jobs_from_db
|
||
start_scheduler()
|
||
await init_batch_jobs_from_db() # DB에서 활성 배치 잡 자동 등록
|
||
|
||
yield
|
||
|
||
# 스케줄러 종료
|
||
from core.scheduler import stop_scheduler
|
||
stop_scheduler()
|
||
|
||
# F-2: Redis 연결 종료
|
||
try:
|
||
from core.cache import close_redis
|
||
await close_redis()
|
||
except Exception:
|
||
pass
|
||
|
||
|
||
app = FastAPI(title="GUARDiA ITSM", version="1.0.0", lifespan=lifespan)
|
||
|
||
# ── F-2: Redis 캐시 종료 훅 ──────────────────────────────────────────────────
|
||
# (lifespan의 yield 이후에 실행 — close_redis는 shutdown시 호출)
|
||
|
||
# ── F-3: Rate Limiting 미들웨어 등록 ─────────────────────────────────────────
|
||
from core.ratelimit import setup_rate_limiting
|
||
setup_rate_limiting(app)
|
||
|
||
app.add_middleware(
|
||
CORSMiddleware,
|
||
allow_origins=["http://localhost:8001", "http://127.0.0.1:8001"],
|
||
allow_methods=["*"],
|
||
allow_headers=["*"],
|
||
)
|
||
|
||
app.include_router(auth.router)
|
||
app.include_router(dashboard.router)
|
||
app.include_router(assign.router)
|
||
app.include_router(kb.router)
|
||
app.include_router(nlcmd.router)
|
||
app.include_router(tasks.router)
|
||
app.include_router(approvals.router)
|
||
app.include_router(cmdb.router)
|
||
app.include_router(audit.router)
|
||
app.include_router(work.router)
|
||
app.include_router(rating.router)
|
||
app.include_router(institutions.router)
|
||
app.include_router(shell_scripts.router)
|
||
app.include_router(timetable.router)
|
||
app.include_router(attachments.router)
|
||
app.include_router(notifications.router)
|
||
app.include_router(messenger.router)
|
||
app.include_router(ssh.router)
|
||
app.include_router(projects.router)
|
||
app.include_router(vibe.router)
|
||
app.include_router(ssl_manager.router)
|
||
app.include_router(pm.router)
|
||
app.include_router(incidents.router)
|
||
app.include_router(oncall.router)
|
||
app.include_router(batch.router)
|
||
|
||
# ── SI 프로젝트 관리 (분석→설계→구현→인도) ─────────────────────────────────
|
||
app.include_router(si_projects.router)
|
||
app.include_router(si_wbs.router)
|
||
app.include_router(si_requirements.router)
|
||
app.include_router(si_issues.router)
|
||
app.include_router(si_risks.router)
|
||
app.include_router(si_milestones.router)
|
||
app.include_router(si_change_requests.router)
|
||
app.include_router(si_tests.router)
|
||
|
||
# ── AI 에이전트 (Paperclip × GUARDiA, Ollama 로컬 LLM) ──────────────────────
|
||
app.include_router(agents.router)
|
||
|
||
# ── Analytics (E-2 배포 성공률 트렌드, E-3 엔지니어 워크로드) ─────────────────
|
||
app.include_router(analytics.router)
|
||
|
||
# ── A-1: WebSocket 실시간 대시보드 ───────────────────────────────────────────
|
||
app.include_router(ws_router.router)
|
||
|
||
# ── A-4: 운영 이벤트 타임라인 ────────────────────────────────────────────────
|
||
app.include_router(timeline.router)
|
||
|
||
# ── B-3: 코드 리뷰 에이전트 ──────────────────────────────────────────────────
|
||
app.include_router(code_review.router)
|
||
|
||
# ── B-1: AI 이상 탐지 ────────────────────────────────────────────────────────
|
||
app.include_router(anomaly.router)
|
||
|
||
# ── B-2: 자연어 SR 접수 챗봇 ─────────────────────────────────────────────────
|
||
app.include_router(chatbot.router)
|
||
|
||
# ── B-4: KB 자동 업데이트 에이전트 ───────────────────────────────────────────
|
||
app.include_router(kb_agent.router)
|
||
|
||
# ── B-5: 멀티 에이전트 협업 오케스트레이션 ────────────────────────────────────
|
||
app.include_router(orchestrator.router)
|
||
|
||
# ── B-6: 예측 유지보수 ────────────────────────────────────────────────────────
|
||
app.include_router(predictive.router)
|
||
|
||
# ── C-2: 변경 관리 CAB ───────────────────────────────────────────────────────
|
||
app.include_router(change.router)
|
||
|
||
# ── C-3: Problem Management ─────────────────────────────────────────────────
|
||
app.include_router(problem.router)
|
||
|
||
# ── C-4: 용량 관리 대시보드 ──────────────────────────────────────────────────
|
||
app.include_router(capacity.router)
|
||
|
||
# ── C-5: 서비스 카탈로그 ──────────────────────────────────────────────────────
|
||
app.include_router(catalog.router)
|
||
|
||
# ── D-1: LDAP/AD 연동 ────────────────────────────────────────────────────────
|
||
app.include_router(ldap.router)
|
||
|
||
# ── D-3: 특권 접근 관리 (PAM) ─────────────────────────────────────────────────
|
||
app.include_router(pam.router)
|
||
|
||
# ── D-4: 보안 취약점 자동 스캔 ───────────────────────────────────────────────
|
||
app.include_router(vuln_scan.router)
|
||
|
||
# ── E-1: 월별 리포트 자동 생성 ───────────────────────────────────────────────
|
||
app.include_router(report.router)
|
||
|
||
# ── E-4: Grafana 연동 (Prometheus 메트릭) ─────────────────────────────────
|
||
app.include_router(metrics.router)
|
||
|
||
# ── E-5: FinOps 비용 분석 ────────────────────────────────────────────────
|
||
app.include_router(finops.router)
|
||
|
||
# ── F-1: 멀티테넌트 데이터 격리 ──────────────────────────────────────────
|
||
from middleware.tenant import TenantMiddleware
|
||
app.add_middleware(TenantMiddleware)
|
||
app.include_router(tenant_mgmt.router)
|
||
|
||
# ── F-5: OpenAPI 외부 연동 게이트웨이 ────────────────────────────────────
|
||
app.include_router(gateway.router)
|
||
|
||
# ── Self-Improving Learning Loop ──────────────────────────────────────────
|
||
app.include_router(learning.router)
|
||
|
||
# ── 라이선스 관리 ──────────────────────────────────────────────────────────
|
||
app.include_router(license_router.router)
|
||
|
||
# ── G-10: PWA Push 알림 ──────────────────────────────────────────────────
|
||
app.include_router(push_router.router)
|
||
|
||
# Scouter APM
|
||
app.include_router(scouter_router.router)
|
||
|
||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||
|
||
|
||
@app.get("/")
|
||
async def index():
|
||
return FileResponse("static/index.html")
|
||
|
||
|
||
@app.get("/customer")
|
||
async def customer():
|
||
return FileResponse("static/customer.html")
|
||
|
||
|
||
@app.get("/login")
|
||
async def login_page():
|
||
return FileResponse("static/login.html")
|
||
|
||
|
||
@app.get("/change-password")
|
||
async def change_password_page():
|
||
return FileResponse("static/change-password.html")
|
||
|
||
|
||
@app.get("/agents")
|
||
async def agents_page():
|
||
return FileResponse("static/agents.html")
|
||
|
||
|
||
@app.get("/incidents")
|
||
async def incidents_page():
|
||
return FileResponse("static/incidents.html")
|
||
|
||
|
||
@app.get("/ssl")
|
||
async def ssl_page():
|
||
return FileResponse("static/ssl.html")
|
||
|
||
|
||
@app.get("/pm")
|
||
async def pm_page():
|
||
return FileResponse("static/pm.html")
|
||
|
||
|
||
@app.get("/oncall")
|
||
async def oncall_page():
|
||
return FileResponse("static/oncall.html")
|
||
|
||
|
||
@app.get("/batch")
|
||
async def batch_page():
|
||
return FileResponse("static/batch.html")
|
||
|
||
|
||
@app.get("/vibe")
|
||
async def vibe_page():
|
||
return FileResponse("static/vibe.html")
|
||
|
||
|
||
@app.get("/si")
|
||
async def si_page():
|
||
return FileResponse("static/si.html")
|
||
|
||
|
||
@app.get("/license")
|
||
async def license_page():
|
||
return FileResponse("static/license.html")
|