Skip to content

Kingbase

·


Kingbase collector can collect the running status index from Kingbase instance.

Configuration

Preconditions

  • Create user
-- Create monitor user
CREATE USER datakit with password 'datakit';
-- Grant (compatible with different versions)
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 $$;
  • Enable sys_stat_statements extended logging

Edit the kingbase.conf configuration file and change the value of sys_stat_statements.track to top. If this configuration item is not found, add it at the end of the file.

# Track statistics of SQL statement access, recommended 'top', default is 'none'
# Old parameter (V8R5 or early V8R6)
# pg_stat_statements.track = 'top'

# New parameter
sys_stat_statements.track = 'top'

Collector Configuration

Go to the conf.d/samples directory under the DataKit installation directory, copy kingbase.conf.sample and name it kingbase.conf. Examples are as follows:

[[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"

After configuration, restart DataKit.

The collector can now be turned on by ConfigMap Injection Collector Configuration.

Metric

For all of the following data collections, the global election tags will added automatically, we can add extra tags in [inputs.kingbase.tags] if needed:

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

Custom Object

Log Collection

  • To enable Kingbase runtime logging, configure the Kingbase configuration file kingbase.conf in the data directory as follows:
log_destination = 'stderr'

logging_collector = on
log_directory = 'sys_log'
  • The Kingbase collector does not have log collection enabled by default. You can open files in conf.d/db/kingbase.conf and write to the absolute path of the Kingbase log file. For example:
[[inputs.kingbase]]

  ...

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

When log collection is turned on, a log with a log source of kingbase is generated by default.

Notices:

  • Log collection only supports logs on hosts where DataKit is installed.

Log Pipeline Cut

The original log is

2025-06-17 13:07:10.952 UTC [999] ERROR:  relation "sys_stat_activity" does not exist at character 240

Description of the cut field:

Field name Field Value Description
msg relation "sys_stat_activity" does not exist at character 240 Log content
db_name test Database accessed
process_id 999 The client process ID of the current connection
status ERROR Current log level (LOG,ERROR,FATAL,PANIC,WARNING,NOTICE,INFO)
time 1750136961776000000 Log generation time

Feedback

Is this page helpful? ×