Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
山不在高_有仙则灵
SkyWalking
提交
f6874d0d
S
SkyWalking
项目概览
山不在高_有仙则灵
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
12
Star
0
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f6874d0d
编写于
10月 18, 2017
作者:
wu-sheng
提交者:
GitHub
10月 18, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #524 from ascrutae/postgresql-support
support postgresql plugin
上级
64c9df9d
a2d910ba
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
137 addition
and
4 deletion
+137
-4
apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java
...walking/apm/network/trace/component/ComponentsDefine.java
+4
-1
apm-sniffer/apm-sdk-plugin/jdbc-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/jdbc-plugin/pom.xml
+6
-0
apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java
...plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java
+85
-0
apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java
...lking/apm/plugin/jdbc/connectionurl/parser/URLParser.java
+5
-2
apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/define/PostgreSQLInstrumentation.java
...ing/apm/plugin/jdbc/define/PostgreSQLInstrumentation.java
+35
-0
apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def
...ugin/jdbc-plugin/src/main/resources/skywalking-plugin.def
+2
-1
未找到文件。
apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java
浏览文件 @
f6874d0d
...
...
@@ -67,6 +67,8 @@ public class ComponentsDefine {
public
static
final
OfficialComponent
SHARDING_JDBC
=
new
OfficialComponent
(
21
,
"ShardingJDBC"
);
public
static
final
OfficialComponent
POSTGRESQL
=
new
OfficialComponent
(
22
,
"PostgreSQL"
);
private
static
ComponentsDefine
instance
=
new
ComponentsDefine
();
private
String
[]
components
;
...
...
@@ -76,7 +78,7 @@ public class ComponentsDefine {
}
public
ComponentsDefine
()
{
components
=
new
String
[
2
2
];
components
=
new
String
[
2
3
];
addComponent
(
TOMCAT
);
addComponent
(
HTTPCLIENT
);
addComponent
(
DUBBO
);
...
...
@@ -98,6 +100,7 @@ public class ComponentsDefine {
addComponent
(
JETTY_SERVER
);
addComponent
(
MEMCACHED
);
addComponent
(
SHARDING_JDBC
);
addComponent
(
POSTGRESQL
);
}
private
void
addComponent
(
OfficialComponent
component
)
{
...
...
apm-sniffer/apm-sdk-plugin/jdbc-plugin/pom.xml
浏览文件 @
f6874d0d
...
...
@@ -60,6 +60,12 @@
<version>
[2.0.14,6.0.6]
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
<version>
42.0.0
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
<build>
...
...
apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java
0 → 100644
浏览文件 @
f6874d0d
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.plugin.jdbc.connectionurl.parser
;
import
org.skywalking.apm.network.trace.component.ComponentsDefine
;
import
org.skywalking.apm.plugin.jdbc.ConnectionInfo
;
/**
* {@link PostgreSQLURLParser} parse connection url of mysql.
* <p>
* The {@link ConnectionInfo#host} be set the string between charset "//" and the first
* charset "/" after the charset "//", and {@link ConnectionInfo#databaseName} be set the
* string between the last index of "/" and the first charset "?". but one more thing, the
* {@link ConnectionInfo#hosts} be set if the host container multiple host.
*
* @author zhangxin
*/
public
class
PostgreSQLURLParser
extends
AbstractURLParser
{
private
static
final
int
DEFAULT_PORT
=
5432
;
private
static
final
String
DB_TYPE
=
"PostgreSQL"
;
public
PostgreSQLURLParser
(
String
url
)
{
super
(
url
);
}
@Override
protected
int
[]
fetchDatabaseHostsIndexRange
()
{
int
hostLabelStartIndex
=
url
.
indexOf
(
"//"
);
int
hostLabelEndIndex
=
url
.
indexOf
(
"/"
,
hostLabelStartIndex
+
2
);
return
new
int
[]
{
hostLabelStartIndex
+
2
,
hostLabelEndIndex
};
}
@Override
protected
int
[]
fetchDatabaseNameIndexRange
()
{
int
databaseStartTag
=
url
.
lastIndexOf
(
"/"
);
int
databaseEndTag
=
url
.
indexOf
(
"?"
,
databaseStartTag
);
if
(
databaseEndTag
==
-
1
)
{
databaseEndTag
=
url
.
length
();
}
return
new
int
[]
{
databaseStartTag
+
1
,
databaseEndTag
};
}
@Override
public
ConnectionInfo
parse
()
{
int
[]
hostRangeIndex
=
fetchDatabaseHostsIndexRange
();
String
hosts
=
url
.
substring
(
hostRangeIndex
[
0
],
hostRangeIndex
[
1
]);
String
[]
hostSegment
=
hosts
.
split
(
","
);
if
(
hostSegment
.
length
>
1
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
String
host
:
hostSegment
)
{
if
(
host
.
split
(
":"
).
length
==
1
)
{
sb
.
append
(
host
+
":"
+
DEFAULT_PORT
+
","
);
}
else
{
sb
.
append
(
host
+
","
);
}
}
return
new
ConnectionInfo
(
ComponentsDefine
.
POSTGRESQL
,
DB_TYPE
,
sb
.
toString
(),
fetchDatabaseNameFromURL
());
}
else
{
String
[]
hostAndPort
=
hostSegment
[
0
].
split
(
":"
);
if
(
hostAndPort
.
length
!=
1
)
{
return
new
ConnectionInfo
(
ComponentsDefine
.
POSTGRESQL
,
DB_TYPE
,
hostAndPort
[
0
],
Integer
.
valueOf
(
hostAndPort
[
1
]),
fetchDatabaseNameFromURL
());
}
else
{
return
new
ConnectionInfo
(
ComponentsDefine
.
POSTGRESQL
,
DB_TYPE
,
hostAndPort
[
0
],
DEFAULT_PORT
,
fetchDatabaseNameFromURL
());
}
}
}
}
apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java
浏览文件 @
f6874d0d
...
...
@@ -21,8 +21,8 @@ package org.skywalking.apm.plugin.jdbc.connectionurl.parser;
import
org.skywalking.apm.plugin.jdbc.ConnectionInfo
;
/**
* {@link URLParser#parser(String)} support parse the connection url, such as Mysql, Oracle, H2 Database.
*
But there are
some url cannot be parsed, such as Oracle connection url with multiple host.
* {@link URLParser#parser(String)} support parse the connection url, such as Mysql, Oracle, H2 Database.
But there are
* some url cannot be parsed, such as Oracle connection url with multiple host.
*
* @author zhangxin
*/
...
...
@@ -31,6 +31,7 @@ public class URLParser {
private
static
final
String
MYSQL_JDBC_URL_PREFIX
=
"jdbc:mysql"
;
private
static
final
String
ORACLE_JDBC_URL_PREFIX
=
"jdbc:oracle"
;
private
static
final
String
H2_JDBC_URL_PREFIX
=
"jdbc:h2"
;
private
static
final
String
POSTGRESQL_JDBC_URL_PREFIX
=
"jdbc:postgresql"
;
public
static
ConnectionInfo
parser
(
String
url
)
{
ConnectionURLParser
parser
=
null
;
...
...
@@ -40,6 +41,8 @@ public class URLParser {
parser
=
new
OracleURLParser
(
url
);
}
else
if
(
url
.
startsWith
(
H2_JDBC_URL_PREFIX
))
{
parser
=
new
H2URLParser
(
url
);
}
else
if
(
url
.
startsWith
(
POSTGRESQL_JDBC_URL_PREFIX
))
{
parser
=
new
PostgreSQLURLParser
(
url
);
}
return
parser
.
parse
();
}
...
...
apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/define/PostgreSQLInstrumentation.java
0 → 100644
浏览文件 @
f6874d0d
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.plugin.jdbc.define
;
import
org.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
/**
* {@link PostgreSQLInstrumentation} presents that skywalking intercepts {@link org.postgresql.Driver}.
*
* @author zhangxin
*/
public
class
PostgreSQLInstrumentation
extends
AbstractDatabaseInstrumentation
{
@Override
protected
ClassMatch
enhanceClass
()
{
return
byName
(
"org.postgresql.Driver"
);
}
}
apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def
浏览文件 @
f6874d0d
jdbc=org.skywalking.apm.plugin.jdbc.define.H2Instrumentation
jdbc=org.skywalking.apm.plugin.jdbc.define.MysqlInstrumentation
jdbc=org.skywalking.apm.plugin.jdbc.define.OracleInstrumentation
\ No newline at end of file
jdbc=org.skywalking.apm.plugin.jdbc.define.OracleInstrumentation
jdbc=org.skywalking.apm.plugin.jdbc.define.PostgreSQLInstrumentation
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录