Kingbase
Kingbase 采集器可以从 Kingbase 实例中采集实例运行状态指标。
配置¶
前置条件¶
- 创建监控帐号
-- 创建监控用户
CREATE USER datakit with password 'datakit';
-- 授权(兼容不同版本)
DO $$
BEGIN
BEGIN
GRANT sys_monitor TO datakit;
RAISE NOTICE 'granted sys_monitor';
EXCEPTION WHEN undefined_object THEN
GRANT pg_monitor TO datakit;
RAISE NOTICE 'granted pg_monitor';
END;
END $$;
- 开启 sys_stat_statements 扩展日志记录
编辑 data 目录下的 kingbase.conf 配置文件,修改 sys_stat_statements.track 的值为 top,如果没有找到该配置项,在最后一行添加即可。
# 跟踪统计 SQL 语句访问,推荐 top,默认 none
# 旧版参数(V8R5 或早期 V8R6)
# pg_stat_statements.track = 'top'
# 新版参数
sys_stat_statements.track = 'top'
采集器配置¶
进入 DataKit 安装目录下的 conf.d/samples 目录,复制 kingbase.conf.sample 并命名为 kingbase.conf。示例如下:
[[inputs.kingbase]]
# host name
host = "localhost"
## port
port = 54321
## user name
user = "datakit"
## password
password = "datakit"
## database name
database = "test"
## Slow query threshold in milliseconds, default 1000
slow_query_threshold = 1000
## @param connect_timeout - number - optional - default: 10s
# connect_timeout = "10s"
interval = "10s"
## Set true to enable election
election = true
## Metric name in metric_exclude_list will not be collected.
#
metric_exclude_list = [""]
## Run a custom SQL query and collect corresponding metrics.
#
# [[inputs.kingbase.custom_queries]]
# sql = "SELECT datname AS db, numbackends AS backends FROM sys_catalog.sys_stat_database"
# metric = "kingbase_custom_query"
# tags = ["db"]
# fields = ["backends"]
# interval = "30s"
## Log collection
#
[inputs.kingbase.log]
# files = []
# pipeline = "kingbase.p"
## The pattern should be a regexp. Note the use of '''this regexp'''
## regexp link: https://golang.org/pkg/regexp/syntax/#hdr-Syntax
multiline_match = '''^\\d{4}-\\d{2}-\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}\\s+\\[.*?\\]'''
[inputs.kingbase.tags]
# some_tag = "some_value"
# more_tag = "some_other_value"
配置好后,重启 DataKit 即可。
目前可以通过 ConfigMap 方式注入采集器配置来开启采集器。
指标¶
以下所有数据采集,默认会追加全局选举 tag,也可以在配置中通过 [inputs.kingbase.tags] 指定其它标签:
kingbase_connections¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| active_connections | Number of active connections to the database. Type: int | (gauge) Unit: count |
| idle_connections | Number of idle connections in the database. Type: int | (gauge) Unit: count |
| max_connections | Maximum number of connections allowed. Type: int | (gauge) Unit: count |
kingbase_transactions¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| commits | Number of transactions committed. Type: int | (gauge) Unit: count |
| rollbacks | Number of transactions rolled back. Type: int | (gauge) Unit: count |
kingbase_query_performance¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| mean_exec_time | Mean query execution time Type: float | (gauge) Unit: time,ms |
kingbase_locks¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| waiting_locks | Number of waiting locks in the database. Type: int | (gauge) Unit: count |
kingbase_query_stats¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| queryid ( tag) |
Unique identifier of the query |
| calls | Number of times the query was executed. Type: int | (gauge) Unit: count |
| rows | Number of rows returned by the query. Type: int | (gauge) Unit: count |
| shared_blks_hit | Number of shared buffer blocks hit. Type: int | (gauge) Unit: count |
| shared_blks_read | Number of shared buffer blocks read. Type: int | (gauge) Unit: count |
| total_time | Total execution time of the query in milliseconds. Type: float | (gauge) Unit: time,ms |
kingbase_buffer_cache¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| buffer_hit_ratio | Buffer cache hit ratio as a percentage. Type: float | (gauge) Unit: percent,percent |
| shared_blks_hit | Number of shared buffer blocks hit. Type: int | (gauge) Unit: count |
| shared_blks_read | Number of shared buffer blocks read. Type: int | (gauge) Unit: count |
kingbase_database_status¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| blks_hit | Blocks hit Type: int | (gauge) Unit: count |
| blks_read | Blocks read Type: int | (gauge) Unit: count |
| conflicts | The number of conflicts occurred. Type: int | (gauge) Unit: count |
| numbackends | Number of backends Type: int | (gauge) Unit: count |
| tup_deleted | Tuples deleted Type: int | (gauge) Unit: count |
| tup_inserted | Tuples inserted Type: int | (gauge) Unit: count |
| tup_updated | Tuples updated Type: int | (gauge) Unit: count |
kingbase_tablespace¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| spcname ( tag) |
Tablespace name |
| size_bytes | Tablespace size in bytes Type: int | (gauge) Unit: digital,B |
kingbase_lock_details¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| lock_type ( tag) |
Type of the lock (e.g., relation, tuple) |
| lock_count | Number of locks of a specific type. Type: int | (gauge) Unit: count |
kingbase_index_usage¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| idx_scan | Number of index scans. Type: int | (gauge) Unit: count |
| index_hit_ratio | Index hit ratio as a percentage. Type: float | (gauge) Unit: percent,percent |
| seq_scan | Number of sequential scans. Type: int | (gauge) Unit: count |
kingbase_bgwriter¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| buffers_backend | Number of buffers written by backends. Type: int | (gauge) Unit: count |
| buffers_clean | Number of buffers written by the background writer. Type: int | (gauge) Unit: count |
| checkpoints_req | Number of requested checkpoints. Type: int | (gauge) Unit: count |
| checkpoints_timed | Number of timed checkpoints. Type: int | (gauge) Unit: count |
kingbase_session_activity¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| state ( tag) |
Session state (e.g., active, idle) |
| wait_event ( tag) |
Wait event (e.g., LWLock, IO) |
| session_count | Number of sessions in a specific state or wait event. Type: int | (gauge) Unit: count |
kingbase_query_cancellation¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| deadlocks | Number of deadlocks detected in the database. Type: int | (gauge) Unit: count |
| temp_files | Number of temporary files created by queries. Type: int | (gauge) Unit: count |
kingbase_function_stats¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| funcname ( tag) |
The name of the function |
| host ( tag) |
The server address or the host name |
| schemaname ( tag) |
The schema name of the function |
| calls | Number of times the function has been called. Type: int | (gauge) Unit: count |
| self_time | Time spent in the function itself, excluding sub-functions (milliseconds). Type: float | (gauge) Unit: time,ms |
| total_time | Total time spent in the function, including sub-functions (milliseconds). Type: float | (gauge) Unit: time,ms |
kingbase_slow_query¶
| Tags & Fields | Description |
|---|---|
| database ( tag) |
The name of the database |
| db_version ( tag) |
The version of the database |
| host ( tag) |
The server address or the host name |
| query ( tag) |
Truncated SQL query text |
| queryid ( tag) |
Unique identifier of the query |
| calls | Number of times the query has been executed. Type: int | (gauge) Unit: count |
| mean_exec_time | Average execution time per query call (milliseconds). Type: float | (gauge) Unit: time,ms |
| total_exec_time | Total execution time of the query (milliseconds). Type: float | (gauge) Unit: time,ms |
自定义对象¶
日志¶
- 如需开启 Kingbase 的运行日志,可在 data 目录下的 Kingbase 配置文件
kingbase.conf, 进行如下配置:
- Kingbase 采集器默认是未开启日志采集功能,可在 conf.d/samples/kingbase.conf 中 将
files打开,并写入 Kingbase 日志文件的绝对路径。比如:
开启日志采集后,默认会产生日志来源(source)为 kingbase 的日志。
注意:日志采集仅支持已安装 DataKit 主机上的日志。
日志 Pipeline 切割¶
原始日志为
2025-06-17 13:07:10.952 UTC [999] ERROR: relation "sys_stat_activity" does not exist at character 240
切割后的字段说明:
| 字段名 | 字段值 | 说明 |
|---|---|---|
msg |
relation "sys_stat_activity" does not exist at character 240 |
日志内容 |
db_name |
test |
访问的数据库 |
process_id |
999 |
当前连接的客户端进程 ID |
status |
ERROR |
当前日志的级别(LOG,ERROR,FATAL,PANIC,WARNING,NOTICE,INFO) |
time |
1750136961776000000 |
日志产生时间 |