Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql,mariadb support com_select, com_insert, com_committer ... metrics #4

Merged
merged 3 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ public void collect(CollectRep.MetricsData.Builder builder, long appId, String a
String databaseUrl = constructDatabaseUrl(jdbcProtocol);
// 查询超时时间默认6000毫秒
int timeout = CollectUtil.getTimeout(jdbcProtocol.getTimeout());
Statement statement = null;
try {
Statement statement = getConnection(jdbcProtocol.getUsername(),
statement = getConnection(jdbcProtocol.getUsername(),
jdbcProtocol.getPassword(), databaseUrl, timeout);
switch (jdbcProtocol.getQueryType()) {
case QUERY_TYPE_ONE_ROW:
Expand Down Expand Up @@ -110,6 +111,14 @@ public void collect(CollectRep.MetricsData.Builder builder, long appId, String a
log.error("Jdbc error: {}.", errorMessage, e);
builder.setCode(CollectRep.Code.FAIL);
builder.setMsg("Query Error: " + errorMessage);
} finally {
if (statement != null) {
try {
statement.close();
} catch (Exception e) {
log.error("Jdbc close statement error: {}", e.getMessage());
}
}
}
}

Expand Down
115 changes: 104 additions & 11 deletions manager/src/main/resources/define/app/app-mariadb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ metrics:
priority: 1
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: uptime
type: 0
unit: s
- field: com_select
type: 0
- field: com_insert
type: 0
- field: com_update
type: 0
- field: com_delete
type: 0
- field: com_commit
type: 0
- field: com_rollback
type: 0
- field: threads_created
type: 0
- field: threads_connected
Expand All @@ -97,34 +112,90 @@ metrics:
type: 0
- field: threads_running
type: 0
- field: qps
type: 0
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- uptime
- com_select
- com_insert
- com_update
- com_delete
- com_commit
- com_rollback
- threads_created
- threads_connected
- threads_cached
- threads_running
- questions
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
- threads_created=threads_created
- threads_connected=threads_connected
- threads_cached=threads_cached
- threads_running=threads_running
- qps=uptime / questions
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
platform: mariadb
platform: mysql
username: ^_^username^_^
password: ^_^password^_^
database: ^_^database^_^
timeout: ^_^timeout^_^
# SQL查询方式: oneRow, multiRow, columns
queryType: columns
# sql
sql: show global status where Variable_name like 'thread%' or Variable_name = 'com_commit' or Variable_name = 'com_rollback' or Variable_name = 'questions' or Variable_name = 'uptime';
sql: show global status where Variable_name like 'thread%' or Variable_name = 'com_select' or Variable_name = 'com_insert' or Variable_name = 'com_update' or Variable_name = 'com_delete' or Variable_name = 'com_commit' or Variable_name = 'com_rollback' or Variable_name = 'questions' or Variable_name = 'uptime';
url: ^_^url^_^

- name: cache
priority: 1
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: query_cache_hit_rate
type: 0
unit: '%'
- field: cache_hits
type: 0
- field: cache_inserts
type: 0
- field: cache_free_blocks
type: 0
- field: cache_free_memory
type: 0
unit: KB
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- Qcache_hits
- Qcache_inserts
- Qcache_free_blocks
- Qcache_free_memory
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
- query_cache_hit_rate= (Qcache_hits + 1) / (Qcache_hits + Qcache_inserts + 1) * 100
- cache_hits=Qcache_hits
- cache_inserts=Qcache_inserts
- cache_free_blocks=Qcache_free_blocks
- cache_free_memory=Qcache_free_memory
units:
- cache_free_memory=B->KB
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
platform: mysql
username: ^_^username^_^
password: ^_^password^_^
database: ^_^database^_^
timeout: ^_^timeout^_^
# SQL查询方式: oneRow, multiRow, columns
queryType: columns
# sql
sql: show global status like 'QCache%';
url: ^_^url^_^

- name: innodb
Expand All @@ -133,16 +204,38 @@ metrics:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: innodb_data_reads
type: 0
unit: 次数
unit: Times
- field: innodb_data_writes
type: 0
unit: 次数
unit: Times
- field: innodb_data_read
type: 0
unit: kb
unit: MB
- field: innodb_data_written
type: 0
unit: kb
unit: MB
- field: innodb_buffer_hit_rate
type: 0
unit: '%'
aliasFields:
- Innodb_data_reads
- Innodb_data_writes
- Innodb_data_read
- Innodb_data_written
- Innodb_buffer_pool_read_requests
- Innodb_buffer_pool_read_ahead
- Innodb_buffer_pool_reads
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
- innodb_buffer_hit_rate= (Innodb_buffer_pool_read_requests + 1) / (Innodb_buffer_pool_read_requests + Innodb_buffer_pool_read_ahead + Innodb_buffer_pool_reads + 1) * 100
- innodb_data_reads=Innodb_data_reads
- innodb_data_writes=Innodb_data_writes
- innodb_data_read=Innodb_data_read
- innodb_data_written=Innodb_data_written
units:
- innodb_data_read=KB->MB
- innodb_data_written=KB->MB
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
Expand All @@ -158,4 +251,4 @@ metrics:
queryType: columns
# sql
sql: show global status where Variable_name like 'innodb%';
url: ^_^url^_^
url: ^_^url^_^
121 changes: 107 additions & 14 deletions manager/src/main/resources/define/app/app-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ metrics:
type: 1
- field: max_connections
type: 0
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- version
- version_compile_os
- version_compile_machine
- port
- datadir
- max_connections
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
- port=port
- datadir=datadir
Expand All @@ -74,7 +74,7 @@ metrics:
host: ^_^host^_^
# 端口
port: ^_^port^_^
platform: mysql
platform: mariadb
username: ^_^username^_^
password: ^_^password^_^
database: ^_^database^_^
Expand All @@ -89,6 +89,21 @@ metrics:
priority: 1
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: uptime
type: 0
unit: s
- field: com_select
type: 0
- field: com_insert
type: 0
- field: com_update
type: 0
- field: com_delete
type: 0
- field: com_commit
type: 0
- field: com_rollback
type: 0
- field: threads_created
type: 0
- field: threads_connected
Expand All @@ -97,19 +112,26 @@ metrics:
type: 0
- field: threads_running
type: 0
- field: qps
type: 0
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- uptime
- com_select
- com_insert
- com_update
- com_delete
- com_commit
- com_rollback
- threads_created
- threads_connected
- threads_cached
- threads_running
- questions
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
- threads_created=threads_created
- threads_connected=threads_connected
- threads_cached=threads_cached
- threads_running=threads_running
- qps=uptime / questions
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
Expand All @@ -124,7 +146,56 @@ metrics:
# SQL查询方式: oneRow, multiRow, columns
queryType: columns
# sql
sql: show global status where Variable_name like 'thread%' or Variable_name = 'com_commit' or Variable_name = 'com_rollback' or Variable_name = 'questions' or Variable_name = 'uptime';
sql: show global status where Variable_name like 'thread%' or Variable_name = 'com_select' or Variable_name = 'com_insert' or Variable_name = 'com_update' or Variable_name = 'com_delete' or Variable_name = 'com_commit' or Variable_name = 'com_rollback' or Variable_name = 'questions' or Variable_name = 'uptime';
url: ^_^url^_^

- name: cache
priority: 1
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: query_cache_hit_rate
type: 0
unit: '%'
- field: cache_hits
type: 0
- field: cache_inserts
type: 0
- field: cache_free_blocks
type: 0
- field: cache_free_memory
type: 0
unit: KB
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- Qcache_hits
- Qcache_inserts
- Qcache_free_blocks
- Qcache_free_memory
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
- query_cache_hit_rate= (Qcache_hits + 1) / (Qcache_hits + Qcache_inserts + 1) * 100
- cache_hits=Qcache_hits
- cache_inserts=Qcache_inserts
- cache_free_blocks=Qcache_free_blocks
- cache_free_memory=Qcache_free_memory
units:
- cache_free_memory=B->KB
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
platform: mysql
username: ^_^username^_^
password: ^_^password^_^
database: ^_^database^_^
timeout: ^_^timeout^_^
# SQL查询方式: oneRow, multiRow, columns
queryType: columns
# sql
sql: show global status like 'QCache%';
url: ^_^url^_^

- name: innodb
Expand All @@ -133,23 +204,45 @@ metrics:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: innodb_data_reads
type: 0
unit: 次数
unit: Times
- field: innodb_data_writes
type: 0
unit: 次数
unit: Times
- field: innodb_data_read
type: 0
unit: kb
unit: MB
- field: innodb_data_written
type: 0
unit: kb
unit: MB
- field: innodb_buffer_hit_rate
type: 0
unit: '%'
aliasFields:
- Innodb_data_reads
- Innodb_data_writes
- Innodb_data_read
- Innodb_data_written
- Innodb_buffer_pool_read_requests
- Innodb_buffer_pool_read_ahead
- Innodb_buffer_pool_reads
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
- innodb_buffer_hit_rate= (Innodb_buffer_pool_read_requests + 1) / (Innodb_buffer_pool_read_requests + Innodb_buffer_pool_read_ahead + Innodb_buffer_pool_reads + 1) * 100
- innodb_data_reads=Innodb_data_reads
- innodb_data_writes=Innodb_data_writes
- innodb_data_read=Innodb_data_read
- innodb_data_written=Innodb_data_written
units:
- innodb_data_read=KB->MB
- innodb_data_written=KB->MB
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
platform: mysql
platform: mariadb
username: ^_^username^_^
password: ^_^password^_^
database: ^_^database^_^
Expand Down