跳转至

Kingbase

·


Kingbase 采集器可以从 Kingbase 实例中采集实例运行状态指标。

配置

前置条件

  • 创建监控帐号
-- 创建监控用户
CREATE USER datakit with password 'datakit';
-- 授权
GRANT sys_monitor TO datakit;
  • 开启 sys_stat_statements 扩展日志记录

编辑 data 目录下的 kingbase.conf 配置文件,修改 sys_stat_statements.track 的值为 top

# 跟踪统计 SQL 语句访问,推荐 top,默认 none
sys_stat_statements.track = 'top'

采集器配置

进入 DataKit 安装目录下的 conf.d/db 目录,复制 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

  • 标签
Tag Description
database The name of the database
host The server address or the host name
  • 指标列表
Metric Description
active_connections Number of active connections to the database.
Type: int
Unit: count
idle_connections Number of idle connections in the database.
Type: int
Unit: count
max_connections Maximum number of connections allowed.
Type: int
Unit: count

kingbase_transactions

  • 标签
Tag Description
database The name of the database
host The server address or the host name
  • 指标列表
Metric Description
commits Number of transactions committed.
Type: int
Unit: count
rollbacks Number of transactions rolled back.
Type: int
Unit: count

kingbase_query_performance

  • 标签
Tag Description
database The name of the database
host The server address or the host name
  • 指标列表
Metric Description
mean_exec_time Mean query execution time
Type: float
Unit: time,ms

kingbase_locks

  • 标签
Tag Description
database The name of the database
host The server address or the host name
  • 指标列表
Metric Description
waiting_locks Number of waiting locks in the database.
Type: int
Unit: count

kingbase_query_stats

  • 标签
Tag Description
database The name of the database
host The server address or the host name
queryid Unique identifier of the query
  • 指标列表
Metric Description
calls Number of times the query was executed.
Type: int
Unit: count
rows Number of rows returned by the query.
Type: int
Unit: count
shared_blks_hit Number of shared buffer blocks hit.
Type: int
Unit: count
shared_blks_read Number of shared buffer blocks read.
Type: int
Unit: count
total_time Total execution time of the query in milliseconds.
Type: float
Unit: time,ms

kingbase_buffer_cache

  • 标签
Tag Description
database The name of the database
host The server address or the host name
  • 指标列表
Metric Description
buffer_hit_ratio Buffer cache hit ratio as a percentage.
Type: float
Unit: percent,percent
shared_blks_hit Number of shared buffer blocks hit.
Type: int
Unit: count
shared_blks_read Number of shared buffer blocks read.
Type: int
Unit: count

kingbase_database_status

  • 标签
Tag Description
database The name of the database
host The server address or the host name
  • 指标列表
Metric Description
blks_hit Blocks hit
Type: int
Unit: count
blks_read Blocks read
Type: int
Unit: count
conflicts The number of conflicts occurred.
Type: int
Unit: count
numbackends Number of backends
Type: int
Unit: count
tup_deleted Tuples deleted
Type: int
Unit: count
tup_inserted Tuples inserted
Type: int
Unit: count
tup_updated Tuples updated
Type: int
Unit: count

kingbase_tablespace

  • 标签
Tag Description
database The name of the database
host The server address or the host name
spcname Tablespace name
  • 指标列表
Metric Description
size_bytes Tablespace size in bytes
Type: int
Unit: digital,B

kingbase_lock_details

  • 标签
Tag Description
database The name of the database
host The server address or the host name
lock_type Type of the lock (e.g., relation, tuple)
  • 指标列表
Metric Description
lock_count Number of locks of a specific type.
Type: int
Unit: count

kingbase_index_usage

  • 标签
Tag Description
database The name of the database
host The server address or the host name
  • 指标列表
Metric Description
idx_scan Number of index scans.
Type: int
Unit: count
index_hit_ratio Index hit ratio as a percentage.
Type: float
Unit: percent,percent
seq_scan Number of sequential scans.
Type: int
Unit: count

kingbase_bgwriter

  • 标签
Tag Description
database The name of the database
host The server address or the host name
  • 指标列表
Metric Description
buffers_backend Number of buffers written by backends.
Type: int
Unit: count
buffers_clean Number of buffers written by the background writer.
Type: int
Unit: count
checkpoints_req Number of requested checkpoints.
Type: int
Unit: count
checkpoints_timed Number of timed checkpoints.
Type: int
Unit: count

kingbase_session_activity

  • 标签
Tag Description
database The name of the database
host The server address or the host name
state Session state (e.g., active, idle)
wait_event Wait event (e.g., LWLock, IO)
  • 指标列表
Metric Description
session_count Number of sessions in a specific state or wait event.
Type: int
Unit: count

kingbase_query_cancellation

  • 标签
Tag Description
database The name of the database
host The server address or the host name
  • 指标列表
Metric Description
deadlocks Number of deadlocks detected in the database.
Type: int
Unit: count
temp_files Number of temporary files created by queries.
Type: int
Unit: count

kingbase_function_stats

  • 标签
Tag Description
database The name of the database
funcname The name of the function
host The server address or the host name
schemaname The schema name of the function
  • 指标列表
Metric Description
calls Number of times the function has been called.
Type: int
Unit: count
self_time Time spent in the function itself, excluding sub-functions (milliseconds).
Type: float
Unit: time,ms
total_time Total time spent in the function, including sub-functions (milliseconds).
Type: float
Unit: time,ms

kingbase_slow_query

  • 标签
Tag Description
database The name of the database
host The server address or the host name
query Truncated SQL query text
queryid Unique identifier of the query
  • 指标列表
Metric Description
calls Number of times the query has been executed.
Type: int
Unit: count
mean_exec_time Average execution time per query call (milliseconds).
Type: float
Unit: time,ms
total_exec_time Total execution time of the query (milliseconds).
Type: float
Unit: time,ms

自定义对象

日志

  • 如需开启 Kingbase 的运行日志,可在 data 目录下的 Kingbase 配置文件 kingbase.conf , 进行如下配置:
log_destination = 'stderr'

logging_collector = on
log_directory = 'sys_log'
  • Kingbase 采集器默认是未开启日志采集功能,可在 conf.d/db/kingbase.conf 中 将 files 打开,并写入 Kingbase 日志文件的绝对路径。比如:
[[inputs.kingbase]]

  ...

  [inputs.kingbases.log]
    files = ["/tmp/kingbase.log"]

开启日志采集后,默认会产生日志来源(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 日志产生时间

文档评价

文档内容是否对您有帮助? ×