Add dolphinscheduler-dao-plugin module (#15019)
This commit is contained in:
parent
0a2cd61a85
commit
33084d281f
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
|
||||
spring:
|
||||
profiles:
|
||||
active: postgresql
|
||||
jackson:
|
||||
time-zone: UTC
|
||||
date-format: "yyyy-MM-dd HH:mm:ss"
|
||||
|
|
|
|||
|
|
@ -50,6 +50,12 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-meter</artifactId>
|
||||
|
|
|
|||
|
|
@ -22,9 +22,8 @@ import org.apache.dolphinscheduler.api.service.MonitorService;
|
|||
import org.apache.dolphinscheduler.common.constants.Constants;
|
||||
import org.apache.dolphinscheduler.common.model.Server;
|
||||
import org.apache.dolphinscheduler.common.model.WorkerServerModel;
|
||||
import org.apache.dolphinscheduler.dao.MonitorDBDao;
|
||||
import org.apache.dolphinscheduler.dao.entity.MonitorRecord;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMonitor;
|
||||
import org.apache.dolphinscheduler.registry.api.RegistryClient;
|
||||
import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType;
|
||||
|
||||
|
|
@ -39,6 +38,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
|
|
@ -49,7 +49,7 @@ import com.google.common.collect.Sets;
|
|||
public class MonitorServiceImpl extends BaseServiceImpl implements MonitorService {
|
||||
|
||||
@Autowired
|
||||
private MonitorDBDao monitorDBDao;
|
||||
private DatabaseMonitor databaseMonitor;
|
||||
|
||||
@Autowired
|
||||
private RegistryClient registryClient;
|
||||
|
|
@ -63,8 +63,7 @@ public class MonitorServiceImpl extends BaseServiceImpl implements MonitorServic
|
|||
@Override
|
||||
public Map<String, Object> queryDatabaseState(User loginUser) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<MonitorRecord> monitorRecordList = monitorDBDao.queryDatabaseState();
|
||||
result.put(Constants.DATA_LIST, monitorRecordList);
|
||||
result.put(Constants.DATA_LIST, Lists.newArrayList(databaseMonitor.getDatabaseMetrics()));
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ server:
|
|||
custom-format: '%{client}a - %u %t "%r" %s %O %{ms}Tms'
|
||||
|
||||
spring:
|
||||
profiles:
|
||||
active: postgresql
|
||||
banner:
|
||||
charset: UTF-8
|
||||
jackson:
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@ import org.apache.dolphinscheduler.common.constants.Constants;
|
|||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.common.model.Server;
|
||||
import org.apache.dolphinscheduler.dao.MonitorDBDao;
|
||||
import org.apache.dolphinscheduler.dao.entity.MonitorRecord;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMetrics;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMonitor;
|
||||
import org.apache.dolphinscheduler.registry.api.RegistryClient;
|
||||
import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType;
|
||||
import org.apache.dolphinscheduler.spi.enums.DbType;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
|
|
@ -53,6 +53,8 @@ import org.mockito.quality.Strictness;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
|
||||
/**
|
||||
* monitor service test
|
||||
*/
|
||||
|
|
@ -66,7 +68,7 @@ public class MonitorServiceTest {
|
|||
private MonitorServiceImpl monitorService;
|
||||
|
||||
@Mock
|
||||
private MonitorDBDao monitorDBDao;
|
||||
private DatabaseMonitor databaseMonitor;
|
||||
|
||||
@Mock
|
||||
private ResourcePermissionCheckService resourcePermissionCheckService;
|
||||
|
|
@ -88,7 +90,7 @@ public class MonitorServiceTest {
|
|||
@Test
|
||||
public void testQueryDatabaseState() {
|
||||
mockPermissionCheck(ApiFuncIdentificationConstant.MONITOR_DATABASES_VIEW, true);
|
||||
Mockito.when(monitorDBDao.queryDatabaseState()).thenReturn(getList());
|
||||
Mockito.when(databaseMonitor.getDatabaseMetrics()).thenReturn(getDatabaseMetrics());
|
||||
Map<String, Object> result = monitorService.queryDatabaseState(user);
|
||||
logger.info(result.toString());
|
||||
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
|
||||
|
|
@ -138,14 +140,8 @@ public class MonitorServiceTest {
|
|||
serviceLogger)).thenReturn(true);
|
||||
}
|
||||
|
||||
private List<MonitorRecord> getList() {
|
||||
List<MonitorRecord> monitorRecordList = new ArrayList<>();
|
||||
monitorRecordList.add(getEntity());
|
||||
return monitorRecordList;
|
||||
}
|
||||
|
||||
private MonitorRecord getEntity() {
|
||||
MonitorRecord monitorRecord = new MonitorRecord();
|
||||
private DatabaseMetrics getDatabaseMetrics() {
|
||||
DatabaseMetrics monitorRecord = new DatabaseMetrics();
|
||||
monitorRecord.setDbType(DbType.MYSQL);
|
||||
return monitorRecord;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,16 @@
|
|||
#
|
||||
|
||||
spring:
|
||||
profiles:
|
||||
active: h2
|
||||
main:
|
||||
banner-mode: off
|
||||
sql:
|
||||
init:
|
||||
schema-locations: classpath:sql/dolphinscheduler_h2.sql
|
||||
datasource:
|
||||
driver-class-name: org.h2.Driver
|
||||
url: jdbc:h2:mem:dolphinscheduler;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true;INIT=runscript from 'classpath:sql/dolphinscheduler_h2.sql'
|
||||
url: jdbc:h2:mem:dolphinscheduler;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true;
|
||||
username: sa
|
||||
password: ""
|
||||
|
||||
|
|
|
|||
|
|
@ -27,11 +27,15 @@ import java.io.Reader;
|
|||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
@Slf4j
|
||||
public class ClasspathSqlScriptParser implements SqlScriptParser {
|
||||
|
||||
private final String sqlScriptPath;
|
||||
|
|
@ -46,6 +50,10 @@ public class ClasspathSqlScriptParser implements SqlScriptParser {
|
|||
@Override
|
||||
public List<String> getAllSql() throws IOException {
|
||||
Resource sqlScriptResource = new ClassPathResource(sqlScriptPath);
|
||||
if (!sqlScriptResource.exists()) {
|
||||
log.warn("The sql script file {} doesn't exist", sqlScriptPath);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<String> result = new ArrayList<>();
|
||||
try (
|
||||
InputStream inputStream = sqlScriptResource.getInputStream();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
~ contributor license agreements. See the NOTICE file distributed with
|
||||
~ this work for additional information regarding copyright ownership.
|
||||
~ The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
~ (the "License"); you may not use this file except in compliance with
|
||||
~ the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-plugin</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dolphinscheduler-dao-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.plugin.api;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMonitor;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
|
||||
/**
|
||||
* DaoPluginConfiguration used to configure the dao plugin.
|
||||
*/
|
||||
public interface DaoPluginConfiguration {
|
||||
|
||||
DbType dbType();
|
||||
|
||||
DatabaseMonitor databaseMonitor();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.plugin.api.monitor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DatabaseMetrics {
|
||||
|
||||
private DbType dbType;
|
||||
|
||||
private DatabaseHealthStatus state;
|
||||
|
||||
private long maxConnections;
|
||||
|
||||
private long maxUsedConnections;
|
||||
|
||||
private long threadsConnections;
|
||||
|
||||
private long threadsRunningConnections;
|
||||
|
||||
private Date date;
|
||||
|
||||
public enum DatabaseHealthStatus {
|
||||
YES,
|
||||
NO
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.plugin.api.monitor;
|
||||
|
||||
public interface DatabaseMonitor {
|
||||
|
||||
DatabaseMetrics getDatabaseMetrics();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
~ contributor license agreements. See the NOTICE file distributed with
|
||||
~ this work for additional information regarding copyright ownership.
|
||||
~ The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
~ (the "License"); you may not use this file except in compliance with
|
||||
~ the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-plugin</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dolphinscheduler-dao-h2</artifactId>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.plugin.h2;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.DaoPluginConfiguration;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMonitor;
|
||||
import org.apache.dolphinscheduler.dao.plugin.h2.monitor.H2Monitor;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
|
||||
@Profile("h2")
|
||||
@Configuration
|
||||
public class H2DaoPluginConfiguration implements DaoPluginConfiguration {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Override
|
||||
public DbType dbType() {
|
||||
return DbType.H2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseMonitor databaseMonitor() {
|
||||
return new H2Monitor(dataSource);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.plugin.h2.monitor;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMetrics;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMonitor;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
|
||||
public class H2Monitor implements DatabaseMonitor {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
public H2Monitor(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public DatabaseMetrics getDatabaseMetrics() {
|
||||
DatabaseMetrics monitorRecord = new DatabaseMetrics();
|
||||
monitorRecord.setDate(new Date());
|
||||
monitorRecord.setDbType(DbType.H2);
|
||||
monitorRecord.setState(DatabaseMetrics.DatabaseHealthStatus.YES);
|
||||
|
||||
try (
|
||||
Connection connection = dataSource.getConnection();
|
||||
Statement pstmt = connection.createStatement()) {
|
||||
|
||||
try (
|
||||
ResultSet rs1 = pstmt
|
||||
.executeQuery("select count(1) as total from information_schema.sessions;")) {
|
||||
if (rs1.next()) {
|
||||
int currentSessions = rs1.getInt("total");
|
||||
monitorRecord.setThreadsConnections(currentSessions);
|
||||
monitorRecord.setMaxUsedConnections(currentSessions);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return monitorRecord;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
~ contributor license agreements. See the NOTICE file distributed with
|
||||
~ this work for additional information regarding copyright ownership.
|
||||
~ The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
~ (the "License"); you may not use this file except in compliance with
|
||||
~ the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-plugin</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dolphinscheduler-dao-mysql</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.apache.dolphinscheduler.dao.plugin.mysql;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.DaoPluginConfiguration;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMonitor;
|
||||
import org.apache.dolphinscheduler.dao.plugin.mysql.monitor.MysqlMonitor;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
|
||||
@Profile("mysql")
|
||||
@Configuration
|
||||
public class MysqlDaoPluginConfiguration implements DaoPluginConfiguration {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Override
|
||||
public DbType dbType() {
|
||||
return DbType.MYSQL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseMonitor databaseMonitor() {
|
||||
return new MysqlMonitor(dataSource);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.plugin.mysql.monitor;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMetrics;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMonitor;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
|
||||
public class MysqlMonitor implements DatabaseMonitor {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
public MysqlMonitor(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public DatabaseMetrics getDatabaseMetrics() {
|
||||
DatabaseMetrics monitorRecord = new DatabaseMetrics();
|
||||
monitorRecord.setDate(new Date());
|
||||
monitorRecord.setDbType(DbType.MYSQL);
|
||||
monitorRecord.setState(DatabaseMetrics.DatabaseHealthStatus.YES);
|
||||
|
||||
try (
|
||||
Connection connection = dataSource.getConnection();
|
||||
Statement pstmt = connection.createStatement()) {
|
||||
|
||||
try (ResultSet rs1 = pstmt.executeQuery("show global variables")) {
|
||||
while (rs1.next()) {
|
||||
if ("MAX_CONNECTIONS".equalsIgnoreCase(rs1.getString("variable_name"))) {
|
||||
monitorRecord.setMaxConnections(Long.parseLong(rs1.getString("value")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (ResultSet rs2 = pstmt.executeQuery("show global status")) {
|
||||
while (rs2.next()) {
|
||||
if ("MAX_USED_CONNECTIONS".equalsIgnoreCase(rs2.getString("variable_name"))) {
|
||||
monitorRecord.setMaxUsedConnections(Long.parseLong(rs2.getString("value")));
|
||||
} else if ("THREADS_CONNECTED".equalsIgnoreCase(rs2.getString("variable_name"))) {
|
||||
monitorRecord.setThreadsConnections(Long.parseLong(rs2.getString("value")));
|
||||
} else if ("THREADS_RUNNING".equalsIgnoreCase(rs2.getString("variable_name"))) {
|
||||
monitorRecord.setThreadsRunningConnections(Long.parseLong(rs2.getString("value")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return monitorRecord;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
~ contributor license agreements. See the NOTICE file distributed with
|
||||
~ this work for additional information regarding copyright ownership.
|
||||
~ The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
~ (the "License"); you may not use this file except in compliance with
|
||||
~ the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-plugin</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dolphinscheduler-dao-plugin-all</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-h2</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-postgresql</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-mysql</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
~ contributor license agreements. See the NOTICE file distributed with
|
||||
~ this work for additional information regarding copyright ownership.
|
||||
~ The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
~ (the "License"); you may not use this file except in compliance with
|
||||
~ the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-plugin</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dolphinscheduler-dao-postgresql</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.plugin.postgresql;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.DaoPluginConfiguration;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMonitor;
|
||||
import org.apache.dolphinscheduler.dao.plugin.postgresql.monitor.PostgresqlMonitor;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
|
||||
@Profile("postgresql")
|
||||
@Configuration
|
||||
public class PostgresqlDaoPluginConfiguration implements DaoPluginConfiguration {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Override
|
||||
public DbType dbType() {
|
||||
return DbType.POSTGRE_SQL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseMonitor databaseMonitor() {
|
||||
return new PostgresqlMonitor(dataSource);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.plugin.postgresql.monitor;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMetrics;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMonitor;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
|
||||
public class PostgresqlMonitor implements DatabaseMonitor {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
public PostgresqlMonitor(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public DatabaseMetrics getDatabaseMetrics() {
|
||||
DatabaseMetrics monitorRecord = new DatabaseMetrics();
|
||||
monitorRecord.setDate(new Date());
|
||||
monitorRecord.setState(DatabaseMetrics.DatabaseHealthStatus.YES);
|
||||
monitorRecord.setDbType(DbType.POSTGRE_SQL);
|
||||
|
||||
try (
|
||||
Connection connection = dataSource.getConnection();
|
||||
Statement pstmt = connection.createStatement()) {
|
||||
|
||||
try (ResultSet rs1 = pstmt.executeQuery("select count(*) from pg_stat_activity;")) {
|
||||
if (rs1.next()) {
|
||||
monitorRecord.setThreadsConnections(rs1.getInt("count"));
|
||||
}
|
||||
}
|
||||
|
||||
try (ResultSet rs2 = pstmt.executeQuery("show max_connections")) {
|
||||
if (rs2.next()) {
|
||||
monitorRecord.setMaxConnections(rs2.getInt("max_connections"));
|
||||
}
|
||||
}
|
||||
|
||||
try (
|
||||
ResultSet rs3 =
|
||||
pstmt.executeQuery("select count(*) from pg_stat_activity pg where pg.state = 'active';")) {
|
||||
if (rs3.next()) {
|
||||
monitorRecord.setThreadsRunningConnections(rs3.getInt("count"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return monitorRecord;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
~ contributor license agreements. See the NOTICE file distributed with
|
||||
~ this work for additional information regarding copyright ownership.
|
||||
~ The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
~ (the "License"); you may not use this file except in compliance with
|
||||
~ the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dolphinscheduler-dao-plugin</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>dolphinscheduler-dao-api</module>
|
||||
<module>dolphinscheduler-dao-plugin-all</module>
|
||||
<module>dolphinscheduler-dao-h2</module>
|
||||
<module>dolphinscheduler-dao-mysql</module>
|
||||
<module>dolphinscheduler-dao-postgresql</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-bom</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
|
|
@ -50,6 +50,11 @@
|
|||
<artifactId>dolphinscheduler-task-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-plugin-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
|
|
@ -83,15 +88,6 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
|
|
@ -107,11 +103,6 @@
|
|||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-storage-api</artifactId>
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.entity.MonitorRecord;
|
||||
import org.apache.dolphinscheduler.dao.utils.H2Performance;
|
||||
import org.apache.dolphinscheduler.dao.utils.MySQLPerformance;
|
||||
import org.apache.dolphinscheduler.dao.utils.PostgreSQLPerformance;
|
||||
import org.apache.dolphinscheduler.spi.enums.DbType;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MonitorDBDao {
|
||||
|
||||
public static final String VARIABLE_NAME = "variable_name";
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
private MonitorRecord getCurrentDbPerformance() {
|
||||
try (final Connection conn = dataSource.getConnection()) {
|
||||
String driverClassName = DriverManager.getDriver(conn.getMetaData().getURL()).getClass().getName();
|
||||
if (driverClassName.contains(DbType.MYSQL.toString().toLowerCase())) {
|
||||
return new MySQLPerformance().getMonitorRecord(conn);
|
||||
} else if (driverClassName.contains(DbType.POSTGRESQL.toString().toLowerCase())) {
|
||||
return new PostgreSQLPerformance().getMonitorRecord(conn);
|
||||
} else if (driverClassName.contains(DbType.H2.toString().toLowerCase())) {
|
||||
return new H2Performance().getMonitorRecord(conn);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("SQLException: {}", e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* query database state
|
||||
*
|
||||
* @return MonitorRecord list
|
||||
*/
|
||||
public List<MonitorRecord> queryDatabaseState() {
|
||||
List<MonitorRecord> list = new ArrayList<>(1);
|
||||
|
||||
MonitorRecord monitorRecord = getCurrentDbPerformance();
|
||||
if (monitorRecord != null) {
|
||||
list.add(monitorRecord);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,21 +17,18 @@
|
|||
|
||||
package org.apache.dolphinscheduler.dao.datasource;
|
||||
|
||||
import org.apache.ibatis.mapping.DatabaseIdProvider;
|
||||
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.DaoPluginConfiguration;
|
||||
import org.apache.dolphinscheduler.dao.plugin.api.monitor.DatabaseMonitor;
|
||||
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
|
|
@ -53,6 +50,12 @@ public class SpringConnectionFactory {
|
|||
@Autowired(required = false)
|
||||
public DataSourceScriptDatabaseInitializer dataSourceScriptDatabaseInitializer;
|
||||
|
||||
/**
|
||||
* Inject this field to make sure the DaoPluginConfiguration is initialized before SpringConnectionFactory.
|
||||
*/
|
||||
@Autowired
|
||||
public DaoPluginConfiguration daoPluginConfiguration;
|
||||
|
||||
@Bean
|
||||
public MybatisPlusInterceptor paginationInterceptor(DbType dbType) {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
|
|
@ -66,7 +69,8 @@ public class SpringConnectionFactory {
|
|||
}
|
||||
|
||||
@Bean
|
||||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource, GlobalConfig globalConfig,
|
||||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource,
|
||||
GlobalConfig globalConfig,
|
||||
DbType dbType) throws Exception {
|
||||
MybatisConfiguration configuration = new MybatisConfiguration();
|
||||
configuration.setMapUnderscoreToCamelCase(true);
|
||||
|
|
@ -82,9 +86,9 @@ public class SpringConnectionFactory {
|
|||
sqlSessionFactoryBean.setGlobalConfig(globalConfig);
|
||||
sqlSessionFactoryBean.setTypeAliasesPackage("org.apache.dolphinscheduler.dao.entity");
|
||||
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
// todo: if the different database has different sql, we need to add the different mapper.
|
||||
sqlSessionFactoryBean
|
||||
.setMapperLocations(resolver.getResources("org/apache/dolphinscheduler/dao/mapper/*Mapper.xml"));
|
||||
sqlSessionFactoryBean.setDatabaseIdProvider(databaseIdProvider());
|
||||
return sqlSessionFactoryBean.getObject();
|
||||
}
|
||||
|
||||
|
|
@ -95,32 +99,13 @@ public class SpringConnectionFactory {
|
|||
}
|
||||
|
||||
@Bean
|
||||
public DatabaseIdProvider databaseIdProvider() {
|
||||
DatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("MySQL", "mysql");
|
||||
properties.setProperty("PostgreSQL", "pg");
|
||||
properties.setProperty("h2", "h2");
|
||||
databaseIdProvider.setProperties(properties);
|
||||
return databaseIdProvider;
|
||||
public DbType dbType() {
|
||||
return daoPluginConfiguration.dbType();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
@Profile("mysql")
|
||||
public DbType mysql() {
|
||||
return DbType.MYSQL;
|
||||
public DatabaseMonitor databaseMonitor() {
|
||||
return daoPluginConfiguration.databaseMonitor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DbType h2() {
|
||||
return DbType.H2;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
@Profile("postgresql")
|
||||
public DbType postgresql() {
|
||||
return DbType.POSTGRE_SQL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.utils;
|
||||
|
||||
import org.apache.dolphinscheduler.common.enums.Flag;
|
||||
import org.apache.dolphinscheduler.dao.entity.MonitorRecord;
|
||||
import org.apache.dolphinscheduler.spi.enums.DbType;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Date;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* H2 MEMORY DB Performance Monitor
|
||||
*/
|
||||
@Slf4j
|
||||
public class H2Performance extends BaseDBPerformance {
|
||||
|
||||
/**
|
||||
* return the current database performance
|
||||
*
|
||||
* @param conn connection
|
||||
* @return MonitorRecord
|
||||
*/
|
||||
@Override
|
||||
public MonitorRecord getMonitorRecord(Connection conn) {
|
||||
MonitorRecord monitorRecord = new MonitorRecord();
|
||||
monitorRecord.setDate(new Date());
|
||||
monitorRecord.setDbType(DbType.H2);
|
||||
monitorRecord.setState(Flag.YES);
|
||||
|
||||
try (Statement pstmt = conn.createStatement()) {
|
||||
try (
|
||||
ResultSet rs1 = pstmt
|
||||
.executeQuery("select count(1) as total from information_schema.sessions;")) {
|
||||
if (rs1.next()) {
|
||||
monitorRecord.setThreadsConnections(rs1.getInt("total"));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
monitorRecord.setState(Flag.NO);
|
||||
log.error("SQLException ", e);
|
||||
}
|
||||
return monitorRecord;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.utils;
|
||||
|
||||
import static org.apache.dolphinscheduler.dao.MonitorDBDao.VARIABLE_NAME;
|
||||
|
||||
import org.apache.dolphinscheduler.common.enums.Flag;
|
||||
import org.apache.dolphinscheduler.dao.entity.MonitorRecord;
|
||||
import org.apache.dolphinscheduler.spi.enums.DbType;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Date;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* MySQL performance
|
||||
*/
|
||||
@Slf4j
|
||||
public class MySQLPerformance extends BaseDBPerformance {
|
||||
|
||||
/**
|
||||
* get monitor record
|
||||
* @param conn connection
|
||||
* @return MonitorRecord
|
||||
*/
|
||||
@Override
|
||||
public MonitorRecord getMonitorRecord(Connection conn) {
|
||||
MonitorRecord monitorRecord = new MonitorRecord();
|
||||
monitorRecord.setDate(new Date());
|
||||
monitorRecord.setDbType(DbType.MYSQL);
|
||||
monitorRecord.setState(Flag.YES);
|
||||
|
||||
try (Statement pstmt = conn.createStatement()) {
|
||||
try (ResultSet rs1 = pstmt.executeQuery("show global variables")) {
|
||||
while (rs1.next()) {
|
||||
if ("MAX_CONNECTIONS".equalsIgnoreCase(rs1.getString(VARIABLE_NAME))) {
|
||||
monitorRecord.setMaxConnections(Long.parseLong(rs1.getString("value")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (ResultSet rs2 = pstmt.executeQuery("show global status")) {
|
||||
while (rs2.next()) {
|
||||
if ("MAX_USED_CONNECTIONS".equalsIgnoreCase(rs2.getString(VARIABLE_NAME))) {
|
||||
monitorRecord.setMaxUsedConnections(Long.parseLong(rs2.getString("value")));
|
||||
} else if ("THREADS_CONNECTED".equalsIgnoreCase(rs2.getString(VARIABLE_NAME))) {
|
||||
monitorRecord.setThreadsConnections(Long.parseLong(rs2.getString("value")));
|
||||
} else if ("THREADS_RUNNING".equalsIgnoreCase(rs2.getString(VARIABLE_NAME))) {
|
||||
monitorRecord.setThreadsRunningConnections(Long.parseLong(rs2.getString("value")));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
monitorRecord.setState(Flag.NO);
|
||||
log.error("SQLException ", e);
|
||||
}
|
||||
return monitorRecord;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.utils;
|
||||
|
||||
import org.apache.dolphinscheduler.common.enums.Flag;
|
||||
import org.apache.dolphinscheduler.dao.entity.MonitorRecord;
|
||||
import org.apache.dolphinscheduler.spi.enums.DbType;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Date;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class PostgreSQLPerformance extends BaseDBPerformance {
|
||||
|
||||
/**
|
||||
* get monitor record
|
||||
*
|
||||
* @param conn connection
|
||||
* @return MonitorRecord
|
||||
*/
|
||||
@Override
|
||||
public MonitorRecord getMonitorRecord(Connection conn) {
|
||||
MonitorRecord monitorRecord = new MonitorRecord();
|
||||
monitorRecord.setDate(new Date());
|
||||
monitorRecord.setState(Flag.YES);
|
||||
monitorRecord.setDbType(DbType.POSTGRESQL);
|
||||
|
||||
try (Statement pstmt = conn.createStatement()) {
|
||||
try (ResultSet rs1 = pstmt.executeQuery("select count(*) from pg_stat_activity;")) {
|
||||
if (rs1.next()) {
|
||||
monitorRecord.setThreadsConnections(rs1.getInt("count"));
|
||||
}
|
||||
}
|
||||
|
||||
try (ResultSet rs2 = pstmt.executeQuery("show max_connections")) {
|
||||
if (rs2.next()) {
|
||||
monitorRecord.setMaxConnections(rs2.getInt("max_connections"));
|
||||
}
|
||||
}
|
||||
|
||||
try (
|
||||
ResultSet rs3 =
|
||||
pstmt.executeQuery("select count(*) from pg_stat_activity pg where pg.state = 'active';")) {
|
||||
if (rs3.next()) {
|
||||
monitorRecord.setThreadsRunningConnections(rs3.getInt("count"));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
monitorRecord.setState(Flag.NO);
|
||||
log.error("SQLException ", e);
|
||||
}
|
||||
return monitorRecord;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,8 +16,13 @@
|
|||
#
|
||||
|
||||
spring:
|
||||
profiles:
|
||||
active: h2
|
||||
sql:
|
||||
init:
|
||||
schema-locations: classpath:sql/dolphinscheduler_h2.sql
|
||||
datasource:
|
||||
driver-class-name: org.h2.Driver
|
||||
url: jdbc:h2:mem:dolphinscheduler;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true;INIT=runscript from 'classpath:sql/dolphinscheduler_h2.sql'
|
||||
url: jdbc:h2:mem:dolphinscheduler;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true;
|
||||
username: sa
|
||||
password: ""
|
||||
|
|
|
|||
|
|
@ -511,7 +511,6 @@ The text of each license is also included at licenses/LICENSE-[project].txt.
|
|||
zt-zip 1.15: https://github.com/zeroturnaround/zt-zip/blob/master/LICENSE, Apache 2.0
|
||||
content-type 2.2: https://mvnrepository.com/artifact/com.nimbusds/content-type/2.2, Apache 2.0
|
||||
jackson-dataformat-xml 2.13.3: https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml/2.13.3, Apache 2.0
|
||||
jna-platform 5.6.0: https://mvnrepository.com/artifact/net.java.dev.jna/jna-platform/5.6.0, Apache 2.0
|
||||
lang-tag 1.6: https://mvnrepository.com/artifact/com.nimbusds/lang-tag/1.6, Apache 2.0
|
||||
netty-codec-dns 4.1.53.Final: https://mvnrepository.com/artifact/io.netty/netty-codec-dns/4.1.53.Final, Apache 2.0
|
||||
netty-codec-socks 4.1.53.Final: https://mvnrepository.com/artifact/io.netty/netty-codec-socks/4.1.53.Final, Apache 2.0
|
||||
|
|
@ -651,6 +650,7 @@ The text of each license is also included at licenses/LICENSE-[project].txt.
|
|||
slf4j-api 1.7.36: https://mvnrepository.com/artifact/org.slf4j/slf4j-api/1.7.36, MIT
|
||||
animal-sniffer-annotations 1.19 https://mvnrepository.com/artifact/org.codehaus.mojo/animal-sniffer-annotations/1.19, MIT
|
||||
checker-qual 3.12.0 https://mvnrepository.com/artifact/org.checkerframework/checker-qual/3.12.0, MIT + GPLv2
|
||||
checker-qual 3.19.0 https://mvnrepository.com/artifact/org.checkerframework/checker-qual/3.19.0, MIT + GPLv2
|
||||
Java-WebSocket 1.5.1: https://github.com/TooTallNate/Java-WebSocket, MIT
|
||||
oshi-core 6.1.1: https://mvnrepository.com/artifact/com.github.oshi/oshi-core/6.1.1, MIT
|
||||
unirest-java 3.7.04-standalone: https://mvnrepository.com/artifact/com.konghq/unirest-java/3.7.04, MIT
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
spring:
|
||||
profiles:
|
||||
active: postgresql
|
||||
banner:
|
||||
charset: UTF-8
|
||||
jackson:
|
||||
|
|
|
|||
|
|
@ -56,11 +56,6 @@
|
|||
<artifactId>dolphinscheduler-alert-server</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-test</artifactId>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
|
||||
spring:
|
||||
profiles:
|
||||
active: h2
|
||||
jackson:
|
||||
time-zone: UTC
|
||||
date-format: "yyyy-MM-dd HH:mm:ss"
|
||||
|
|
|
|||
31
pom.xml
31
pom.xml
|
|
@ -56,6 +56,7 @@
|
|||
<module>dolphinscheduler-scheduler-plugin</module>
|
||||
<module>dolphinscheduler-storage-plugin</module>
|
||||
<module>dolphinscheduler-extract</module>
|
||||
<module>dolphinscheduler-dao-plugin</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
@ -259,6 +260,36 @@
|
|||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-plugin-all</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-h2</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-mysql</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-dao-postgresql</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ bucket4j-core-6.2.0.jar
|
|||
caffeine-2.9.3.jar
|
||||
checker-qual-3.12.0.jar
|
||||
checker-qual-3.19.0.jar
|
||||
checker-qual-3.5.0.jar
|
||||
classgraph-4.8.147.jar
|
||||
classmate-1.5.1.jar
|
||||
clickhouse-jdbc-0.4.6.jar
|
||||
|
|
@ -381,7 +380,6 @@ azure-core-http-netty-1.13.0.jar
|
|||
azure-identity-1.7.1.jar
|
||||
content-type-2.2.jar
|
||||
jackson-dataformat-xml-2.13.3.jar
|
||||
jna-platform-5.6.0.jar
|
||||
lang-tag-1.6.jar
|
||||
msal4j-1.13.3.jar
|
||||
msal4j-persistence-extension-1.1.0.jar
|
||||
|
|
|
|||
Loading…
Reference in New Issue