🚀 免費嘗試 Zilliz Cloud,完全托管的 Milvus,體驗速度提升 10 倍!立即嘗試

milvus-logo
LFAI
主頁
  • 管理指南
    • 監控、警示與日誌
  • Home
  • Docs
  • 管理指南

  • 監控、警示與日誌

  • 日誌

  • 設定存取日誌

配置訪問日誌

Milvus 的存取日誌功能允許伺服器管理員記錄和分析使用者的存取行為,協助瞭解查詢成功率和失敗原因等方面。

本指南提供在 Milvus 中配置訪問日誌的詳細說明。

存取日誌的設定取決於 Milvus 的安裝方式:

組態選項

根據您的需求,從三個組態選項中選擇:

  • 基本配置:用於一般用途。
  • 本機存取記錄檔的組態:用於在本機儲存記錄。
  • 將本機存取記錄上傳至 MinIO 的組態:用於雲端儲存與備份。

基本設定

基本設定包括啟用存取日誌、定義日誌檔名或使用 stdout。

proxy:
  accessLog:
    enable: true
    # If `filename` is emtpy, logs will be printed to stdout.
    filename: ""
    # Additional formatter configurations...
  • proxy.accessLog.enable:是否啟用存取記錄功能。預設為false
  • proxy.accessLog.filename:存取日誌檔案名稱。如果將此參數留空,存取日誌會列印到 stdout。

配置本機存取日誌檔案

設定存取日誌檔案的本機儲存,參數包括本機檔案路徑、檔案大小和輪換時間間隔:

proxy:
  accessLog:
    enable: true
    filename: "access_log.txt" # Name of the access log file
    localPath: "/var/logs/milvus" # Local file path where the access log file is stored
    maxSize: 500 # Max size for each single access log file. Unit: MB
    rotatedTime: 24 # Time interval for log rotation. Unit: seconds
    maxBackups: 7 # Max number of sealed access log files that can be retained
    # Additional formatter configurations...

這些參數會在filename 不為空時指定。

  • proxy.accessLog.localPath:儲存存取記錄檔的本機檔案路徑。
  • proxy.accessLog.maxSize:單一存取記錄檔允許的最大大小 (MB)。如果日誌檔案大小達到此限制,就會啟動輪換程序。此程序會封鎖目前的存取記錄檔,建立新的記錄檔,並清除原始記錄檔的內容。
  • proxy.accessLog.rotatedTime:允許輪換單一存取記錄檔的最大時間間隔 (以秒為單位)。當達到指定的時間間隔,就會觸發輪換程序,建立新的存取記錄檔,並封存先前的存取記錄檔。
  • proxy.accessLog.maxBackups:可保留的最大封存存取記錄檔數量。如果封存的存取日誌檔案數量超過此限制,則會刪除最舊的檔案。

將本機存取記錄檔上傳至 MinIO 的設定

啟用並設定將本機存取記錄檔上傳至 MinIO 的設定:

proxy:
  accessLog:
    enable: true
    filename: "access_log.txt"
    localPath: "/var/logs/milvus"
    maxSize: 500
    rotatedTime: 24 
    maxBackups: 7
    minioEnable: true
    remotePath: "/milvus/logs/access_logs"
    remoteMaxTime: 0
    # Additional formatter configurations...

設定 MinIO 參數時,請確認已設定maxSizerotatedTime 。否則可能會導致無法成功上傳本機存取記錄檔到 MinIO。

  • proxy.accessLog.minioEnable:是否將本機存取記錄檔上傳至 MinIO。預設為false
  • proxy.accessLog.remotePath:上傳存取記錄檔的物件儲存路徑。
  • proxy.accessLog.remoteMaxTime:允許上傳存取記錄檔的時間間隔。如果日誌檔案的上傳時間超過此時間間隔,檔案會被刪除。將值設為 0 會停用此功能。

格式設定

所有方法使用的預設記錄格式是base 格式,不需要特定的方法關聯。但是,如果您希望自訂特定方法的日誌輸出,您可以定義自訂的日誌格式,並應用在關聯的方法上。

proxy:
  accessLog:
    enable: true
    filename: "access_log.txt"
    localPath: "/var/logs/milvus"
    # Define custom formatters for access logs with format and applicable methods
    formatters:
      # The `base` formatter applies to all methods by default
      # The `base` formatter does not require specific method association
      base: 
        # Format string; an empty string means no log output
        format: "[$time_now] [ACCESS] <$user_name: $user_addr> $method_name-$method_status-$error_code [traceID: $trace_id] [timeCost: $time_cost]"
      # Custom formatter for specific methods (e.g., Query, Search)
      query: 
        format: "[$time_now] [ACCESS] <$user_name: $user_addr> $method_status-$method_name [traceID: $trace_id] [timeCost: $time_cost] [database: $database_name] [collection: $collection_name] [partitions: $partition_name] [expr: $method_expr]"
        # Specify the methods to which this custom formatter applies
        methods: ["Query", "Search"]
  • proxy.accessLog.<formatter_name>.format:使用動態度量定義日誌格式。如需詳細資訊,請參閱支援的度量
  • proxy.accessLog.<formatter_name>.methods:列出使用此格式的 Milvus 操作。要取得方法名稱,請參閱Milvus 方法中的MilvusService

參考:支援的度量

公制名稱說明
$method_name方法名稱
$method_status存取狀態:確定失敗
$method_expr用於查詢、搜尋或刪除操作的表達式
$trace_id與存取相關聯的 TraceID
$user_addr使用者的 IP 位址
$user_name使用者名稱
$response_size回應資料的大小
$error_codeMilvus 特有的錯誤代碼
$error_msg詳細錯誤資訊
$database_name目標 Milvus 資料庫名稱
$collection_name目標 Milvus 收集的名稱
$partition_name目標 Milvus 磁碟分割的名稱
$time_cost完成存取所花的時間
$time_now列印存取記錄的時間 (通常相等於$time_end)
$time_start開始存取的時間
$time_end存取結束的時間
$sdk_version使用者使用的 Milvus SDK 版本

免費嘗試托管的 Milvus

Zilliz Cloud 無縫接入,由 Milvus 提供動力,速度提升 10 倍。

開始使用
反饋

這個頁面有幫助嗎?