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"
);