跳转至

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"

  ## Specify the value used as the "server" tag.
  # server = "db01"

  ## 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
server
(tag)
The address of the server. The value is host:port
active_connections Number of active connections to the database.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
idle_connections Number of idle connections in the database.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
max_connections Maximum number of connections allowed.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version

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
server
(tag)
The address of the server. The value is host:port
commits Number of transactions committed.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
rollbacks Number of transactions rolled back.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version

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
query
(tag)
SQL query text
queryid
(tag)
Unique identifier of the query
server
(tag)
The address of the server. The value is host:port
mean_exec_time Mean query execution time in milliseconds.
Type: float | (gauge)
Unit: time,ms
Tagged by: query, queryid

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
server
(tag)
The address of the server. The value is host:port
waiting_locks Number of waiting locks in the database.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version

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
server
(tag)
The address of the server. The value is host:port
calls Number of times the query was executed.
Type: int | (gauge)
Unit: count
Tagged by: queryid
rows Number of rows returned by the query.
Type: int | (gauge)
Unit: count
Tagged by: queryid
shared_blks_hit Number of shared buffer blocks hit.
Type: int | (gauge)
Unit: count
Tagged by: queryid
shared_blks_read Number of shared buffer blocks read.
Type: int | (gauge)
Unit: count
Tagged by: queryid
total_time Total execution time of the query in milliseconds.
Type: float | (gauge)
Unit: time,ms
Tagged by: queryid

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
server
(tag)
The address of the server. The value is host:port
buffer_hit_ratio Buffer cache hit ratio as a percentage.
Type: float | (gauge)
Unit: percent,percent
Tagged by: database, db_version
shared_blks_hit Number of shared buffer blocks hit.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
shared_blks_read Number of shared buffer blocks read.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version

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
server
(tag)
The address of the server. The value is host:port
blks_hit Blocks hit
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
blks_read Blocks read
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
conflicts The number of conflicts occurred.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
numbackends Number of backends
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
tup_deleted Tuples deleted
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
tup_inserted Tuples inserted
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
tup_updated Tuples updated
Type: int | (gauge)
Unit: count
Tagged by: database, db_version

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
server
(tag)
The address of the server. The value is host:port
spcname
(tag)
Tablespace name
size_bytes Tablespace size in bytes
Type: int | (gauge)
Unit: digital,B
Tagged by: spcname

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)
server
(tag)
The address of the server. The value is host:port
lock_count Number of locks of a specific type.
Type: int | (gauge)
Unit: count
Tagged by: lock_type

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
server
(tag)
The address of the server. The value is host:port
idx_scan Number of index scans.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
index_hit_ratio Index hit ratio as a percentage.
Type: float | (gauge)
Unit: percent,percent
Tagged by: database, db_version
seq_scan Number of sequential scans.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version

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
server
(tag)
The address of the server. The value is host:port
buffers_backend Number of buffers written by backends.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
buffers_clean Number of buffers written by the background writer.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
checkpoints_req Number of requested checkpoints.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
checkpoints_timed Number of timed checkpoints.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version

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
server
(tag)
The address of the server. The value is host:port
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
Tagged by: state, wait_event

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
server
(tag)
The address of the server. The value is host:port
deadlocks Number of deadlocks detected in the database.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version
temp_files Number of temporary files created by queries.
Type: int | (gauge)
Unit: count
Tagged by: database, db_version

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
server
(tag)
The address of the server. The value is host:port
calls Number of times the function has been called.
Type: int | (gauge)
Unit: count
Tagged by: funcname, schemaname
self_time Time spent in the function itself, excluding sub-functions (milliseconds).
Type: float | (gauge)
Unit: time,ms
Tagged by: funcname, schemaname
total_time Total time spent in the function, including sub-functions (milliseconds).
Type: float | (gauge)
Unit: time,ms
Tagged by: funcname, schemaname

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
server
(tag)
The address of the server. The value is host:port
calls Number of times the query has been executed.
Type: int | (gauge)
Unit: count
Tagged by: query, queryid
mean_exec_time Average execution time per query call (milliseconds).
Type: float | (gauge)
Unit: time,ms
Tagged by: query, queryid
total_exec_time Total execution time of the query (milliseconds).
Type: float | (gauge)
Unit: time,ms
Tagged by: query, queryid

自定义对象

日志

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

logging_collector = on
log_directory = 'sys_log'
  • Kingbase 采集器默认是未开启日志采集功能,可在 conf.d/samples/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 日志产生时间

文档评价

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