feat: 标签扩展:新增mysql查询超时设置 #18
This commit is contained in:
@@ -52,9 +52,11 @@ public class JdbcCommonCollect extends AbstractCollect {
|
|||||||
}
|
}
|
||||||
JdbcProtocol jdbcProtocol = metrics.getJdbc();
|
JdbcProtocol jdbcProtocol = metrics.getJdbc();
|
||||||
String databaseUrl = constructDatabaseUrl(jdbcProtocol);
|
String databaseUrl = constructDatabaseUrl(jdbcProtocol);
|
||||||
|
//获取查询语句/获取链接最大超时时间
|
||||||
|
int timeout = metrics.getJdbc().getTimeout().intValue();
|
||||||
try {
|
try {
|
||||||
Statement statement = getConnection(jdbcProtocol.getUsername(),
|
Statement statement = getConnection(jdbcProtocol.getUsername(),
|
||||||
jdbcProtocol.getPassword(), databaseUrl);
|
jdbcProtocol.getPassword(), databaseUrl,timeout);
|
||||||
switch (jdbcProtocol.getQueryType()) {
|
switch (jdbcProtocol.getQueryType()) {
|
||||||
case QUERY_TYPE_ONE_ROW:
|
case QUERY_TYPE_ONE_ROW:
|
||||||
queryOneRow(statement, jdbcProtocol.getSql(), metrics.getAliasFields(), builder, startTime);
|
queryOneRow(statement, jdbcProtocol.getSql(), metrics.getAliasFields(), builder, startTime);
|
||||||
@@ -95,7 +97,7 @@ public class JdbcCommonCollect extends AbstractCollect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Statement getConnection(String username, String password, String url) throws Exception {
|
private Statement getConnection(String username, String password, String url,Integer timeout) throws Exception {
|
||||||
CacheIdentifier identifier = CacheIdentifier.builder()
|
CacheIdentifier identifier = CacheIdentifier.builder()
|
||||||
.ip(url)
|
.ip(url)
|
||||||
.username(username).password(password).build();
|
.username(username).password(password).build();
|
||||||
@@ -106,7 +108,7 @@ public class JdbcCommonCollect extends AbstractCollect {
|
|||||||
try {
|
try {
|
||||||
statement = jdbcConnect.getConnection().createStatement();
|
statement = jdbcConnect.getConnection().createStatement();
|
||||||
// 设置查询超时时间10秒
|
// 设置查询超时时间10秒
|
||||||
statement.setQueryTimeout(10);
|
statement.setQueryTimeout(timeout);
|
||||||
// 设置查询最大行数1000行
|
// 设置查询最大行数1000行
|
||||||
statement.setMaxRows(1000);
|
statement.setMaxRows(1000);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -130,7 +132,7 @@ public class JdbcCommonCollect extends AbstractCollect {
|
|||||||
Connection connection = DriverManager.getConnection(url, username, password);
|
Connection connection = DriverManager.getConnection(url, username, password);
|
||||||
statement = connection.createStatement();
|
statement = connection.createStatement();
|
||||||
// 设置查询超时时间10秒
|
// 设置查询超时时间10秒
|
||||||
statement.setQueryTimeout(10);
|
statement.setQueryTimeout(timeout);
|
||||||
// 设置查询最大行数1000行
|
// 设置查询最大行数1000行
|
||||||
statement.setMaxRows(1000);
|
statement.setMaxRows(1000);
|
||||||
JdbcConnect jdbcConnect = new JdbcConnect(connection);
|
JdbcConnect jdbcConnect = new JdbcConnect(connection);
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ public class JdbcProtocol {
|
|||||||
* 数据库
|
* 数据库
|
||||||
*/
|
*/
|
||||||
private String database;
|
private String database;
|
||||||
|
/**
|
||||||
|
* 超时时间
|
||||||
|
*/
|
||||||
|
private Long timeout;
|
||||||
/**
|
/**
|
||||||
* 数据库类型 mysql oracle ...
|
* 数据库类型 mysql oracle ...
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ configmap:
|
|||||||
type: 2
|
type: 2
|
||||||
- key: database
|
- key: database
|
||||||
type: 1
|
type: 1
|
||||||
|
- key: timeout
|
||||||
|
type: 0
|
||||||
|
required: false
|
||||||
|
defaultValue: 3000
|
||||||
- key: url
|
- key: url
|
||||||
type: 1
|
type: 1
|
||||||
# 指标组列表
|
# 指标组列表
|
||||||
@@ -61,6 +65,7 @@ metrics:
|
|||||||
username: ^_^username^_^
|
username: ^_^username^_^
|
||||||
password: ^_^password^_^
|
password: ^_^password^_^
|
||||||
database: ^_^database^_^
|
database: ^_^database^_^
|
||||||
|
timeout: ^_^timeout^_^
|
||||||
# SQL查询方式: oneRow, multiRow, columns
|
# SQL查询方式: oneRow, multiRow, columns
|
||||||
queryType: columns
|
queryType: columns
|
||||||
# sql
|
# sql
|
||||||
|
|||||||
@@ -28,3 +28,9 @@ param:
|
|||||||
name: URL
|
name: URL
|
||||||
type: text
|
type: text
|
||||||
required: false
|
required: false
|
||||||
|
- field: timeout
|
||||||
|
name: 超时时间
|
||||||
|
type: number
|
||||||
|
required: false
|
||||||
|
defaultValue: 3
|
||||||
|
placeholder: '请输入mysql可接受的超时时间'
|
||||||
Reference in New Issue
Block a user