|
|
@ -17,65 +17,47 @@ |
|
|
|
package org.apache.dolphinscheduler.dao; |
|
|
|
package org.apache.dolphinscheduler.dao; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.druid.pool.DruidDataSource; |
|
|
|
import com.alibaba.druid.pool.DruidDataSource; |
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
import java.sql.Connection; |
|
|
|
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import org.apache.dolphinscheduler.common.enums.DbType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.DbType; |
|
|
|
import org.apache.dolphinscheduler.dao.datasource.ConnectionFactory; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.MonitorRecord; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.MonitorRecord; |
|
|
|
import org.apache.commons.configuration.Configuration; |
|
|
|
|
|
|
|
import org.apache.commons.configuration.ConfigurationException; |
|
|
|
|
|
|
|
import org.apache.commons.configuration.PropertiesConfiguration; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.utils.MysqlPerformance; |
|
|
|
import org.apache.dolphinscheduler.dao.utils.MysqlPerformance; |
|
|
|
import org.apache.dolphinscheduler.dao.utils.PostgrePerformance; |
|
|
|
import org.apache.dolphinscheduler.dao.utils.PostgrePerformance; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import java.sql.*; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* database state dao |
|
|
|
* database state dao |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Component |
|
|
|
public class MonitorDBDao { |
|
|
|
public class MonitorDBDao { |
|
|
|
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(MonitorDBDao.class); |
|
|
|
private static Logger logger = LoggerFactory.getLogger(MonitorDBDao.class); |
|
|
|
|
|
|
|
|
|
|
|
public static final String VARIABLE_NAME = "variable_name"; |
|
|
|
public static final String VARIABLE_NAME = "variable_name"; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@Autowired |
|
|
|
* load conf |
|
|
|
private DruidDataSource dataSource; |
|
|
|
*/ |
|
|
|
|
|
|
|
private static Configuration conf; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
conf = new PropertiesConfiguration(Constants.APPLICATION_PROPERTIES); |
|
|
|
|
|
|
|
}catch (ConfigurationException e){ |
|
|
|
|
|
|
|
logger.error("load configuration excetpion",e); |
|
|
|
|
|
|
|
System.exit(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get current db performance |
|
|
|
* get current db performance |
|
|
|
* @return MonitorRecord |
|
|
|
* @return MonitorRecord |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static MonitorRecord getCurrentDbPerformance(){ |
|
|
|
public MonitorRecord getCurrentDbPerformance(){ |
|
|
|
MonitorRecord monitorRecord = null; |
|
|
|
MonitorRecord monitorRecord = null; |
|
|
|
Connection conn = null; |
|
|
|
Connection conn = null; |
|
|
|
DruidDataSource dataSource = null; |
|
|
|
|
|
|
|
try{ |
|
|
|
try{ |
|
|
|
dataSource = ConnectionFactory.getDataSource(); |
|
|
|
|
|
|
|
dataSource.setInitialSize(2); |
|
|
|
|
|
|
|
dataSource.setMinIdle(2); |
|
|
|
|
|
|
|
dataSource.setMaxActive(2); |
|
|
|
|
|
|
|
conn = dataSource.getConnection(); |
|
|
|
conn = dataSource.getConnection(); |
|
|
|
if(conn == null){ |
|
|
|
String driverClassName = dataSource.getDriverClassName(); |
|
|
|
return monitorRecord; |
|
|
|
if(driverClassName.contains(DbType.MYSQL.toString().toLowerCase())){ |
|
|
|
} |
|
|
|
|
|
|
|
if(conf.getString(Constants.SPRING_DATASOURCE_DRIVER_CLASS_NAME).contains(DbType.MYSQL.toString().toLowerCase())) { |
|
|
|
|
|
|
|
return new MysqlPerformance().getMonitorRecord(conn); |
|
|
|
return new MysqlPerformance().getMonitorRecord(conn); |
|
|
|
} else if(conf.getString(Constants.SPRING_DATASOURCE_DRIVER_CLASS_NAME).contains(DbType.POSTGRESQL.toString().toLowerCase())){ |
|
|
|
} else if(driverClassName.contains(DbType.POSTGRESQL.toString().toLowerCase())){ |
|
|
|
return new PostgrePerformance().getMonitorRecord(conn); |
|
|
|
return new PostgrePerformance().getMonitorRecord(conn); |
|
|
|
} |
|
|
|
} |
|
|
|
}catch (Exception e) { |
|
|
|
}catch (Exception e) { |
|
|
@ -85,9 +67,6 @@ public class MonitorDBDao { |
|
|
|
if (conn != null) { |
|
|
|
if (conn != null) { |
|
|
|
conn.close(); |
|
|
|
conn.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
if(dataSource != null){ |
|
|
|
|
|
|
|
dataSource.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
logger.error("SQLException ", e); |
|
|
|
logger.error("SQLException ", e); |
|
|
|
} |
|
|
|
} |
|
|
@ -99,7 +78,7 @@ public class MonitorDBDao { |
|
|
|
* query database state |
|
|
|
* query database state |
|
|
|
* @return MonitorRecord list |
|
|
|
* @return MonitorRecord list |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static List<MonitorRecord> queryDatabaseState() { |
|
|
|
public List<MonitorRecord> queryDatabaseState() { |
|
|
|
List<MonitorRecord> list = new ArrayList<>(1); |
|
|
|
List<MonitorRecord> list = new ArrayList<>(1); |
|
|
|
|
|
|
|
|
|
|
|
MonitorRecord monitorRecord = getCurrentDbPerformance(); |
|
|
|
MonitorRecord monitorRecord = getCurrentDbPerformance(); |
|
|
|