配置訪問日誌
Milvus 的存取日誌功能允許伺服器管理員記錄和分析使用者的存取行為,協助瞭解查詢成功率和失敗原因等方面。
本指南提供在 Milvus 中配置訪問日誌的詳細說明。
存取日誌的設定取決於 Milvus 的安裝方式:
- Helm 安裝:配置在
values.yaml
。如需詳細資訊,請參閱使用 Helm Charts 配置 Milvus。 - Docker 安裝:配置在
milvus.yaml
。如需詳細資訊,請參閱使用 Docker Compose 配置 Milvus。 - 操作員安裝:在設定檔中修改
spec.components
。如需詳細資訊,請參閱使用 Milvus Operator 配置 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 參數時,請確認已設定maxSize
或rotatedTime
。否則可能會導致無法成功上傳本機存取記錄檔到 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_code | Milvus 特有的錯誤代碼 |
$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 版本 |