Skip to content

Commit

Permalink
Merge pull request #10 from uavorg/master
Browse files Browse the repository at this point in the history
merge from uavstack
  • Loading branch information
xxxllluuu committed Mar 16, 2018
2 parents 816cefe + c3ca10b commit 18e188c
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public void run() {

// windows
if (JVMToolHelper.isWindows()) {


JpcapCaptor jpcap =null;
try {
String Local_ip = "/" + ip;
// 存端口流量
Expand Down Expand Up @@ -89,7 +90,7 @@ public void run() {
}
NetworkInterface nc = devices[i];
// 打开网卡设备 ,创建某个卡口上的抓取对象,最大为65535个
JpcapCaptor jpcap = JpcapCaptor.openDevice(nc, 65535, false, 20);
jpcap = JpcapCaptor.openDevice(nc, 65535, false, 20);
jpcap.setFilter("tcp", true);// 设置过滤器

// 抓包 统计流量
Expand All @@ -99,6 +100,12 @@ public void run() {
catch (Exception e) {
log.err(this, "NetworkIo Monitor runs FAIL.", e);
}
finally {
if(jpcap!=null) {
// 关闭
jpcap.close();
}
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,10 @@ private void getJAXRSURLs(String jaxrsBaseUrl, Map<String, Set<String>> compServ
Map<String, Object> compDesInfo = (Map<String, Object>) compInfo.get("anno");

Map<String, Object> annoWebService = (Map<String, Object>) compDesInfo.get("javax.ws.rs.Path");

if (annoWebService == null) {
continue;
}

String resourceClassRelativePath = (String) annoWebService.get("value");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ private void collectDataSourceStat(MonitorElementInstance inst, ComboPooledDataS
String prefix = "get";

for (int i = 0; i < collectMtrx.length; i++) {
inst.setValue(MTRX_PREFIX + collectMtrx[i], ReflectionHelper.invoke(ComboPooledDataSource.class.getName(), pds,
prefix + collectMtrx[i], null, null));
Object obj = ReflectionHelper.invoke(ComboPooledDataSource.class.getName(), pds,
prefix + collectMtrx[i], null, null, this.getClass().getClassLoader());
inst.setValue(MTRX_PREFIX + collectMtrx[i], obj);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected void collectDBPoolMetrics(MonitorElement clientElem) {
cp.getClass().getClassLoader());

/**
* 匹配客户端应用
* 匹配客户端应用
*/
MonitorElementInstance inst = this.matchElemInstance(clientElem, jdbcURL);

Expand All @@ -183,7 +183,7 @@ protected void collectDBPoolMetrics(MonitorElement clientElem) {
}

/**
* 收集DataSource性能指标
* 收集DataSource性能指标
*
* @param inst
* @param pds
Expand All @@ -208,7 +208,7 @@ else if (className.indexOf("tomcat") > -1) {

for (int i = 0; i < collectMtrx.length; i++) {

Object val = ReflectionHelper.invoke(className, pds, prefix + collectMtrx[i], null, null);
Object val = ReflectionHelper.invoke(className, pds, prefix + collectMtrx[i], null, null,this.getClass().getClassLoader());

if (val == null) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected void collectDBPoolMetrics(MonitorElement clientElem) {
cp.getClass().getClassLoader());

/**
* 匹配客户端应用
* 匹配客户端应用
*/
MonitorElementInstance inst = this.matchElemInstance(clientElem, jdbcURL);

Expand All @@ -151,7 +151,7 @@ protected void collectDBPoolMetrics(MonitorElement clientElem) {
}

/**
* 收集DataSource指标
* 收集DataSource指标
*
* @param inst
* @param pds
Expand All @@ -173,7 +173,7 @@ private void collectDataSourceStat(MonitorElementInstance inst, DataSource pds)

for (int i = 0; i < collectMtrx.length; i++) {

Object val = ReflectionHelper.invoke(className, pool, prefix + collectMtrx[i], null, null);
Object val = ReflectionHelper.invoke(className, pool, prefix + collectMtrx[i], null, null,this.getClass().getClassLoader());

if (val == null) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ public class MybatisHookProxy extends AbsDBPoolHookProxy {

protected DynamicProxyInstaller dpInstall;

private ClassLoader webapploaderForMybatis = null;

@SuppressWarnings("rawtypes")
public MybatisHookProxy(String id, Map config) {

super(id, config);

dpInstall = new DynamicProxyInstaller();
Expand All @@ -60,7 +59,6 @@ public MybatisHookProxy(String id, Map config) {
public void start(HookContext context, ClassLoader webapploader) {

super.start(context, webapploader);
webapploaderForMybatis = webapploader;
Event event = context.get(Event.class);
switch (event) {
case SPRING_BEAN_REGIST:
Expand Down Expand Up @@ -104,7 +102,7 @@ protected void collectDBPoolMetrics(MonitorElement clientElem) {
continue;
}

collectDataSourceStat(inst, cp, webapploaderForMybatis);
collectDataSourceStat(inst, cp);
}
}

Expand Down Expand Up @@ -140,7 +138,7 @@ public void process(DPMethod m) throws Exception {
dpInstall.releaseTargetClassLoader();
}

private void collectDataSourceStat(MonitorElementInstance inst, DataSource pds, ClassLoader webapploader) {
private void collectDataSourceStat(MonitorElementInstance inst, DataSource pds) {

String[] collectMtrx = new String[] { "PoolMaximumActiveConnections", "PoolMaximumIdleConnections",
"PoolMaximumCheckoutTime", "PoolTimeToWait", "ActiveConnections", "IdleConnections", "RequestCount",
Expand All @@ -151,15 +149,15 @@ private void collectDataSourceStat(MonitorElementInstance inst, DataSource pds,
int i;
for (i = 0; i < 4; i++) {
inst.setValue(MTRX_PREFIX + collectMtrx[i],
ReflectionHelper.invoke(className, pds, prefix + collectMtrx[i], null, null, webapploader));
ReflectionHelper.invoke(className, pds, prefix + collectMtrx[i], null, null, this.getClass().getClassLoader()));
}

Object poolState = ReflectionHelper.invoke(className, pds, "getPoolState", null, null, webapploader);
Object poolState = ReflectionHelper.invoke(className, pds, "getPoolState", null, null, this.getClass().getClassLoader());

for (; i < collectMtrx.length; i++) {

inst.setValue(MTRX_PREFIX + collectMtrx[i], ReflectionHelper.invoke(PoolState.class.getName(), poolState,
prefix + collectMtrx[i], null, null, webapploader));
prefix + collectMtrx[i], null, null, this.getClass().getClassLoader()));
}

}
Expand Down
8 changes: 7 additions & 1 deletion com.creditease.uav.monitorframework.buildFat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<version>2.4.11</version>
<scope>compile</scope>
</dependency>
<!--Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
Expand Down Expand Up @@ -264,7 +270,7 @@
<artifactId>commons-httpclient</artifactId>
<version>3.0.1</version>
</dependency>

<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.creditease.monitorframework.fat;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
Expand All @@ -47,6 +48,10 @@
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.bson.Document;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
Expand All @@ -71,6 +76,7 @@
import com.creditease.monitorframework.fat.dbconnpool.DAOFactory.QueryHelper;
import com.creditease.monitorframework.fat.dubbo.IMyDubboService;
import com.creditease.monitorframework.fat.ivc.MyTestInjectObj;
import com.creditease.monitorframework.fat.mybatis.User;
import com.creditease.uav.cache.api.CacheManager;
import com.creditease.uav.cache.api.CacheManagerFactory;
import com.creditease.uav.httpasync.HttpAsyncClient;
Expand Down Expand Up @@ -837,6 +843,41 @@ public void testHikari() {
}

}

SqlSession session;

@GET
@Path("testMybatis")
public void testMybatis() {

try{
if (session == null) {

String resource = "com/creditease/monitorframework/fat/mybatis/mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
session = sqlSessionFactory.openSession();
}

User test = new User();
test.setId(1);
test.setName("test");
test.setAge(23);

session.insert("com.creditease.monitorframework.fat.mybatis.UserMapper.insertUser", test);

User blog = session.selectOne("com.creditease.monitorframework.fat.mybatis.UserMapper.selectUser", 1);

session.delete("com.creditease.monitorframework.fat.mybatis.UserMapper.selectUser", 1);

session.close();

}catch(Exception e) {

e.printStackTrace();
}
}


@POST
@Path("testInjectClass")
Expand Down Expand Up @@ -872,7 +913,7 @@ public void testInjectClass() {

}

// 进行服务之间交互
// 进行服务之间交互
CloseableHttpClient client = HttpClients.createDefault();
HttpUriRequest http = new HttpGet(
"http://localhost:8080/com.creditease.uav.monitorframework.buildFat/rs/http/httpclienttest");
Expand Down Expand Up @@ -909,7 +950,7 @@ public void testInjectClass() {

mongoClient.close();

// 进行服务之间交互
// 进行服务之间交互
CloseableHttpClient client2 = HttpClients.createDefault();

HttpUriRequest http2 = new HttpGet(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*-
* <<
* UAVStack
* ==
* Copyright (C) 2016 - 2017 UAVStack
* ==
* Licensed 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 com.creditease.monitorframework.fat.mybatis;


/**
* User description: ???
*
*/
public class User {

private int id;
private String name;
private int age;

/**
* @return the id
*/
public int getId() {

return id;
}

/**
* @param id the id to set
*/
public void setId(int id) {

this.id = id;
}

/**
* @return the name
*/
public String getName() {

return name;
}

/**
* @param name the name to set
*/
public void setName(String name) {

this.name = name;
}

/**
* @return the age
*/
public int getAge() {

return age;
}

/**
* @param age the age to set
*/
public void setAge(int age) {

this.age = age;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.creditease.monitorframework.fat.mybatis.UserMapper">
<select id="selectUser" resultType="com.creditease.monitorframework.fat.mybatis.User">
select * from mytest where id = #{id}
</select>
<select id="insertUser" parameterType="com.creditease.monitorframework.fat.mybatis.User">
insert into mytest(id,name, age) values(#{id},#{name}, #{age})
</select>
<select id="deleteUser">
delete from mytest where id = #{id}
</select>
</mapper>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://127.0.0.1:3306/testdb" />
<property name="username" value="root" />
<property name="password" value="root" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/creditease/monitorframework/fat/mybatis/UserMapper.xml" />
</mappers>
</configuration>

0 comments on commit 18e188c

Please sign in to comment.