저는 최근 50개 이상의 AI API 연동 프로젝트를 수행하면서 로그 분석의 중요성을 절실히 깨달았습니다.深夜, ConnectionError: timeout 오류로 서비스 장애가 발생했을 때, 로그 없이는 원인을 파악할 수 없었습니다.이번 포스트에서는 HolySheep AI의 API 로그를 ELK Stack(Elasticsearch, Logstash, Kibana)와 통합하여 실시간 모니터링 체계를 구축하는 방법을 설명드리겠습니다.

왜 ELK Stack인가?

AI API Gateway를 운영할 때 다음 질문에 즉각 답할 수 있어야 합니다:

ELK Stack은 이러한 질문에 시각화된 대시보드로 즉각 답할 수 있게 해줍니다. HolySheep AI의 중앙 집중식 로깅을 ELK와 연동하면 모든 모델의 API 호출을 하나의 화면에서 추적할 수 있습니다.

아키텍처 개요

┌─────────────────────────────────────────────────────────────────┐
│                    HolySheep AI API Gateway                     │
│                  https://api.holysheep.ai/v1                    │
└─────────────────────────────┬───────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                      Application Server                         │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────────┐  │
│  │ Python SDK  │  │  Node SDK   │  │  원본 API (curl/python) │  │
│  └──────┬──────┘  └──────┬──────┘  └───────────┬─────────────┘  │
│         │                │                      │                │
│         └────────────────┴──────────────────────┘                │
│                            │                                     │
│                            ▼                                     │
│  ┌─────────────────────────────────────────────────────────────┐ │
│  │              Structured JSON Logging                        │ │
│  │  {timestamp, model, tokens, latency, status, cost}          │ │
│  └──────────────────────────┬──────────────────────────────────┘ │
└─────────────────────────────┼─────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                        Filebeat / Fluentd                       │
│                   (Log Collection Agent)                        │
└─────────────────────────────┬───────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                          Logstash                               │
│              (Parse, Filter, Transform)                         │
│  ┌────────────┐  ┌────────────┐  ┌─────────────────────────┐   │
│  │  Grok      │  │  GeoIP     │  │  Cost Calculation      │   │
│  │  Filter    │  │  Enrich    │  │  Plugin                 │   │
│  └────────────┘  └────────────┘  └─────────────────────────┘   │
└─────────────────────────────┬───────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                       Elasticsearch                              │
│              (Storage & Search Engine)                          │
│  Index: holy-sheep-logs-YYYY.MM.DD                              │
└─────────────────────────────┬───────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                          Kibana                                  │
│              (Visualization & Dashboard)                        │
│  ┌────────────┐  ┌────────────┐  ┌─────────────────────────┐   │
│  │ Real-time  │  │  Cost      │  │  Performance            │   │
│  │ Monitoring │  │  Dashboard │  │  Analysis               │   │
│  └────────────┘  └────────────┘  └─────────────────────────┘   │
└─────────────────────────────────────────────────────────────────┘

사전 준비

1. HolySheep AI 계정 생성

지금 HolySheep AI에 가입하고 API 키를 발급받습니다. 가입 시 무료 크레딧이 제공되므로 실제 비용 부담 없이 테스트할 수 있습니다.

2. 필요한 도구 설치

# Ubuntu/Debian 환경
sudo apt-get update
sudo apt-get install -y apt-transport-https

Java (Logstash 실행에 필요)

sudo apt-get install -y openjdk-11-jdk

Elasticsearch 8.x

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - echo "deb https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch/elasticsearch-8.11.0-amd64.deb" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list sudo apt-get update && sudo apt-get install -y elasticsearch

Logstash 8.x

echo "deb https://artifacts.elastic.co/downloads/logstash/logstash-8.11.0.deb" | sudo tee /etc/apt/sources.list.d/logstash.list sudo apt-get update && sudo apt-get install -y logstash

Kibana 8.x

echo "deb https://artifacts.elastic.co/downloads/kibana/kibana-8.11.0-amd64.deb" | sudo tee /etc/apt/sources.list.d/kibana.list sudo apt-get update && sudo apt-get install -y kibana

Filebeat

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.11.0-amd64.deb sudo dpkg -i filebeat-8.11.0-amd64.deb

Docker를 사용한 빠른 시작 (권장)

docker pull elasticsearch:8.11.0 docker pull kibana:8.11.0 docker pull logstash:8.11.0 docker pull elastic/filebeat:8.11.0

Python 애플리케이션에서 HolySheep API 로깅

먼저 HolySheep AI API를 호출하는 Python 애플리케이션에서 구조화된 JSON 로그를 생성합니다. 이 로그에는 모델명, 토큰 사용량, 지연 시간, 비용 정보가 포함됩니다.

# holy_sheep_logger.py
import json
import time
import logging
from datetime import datetime, timezone
from pathlib import Path
from typing import Optional, Dict, Any

try:
    import httpx
except ImportError:
    print("httpx 설치 필요: pip install httpx")
    raise

HolySheep AI 설정

HOLYSHEEP_API_KEY = "YOUR_HOLYSHEEP_API_KEY" HOLYSHEEP_BASE_URL = "https://api.holysheep.ai/v1"

로깅 설정

LOG_DIR = Path("./logs") LOG_DIR.mkdir(exist_ok=True)

JSON 파일 핸들러 생성

class JSONFileHandler(logging.Handler): def __init__(self, filename: str): super().__init__() self.filename = LOG_DIR / filename self.file = open(self.filename, 'a', encoding='utf-8') def emit(self, record: logging.LogRecord) -> None: log_entry = self.format(record) if log_entry: self.file.write(log_entry + '\n') self.file.flush() def close(self) -> None: self.file.close() super().close() class HolySheepAPIClient: """HolySheep AI API 클라이언트 with 구조화된 로깅""" # 모델별 가격 ($/1M tokens) - HolySheep AI 공시 가격 MODEL_PRICING = { "gpt-4.1": {"input": 8.00, "output": 32.00}, "gpt-4o": {"input": 2.50, "output": 10.00}, "gpt-4o-mini": {"input": 0.15, "output": 0.60}, "claude-sonnet-4-5": {"input": 3.00, "output": 15.00}, "claude-opus-4": {"input": 15.00, "output": 75.00}, "claude-haiku-3": {"input": 0.80, "output": 4.00}, "gemini-2.5-flash": {"input": 2.50, "output": 10.00}, "gemini-2.5-pro": {"input": 1.25, "output": 5.00}, "deepseek-v3.2": {"input": 0.42, "output": 1.66}, } def __init__(self, api_key: str = HOLYSHEEP_API_KEY): self.api_key = api_key self.base_url = HOLYSHEEP_BASE_URL self.logger = self._setup_logger() def _setup_logger(self) -> logging.Logger: logger = logging.getLogger("holy_sheep_api") logger.setLevel(logging.INFO) # 구조화된 JSON 로그 포맷터 class JSONFormatter(logging.Formatter): def format(self, record: logging.LogRecord) -> str: log_data = { "@timestamp": datetime.now(timezone.utc).isoformat(), "level": record.levelname, "logger": record.name, "message": record.getMessage(), "service": "holy-sheep-api", "environment": "production", } # 추가 필드가 있으면 포함 if hasattr(record, "model"): log_data["model"] = record.model if hasattr(record, "tokens_used"): log_data["tokens_used"] = record.tokens_used if hasattr(record, "latency_ms"): log_data["latency_ms"] = record.latency_ms if hasattr(record, "cost_usd"): log_data["cost_usd"] = record.cost_usd if hasattr(record, "status_code"): log_data["status_code"] = record.status_code if hasattr(record, "error"): log_data["error"] = record.error if hasattr(record, "request_id"): log_data["request_id"] = record.request_id return json.dumps(log_data, ensure_ascii=False) # 파일 핸들러 json_handler = JSONFileHandler(f"api_calls_{datetime.now().strftime('%Y%m%d')}.json") json_handler.setFormatter(JSONFormatter()) logger.addHandler(json_handler) # 콘솔 핸들러 (실시간 모니터링용) console_handler = logging.StreamHandler() console_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')) logger.addHandler(console_handler) return logger def _calculate_cost(self, model: str, input_tokens: int, output_tokens: int) -> float: """토큰 사용량 기반 비용 계산 (USD)""" pricing = self.MODEL_PRICING.get(model, {"input": 0, "output": 0}) input_cost = (input_tokens / 1_000_000) * pricing["input"] output_cost = (output_tokens / 1_000_000) * pricing["output"] return round(input_cost + output_cost, 6) async def chat_completion( self, model: str, messages: list, temperature: float = 0.7, max_tokens: int = 2048 ) -> Dict[str, Any]: """HolySheep AI Chat Completion API 호출 with 상세 로깅""" request_id = f"req_{int(time.time() * 1000)}" start_time = time.perf_counter() headers = { "Authorization": f"Bearer {self.api_key}", "Content-Type": "application/json" } payload = { "model": model, "messages": messages, "temperature": temperature, "max_tokens": max_tokens } self.logger.info( f"API Request initiated", extra={ "request_id": request_id, "model": model, } ) try: async with httpx.AsyncClient(timeout=60.0) as client: response = await client.post( f"{self.base_url}/chat/completions", headers=headers, json=payload ) end_time = time.perf_counter() latency_ms = round((end_time - start_time) * 1000, 2) if response.status_code == 200: data = response.json() usage = data.get("usage", {}) input_tokens = usage.get("prompt_tokens", 0) output_tokens = usage.get("completion_tokens", 0) total_tokens = usage.get("total_tokens", input_tokens + output_tokens) cost_usd = self._calculate_cost(model, input_tokens, output_tokens) self.logger.info( f"API Request successful", extra={ "request_id": request_id, "model": model, "tokens_used": total_tokens, "input_tokens": input_tokens, "output_tokens": output_tokens, "latency_ms": latency_ms, "cost_usd": cost_usd, "status_code": response.status_code, } ) return { "success": True, "data": data, "metadata": { "request_id": request_id, "latency_ms": latency_ms, "tokens": total_tokens, "cost_usd": cost_usd } } else: self.logger.error( f"API Request failed: {response.status_code}", extra={ "request_id": request_id, "model": model, "latency_ms": latency_ms, "status_code": response.status_code, "error": response.text[:500] } ) return { "success": False, "error": response.text, "status_code": response.status_code } except httpx.TimeoutException as e: end_time = time.perf_counter() latency_ms = round((end_time - start_time) * 1000, 2) self.logger.error( f"API Request timeout", extra={ "request_id": request_id, "model": model, "latency_ms": latency_ms, "status_code": 408, "error": f"TimeoutException: {str(e)}" } ) return { "success": False, "error": "Request timeout", "status_code": 408 } except httpx.ConnectError as e: self.logger.error( f"Connection Error", extra={ "request_id": request_id, "model": model, "status_code": 503, "error": f"ConnectError: {str(e)}" } ) return { "success": False, "error": f"Connection error: {str(e)}", "status_code": 503 }

사용 예제

if __name__ == "__main__": import asyncio async def main(): client = HolySheepAPIClient() # 여러 모델 동시 테스트 test_messages = [ {"role": "user", "content": "안녕하세요, HolySheep API 테스트입니다. 현재 시각을 알려주세요."} ] models_to_test = [ "gpt-4o-mini", "deepseek-v3.2", "claude-haiku-3" ] tasks = [ client.chat_completion(model=model, messages=test_messages) for model in models_to_test ] results = await asyncio.gather(*tasks) for model, result in zip(models_to_test, results): print(f"\n{model}: {'성공' if result['success'] else '실패'}") if result['success']: print(f" 토큰: {result['metadata']['tokens']}") print(f" 비용: ${result['metadata']['cost_usd']:.6f}") print(f" 지연: {result['metadata']['latency_ms']}ms") asyncio.run(main())

Logstash 파이프라인 설정

Logstash는 HolySheep API 로그를 파싱하고 Elasticsearch에 적재하는 핵심 역할을 합니다. 구조화된 로그에서 모델별 성능 지표, 비용, 에러 패턴을 추출합니다.

# /etc/logstash/conf.d/holy-sheep-api.conf
input {
  beats {
    port => 5044
    host => "0.0.0.0"
  }
  
  # 파일에서 직접 읽기 (Filebeat 미사용 시)
  file {
    path => "/var/log/holy-sheep/api_calls_*.json"
    start_position => "beginning"
    sincedb_path => "/var/lib/logstash/sincedb_holy_sheep"
    codec => json
    tags => ["holy-sheep", "api-logs"]
  }
}

filter {
  # HolySheep API 로그 파싱
  if "holy-sheep" in [tags] {
    
    # JSON 파싱 확인
    if ![parsed] {
      json {
        source => "message"
        target => "holysheep"
        skip_on_invalid_json => true
      }
    }
    
    # 타임스탬프 처리
    if [holysheep][@timestamp] {
      date {
        match => ["[holysheep][@timestamp]", "ISO8601"]
        target => "@timestamp"
        timezone => "UTC"
      }
    }
    
    # 모델별 가격 맵핑
    if [holysheep][model] {
      mutate {
        add_field => {
          "model_display_name" => "%{[holysheep][model]}"
        }
      }
      
      # 모델 가격 정보 추가
      if [holysheep][model] == "gpt-4.1" {
        mutate {
          add_field => {
            "price_per_million_input" => 8.00
            "price_per_million_output" => 32.00
            "provider" => "OpenAI via HolySheep"
          }
        }
      }
      else if [holysheep][model] == "deepseek-v3.2" {
        mutate {
          add_field => {
            "price_per_million_input" => 0.42
            "price_per_million_output" => 1.66
            "provider" => "DeepSeek via HolySheep"
          }
        }
      }
      else if [holysheep][model] == "claude-sonnet-4.5" {
        mutate {
          add_field => {
            "price_per_million_input" => 3.00
            "price_per_million_output" => 15.00
            "provider" => "Anthropic via HolySheep"
          }
        }
      }
      else if [holysheep][model] == "gemini-2.5-flash" {
        mutate {
          add_field => {
            "price_per_million_input" => 2.50
            "price_per_million_output" => 10.00
            "provider" => "Google via HolySheep"
          }
        }
      }
      else if [holysheep][model] == "gpt-4o-mini" {
        mutate {
          add_field => {
            "price_per_million_input" => 0.15
            "price_per_million_output" => 0.60
            "provider" => "OpenAI via HolySheep"
          }
        }
      }
      else if [holysheep][model] == "claude-haiku-3" {
        mutate {
          add_field => {
            "price_per_million_input" => 0.80
            "price_per_million_output" => 4.00
            "provider" => "Anthropic via HolySheep"
          }
        }
      }
    }
    
    # 지연 시간 분류
    if [holysheep][latency_ms] {
      if [holysheep][latency_ms] < 500 {
        mutate {
          add_field => { "latency_category" => "fast" }
          add_tag => ["low_latency"]
        }
      }
      else if [holysheep][latency_ms] < 2000 {
        mutate {
          add_field => { "latency_category" => "normal" }
        }
      }
      else if [holysheep][latency_ms] < 10000 {
        mutate {
          add_field => { "latency_category" => "slow" }
          add_tag => ["performance_warning"]
        }
      }
      else {
        mutate {
          add_field => { "latency_category" => "critical" }
          add_tag => ["performance_critical"]
        }
      }
    }
    
    # 비용 USD로 변환 (이미 계산된 값 사용)
    if [holysheep][cost_usd] {
      mutate {
        convert => { "[holysheep][cost_usd]" => "float" }
        add_field => { "cost_usd" => "%{[holysheep][cost_usd]}" }
      }
    }
    
    # HTTP 상태 코드 분류
    if [holysheep][status_code] {
      if [holysheep][status_code] >= 200 and [holysheep][status_code] < 300 {
        mutate {
          add_field => { "status_category" => "success" }
        }
      }
      else if [holysheep][status_code] >= 400 and [holysheep][status_code] < 500 {
        mutate {
          add_field => { "status_category" => "client_error" }
          add_tag => ["error", "client_error"]
        }
      }
      else if [holysheep][status_code] >= 500 {
        mutate {
          add_field => { "status_category" => "server_error" }
          add_tag => ["error", "server_error"]
        }
      }
      else if [holysheep][status_code] >= 300 and [holysheep][status_code] < 400 {
        mutate {
          add_field => { "status_category" => "redirect" }
        }
      }
    }
    
    # 에러 메시지 파싱
    if [holysheep][error] {
      mutate {
        add_tag => ["error"]
        
        # 일반적인 에러 패턴 감지
        if [holysheep][error] =~ /timeout/i {
          mutate {
            add_field => { "error_type" => "timeout" }
            add_tag => ["timeout_error"]
          }
        }
        else if [holysheep][error] =~ /401|unauthorized|authentication/i {
          mutate {
            add_field => { "error_type" => "auth" }
            add_tag => ["auth_error"]
          }
        }
        else if [holysheep][error] =~ /rate.?limit|429/i {
          mutate {
            add_field => { "error_type" => "rate_limit" }
            add_tag => ["rate_limit_error"]
          }
        }
        else if [holysheep][error] =~ /connection|connect/i {
          mutate {
            add_field => { "error_type" => "connection" }
            add_tag => ["connection_error"]
          }
        }
        else {
          mutate {
            add_field => { "error_type" => "unknown" }
          }
        }
      }
    }
    
    # 성공률 계산을 위한 플래그
    if "error" not in [tags] {
      mutate {
        add_field => { "request_status" => "success" }
      }
    }
    else {
      mutate {
        add_field => { "request_status" => "failed" }
      }
    }
    
    # 토큰 사용량 분류
    if [holysheep][tokens_used] {
      if [holysheep][tokens_used] < 500 {
        mutate {
          add_field => { "token_category" => "small" }
        }
      }
      else if [holysheep][tokens_used] < 2000 {
        mutate {
          add_field => { "token_category" => "medium" }
        }
      }
      else if [holysheep][tokens_used] < 8000 {
        mutate {
          add_field => { "token_category" => "large" }
        }
      }
      else {
        mutate {
          add_field => { "token_category" => "xlarge" }
        }
      }
    }
    
    # 메타데이터 보존
    mutate {
      add_field => {
        "index_type" => "holy_sheep_api_logs"
      }
    }
  }
}

output {
  # 콘솔 출력 (디버깅용)
  if "holy-sheep" in [tags] {
    stdout {
      codec => rubydebug
    }
  }
  
  # Elasticsearch 출력
  elasticsearch {
    hosts => ["https://localhost:9200"]
    index => "holy-sheep-logs-%{+YYYY.MM.dd}"
    user => "elastic"
    password => "${ELASTIC_PASSWORD}"
    ssl_certificate_verification => true
    ca_trusted_fingerprint => "${ELASTIC_CERT_FINGERPRINT}"
    
    # ILM (Index Lifecycle Management) 설정
    ilm_enabled => true
    ilm_rollover_alias => "holy-sheep-logs"
    ilm_pattern => "000001"
    ilm_policy => "holy-sheep-api-policy"
    
    # 템플릿 설정
    template_name => "holy-sheep-api"
    template_overwrite => true
  }
  
  # 에러 로그만 별도 인덱스로 분리
  if "error" in [tags] {
    elasticsearch {
      hosts => ["https://localhost:9200"]
      index => "holy-sheep-errors-%{+YYYY.MM.dd}"
      user => "elastic"
      password => "${ELASTIC_PASSWORD}"
    }
  }
}

Filebeat 설정

# /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/log/holy-sheep/api_calls_*.json
  json.keys_under_root: true
  json.add_error_key: true
  json.message_key: message
  fields:
    service: holy-sheep-api
    environment: production
  fields_under_root: true

Logstash 출력

output.logstash: hosts: ["localhost:5044"] ssl.enabled: false

로깅

logging.level: info logging.to_files: true logging.files: path: /var/log/filebeat name: filebeat keepfiles: 7 permissions: 0644

시작 옵션

filebeat.autostart: true

Kibana 대시보드 구성

ELK Stack 통합이 완료되면, Kibana에서 HolySheep API 모니터링 대시보드를 구성합니다. 다음 쿼리와 시각화를 생성합니다.

1. 성공/실패율 시각화

# Kibana Dev Tools에서 실행

전체 API 성공률

GET holy-sheep-logs-*/_search { "size": 0, "query": { "range": { "@timestamp": { "gte": "now-24h", "lte": "now" } } }, "aggs": { "total_requests": { "value_count": { "field": "request_id.keyword" } }, "success_requests": { "filter": { "bool": { "must": [ { "range": { "[holysheep][status_code]": { "gte": 200, "lt": 300 } } } ] } } }, "failed_requests": { "filter": { "bool": { "should": [ { "range": { "[holysheep][status_code]": { "gte": 400 } } }, { "exists": { "field": "error" } } ] } } } } }

2. 모델별 평균 지연 시간

# Kibana Dev Tools
GET holy-sheep-logs-*/_search
{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "@timestamp": {
              "gte": "now-24h",
              "lte": "now"
            }
          }
        }
      ],
      "must_not": [
        { "exists": { "field": "error" } }
      ]
    }
  },
  "aggs": {
    "by_model": {
      "terms": {
        "field": "[holysheep][model].keyword",
        "size": 20
      },
      "aggs": {
        "avg_latency": {
          "avg": {
            "field": "[holysheep][latency_ms]"
          }
        },
        "p50_latency": {
          "percentiles": {
            "field": "[holysheep][latency_ms]",
            "percents": [50, 95, 99]
          }
        },
        "total_tokens": {
          "sum": {
            "field": "[holysheep][tokens_used]"
          }
        },
        "total_cost": {
          "sum": {
            "field": "[holysheep][cost_usd]"
          }
        }
      }
    }
  }
}

3. 시간별 API 호출량 및 비용 추이

# Kibana Dev Tools
GET holy-sheep-logs-*/_search
{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "@timestamp": {
              "gte": "now-30d/d",
              "lte": "now"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "requests_over_time": {
      "date_histogram": {
        "field": "@timestamp",
        "calendar_interval": "1h"
      },
      "aggs": {
        "request_count": {
          "value_count": {
            "field": "request_id.keyword"
          }
        },
        "total_cost": {
          "sum": {
            "field": "[holysheep][cost_usd]"
          }
        },
        "avg_latency": {
          "avg": {
            "field": "[holysheep][latency_ms]"
          }
        }
      }
    }
  }
}

Docker Compose로 ELK Stack 빠른 시작

# docker-compose.yml
version: '3.8'

services:
  elasticsearch:
    image: elasticsearch:8.11.0
    container_name: elasticsearch
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=true
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
      - "ES_JAVA_OPTS=-Xms2g -Xmx2g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - elasticsearch_data:/usr/share/elasticsearch/data
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - elk
    healthcheck:
      test: ["CMD-SHELL", "curl -s https://localhost:9200 | grep -q 'cluster_name'"]
      interval: 30s
      timeout: 10s
      retries: 5

  logstash:
    image: logstash:8.11.0
    container_name: logstash
    volumes:
      - ./logstash/pipeline:/usr/share/logstash/pipeline:ro
      - ./logs:/var/log/holy-sheep:ro
    ports:
      - "5044:5044"
    environment:
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
      - "LS_JAVA_OPTS=-Xms1g -Xmx1g"
    networks:
      - elk
    depends_on:
      elasticsearch:
        condition: service_healthy

  kibana:
    image: kibana:8.11.0
    container_name: kibana
    ports:
      - "5601:5601"
    environment:
      - ELASTICSEARCH_HOSTS=https://elasticsearch:9200
      - ELASTICSEARCH_USERNAME=kibana_system
      - ELASTICSEARCH_PASSWORD=${ELASTIC_PASSWORD}
    networks:
      - elk
    depends_on:
      elasticsearch:
        condition: service_healthy

  filebeat:
    image: elastic/filebeat:8.11.0
    container_name: filebeat
    user: root
    volumes:
      - ./filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
      - ./logs:/var/log/holy-sheep:ro
      - /var/lib/docker/containers:/var/lib/docker/containers:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - elk
    depends_on:
      - logstash
      - elasticsearch

volumes:
  elasticsearch_data:
    driver: local

networks:
  elk:
    driver: bridge
# 시작 명령어

.env 파일 생성

cat > .env << 'EOF' ELASTIC_PASSWORD=your_secure_password_here ELASTIC_CERT_FINGERPRINT=your_cert_fingerprint_here HOLYSHEEP_API_KEY=YOUR_HOLYSHEEP_API_KEY EOF

ELK Stack 시작

docker-compose up -d

상태 확인

docker-compose ps

로그 확인

docker-compose logs -f

Kibana 접속 (초기 비밀번호 변경 필요)

echo "Kibana 접속: http://localhost:5601" echo "Elasticsearch: https://localhost:9200"

자주 발생하는 오류와 해결책

1. ConnectionError: Failed to connect to HolySheep API

# 오류 메시지

ConnectionError: [Errno 111] Connection refused

또는

httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

원인 분석

- 방화벽으로 인해 HolySheep API 접근 불가

- SSL 인증서 검증 실패

- 잘못된 base_url 사용

해결 방법 1: SSL 검증 비활성화 (개발 환경만)

import httpx async def test_connection(): # 개발 환경에서만 SSL 검증 비활성화 async with httpx.AsyncClient(verify=False) as client: response = await client.get( "https://api.holysheep.ai/v1/models", headers={"Authorization": f"Bearer YOUR_HOLYSHEEP_API_KEY"} ) print(response.json())

해결 방법 2: 프록시 설정

async def test_with_proxy(): proxies = { "http://": "http://proxy.example.com:8080", "https://": "http://proxy.example.com:8080" } async with httpx.AsyncClient(proxies=proxies) as client: response = await client.get( "https://api.holysheep.ai/v1/models", headers={"Authorization": f"Bearer YOUR_HOLYSHEEP_API_KEY"} ) print(response.json())

해결 방법 3: 올바른 base_url 확인

✓ 올바른 URL

BASE_URL = "https://api.holysheep.ai/v1" # 반드시 /v1 포함

✗ 잘못된 URL들

BASE_URL = "api.holysheep.ai" # https:// 및