StarRocks將所有審計日誌儲存在本地檔案fe/log/fe.audit.log
中,並且這些日誌無法通過系統內部資料庫訪問。審計日誌功能預設啟用,並將安裝AuditLoader外掛程式,該外掛程式能夠從本地檔案中讀取日誌,並通過HTTP PUT方法將其匯入StarRocks資料庫,方便您查看並分析資料庫中發生的所有操作。
注意事項
審計日誌功能預設開啟,並會自動建立資料庫 _starrocks_audit_db_ 及資料表starrocks_audit_tbl。後續所有的審計日誌將會儲存於該表中。請勿刪除 _starrocks_audit_db_ 資料庫及starrocks_audit_tbl資料表,刪除後將導致Manager中SQL任務查詢功能無法正常使用。
審計日誌使用了動態分區的方式,預設儲存30天的審計資料。您可以根據務需求調整審計資料的儲存時間,即修改
dynamic_partition.start
和dynamic_partition.end
的參數值。審計日誌功能不支援關閉。
功能介紹
在EMR StarRocks Manager頁面,單擊左側導覽列的中繼資料管理,在default_catalog下,您可以看到自動建立的資料庫_starrocks_audit_db_以及其下的資料表starrocks_audit_tbl,後續所有的審計日誌都會儲存於該表中。
starrocks_audit_tbl的建立語句可以通過SHOW CREATE TABLE starrocks_audit_tbl;
查看。具體的建立語句如下所示。
CREATE TABLE `starrocks_audit_tbl` (
`queryId` varchar(64) COMMENT "查詢的唯一ID",
`timestamp` datetime NOT NULL COMMENT "查詢開始時間",
`queryType` varchar(12) COMMENT "查詢類型(query, slow_query, connection)",
`clientIp` varchar(32) COMMENT "用戶端IP",
`user` varchar(64) COMMENT "查詢使用者名稱",
`authorizedUser` varchar(64) COMMENT "使用者唯一標識,既user_identity",
`resourceGroup` varchar(64) COMMENT "資源群組名",
`catalog` varchar(32) COMMENT "資料目錄名",
`db` varchar(96) COMMENT "查詢所在資料庫",
`state` varchar(8) COMMENT "查詢狀態(EOF,ERR,OK)",
`errorCode` varchar(512) COMMENT "錯誤碼",
`queryTime` bigint(20) COMMENT "查詢執行時間(毫秒)",
`scanBytes` bigint(20) COMMENT "查詢掃描的位元組數",
`scanRows` bigint(20) COMMENT "查詢掃描的記錄行數",
`returnRows` bigint(20) COMMENT "查詢返回的結果行數",
`cpuCostNs` bigint(20) COMMENT "查詢CPU耗時(納秒)",
`memCostBytes` bigint(20) COMMENT "查詢消耗記憶體(位元組)",
`stmtId` int(11) COMMENT "SQL語句增量ID",
`isQuery` tinyint(4) COMMENT "SQL是否為查詢(1或0)",
`feIp` varchar(128) COMMENT "執行該語句的FE IP",
`stmt` varchar(1048576) COMMENT "SQL原始語句",
`digest` varchar(32) COMMENT "慢SQL指紋",
`planCpuCosts` double COMMENT "查詢規劃階段CPU佔用(納秒)",
`planMemCosts` double COMMENT "查詢規劃階段記憶體佔用(位元組)",
`warehouse` varchar(96) COMMENT "查詢使用的計算群組",
`stmtType` varchar(8) COMMENT "SQL類型(DQL,DML,DDL,DCL,OTHER)",
`isFilter` tinyint(4) COMMENT "SQL是否過濾(1或0)"
) ENGINE=OLAP
DUPLICATE KEY(`queryId`, `timestamp`, `queryType`)
COMMENT "審計日誌表"
PARTITION BY RANGE(`timestamp`) (
PARTITION p20241023 VALUES LESS THAN ("2024-10-24 00:00:00"),
PARTITION p20241024 VALUES LESS THAN ("2024-10-25 00:00:00"),
PARTITION p20241025 VALUES LESS THAN ("2024-10-26 00:00:00"),
PARTITION p20241026 VALUES LESS THAN ("2024-10-27 00:00:00"),
PARTITION p20241027 VALUES LESS THAN ("2024-10-28 00:00:00"),
PARTITION p20241028 VALUES LESS THAN ("2024-10-29 00:00:00"),
PARTITION p20241029 VALUES LESS THAN ("2024-10-30 00:00:00"),
PARTITION p20241030 VALUES LESS THAN ("2024-10-31 00:00:00"),
PARTITION p20241031 VALUES LESS THAN ("2024-11-01 00:00:00")
)
DISTRIBUTED BY HASH(`queryId`) BUCKETS 3
PROPERTIES (
"replication_num" = "3",
"dynamic_partition.enable" = "true",
"dynamic_partition.time_unit" = "DAY",
"dynamic_partition.time_zone" = "Asia/Shanghai",
"dynamic_partition.start" = "-30",
"dynamic_partition.end" = "3",
"dynamic_partition.prefix" = "p",
"dynamic_partition.buckets" = "3",
"dynamic_partition.history_partition_num" = "0",
"in_memory" = "false",
"enable_persistent_index" = "false",
"replicated_storage" = "true",
"compression" = "LZ4"
);