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"
## 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"
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 |
| 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 |
Custom Object¶
Log Collection¶
- To enable Kingbase runtime logging, configure the Kingbase configuration file
kingbase.confin the data directory as follows:
- The Kingbase collector does not have log collection enabled by default. You can open
filesinconf.d/db/kingbase.confand write to the absolute path of the Kingbase log file. For example:
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 |