Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
killuaz丶x
SkyWalking
提交
8585e42c
S
SkyWalking
项目概览
killuaz丶x
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
8585e42c
编写于
1月 31, 2018
作者:
P
peng-yongsheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Provide the getCPUTrend query.
上级
86e05bc3
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
66 addition
and
218 deletion
+66
-218
apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java
...skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java
+4
-4
apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java
...lking/apm/collector/storage/dao/IInstanceMetricUIDAO.java
+0
-29
apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/CPUTrend.java
.../skywalking/apm/collector/storage/ui/server/CPUTrend.java
+8
-0
apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java
...alking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java
+16
-24
apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java
...g/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java
+0
-53
apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java
...alking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java
+14
-32
apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java
...g/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java
+1
-62
apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServerQuery.java
...apache/skywalking/apm/collector/ui/query/ServerQuery.java
+4
-2
apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceJVMService.java
...ywalking/apm/collector/ui/service/InstanceJVMService.java
+3
-8
apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServerService.java
...he/skywalking/apm/collector/ui/service/ServerService.java
+16
-4
未找到文件。
apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java
浏览文件 @
8585e42c
...
...
@@ -18,14 +18,14 @@
package
org.apache.skywalking.apm.collector.storage.dao
;
import
com.google.gson.JsonArray
;
import
java.util.List
;
import
org.apache.skywalking.apm.collector.storage.base.dao.DAO
;
import
org.apache.skywalking.apm.collector.storage.ui.common.Step
;
import
org.apache.skywalking.apm.collector.storage.utils.DurationPoint
;
/**
* @author peng-yongsheng
*/
public
interface
ICpuMetricUIDAO
extends
DAO
{
int
getMetric
(
int
instanceId
,
long
timeBucket
);
JsonArray
getMetric
(
int
instanceId
,
long
startTimeBucket
,
long
endTimeBucket
);
List
<
Integer
>
getCPUTrend
(
int
instanceId
,
Step
step
,
List
<
DurationPoint
>
durationPoints
);
}
apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java
浏览文件 @
8585e42c
...
...
@@ -27,37 +27,8 @@ import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
* @author peng-yongsheng
*/
public
interface
IInstanceMetricUIDAO
extends
DAO
{
InstanceMetric
get
(
long
[]
timeBuckets
,
int
instanceId
);
long
getTpsMetric
(
int
instanceId
,
long
timeBucket
);
List
<
Integer
>
getServerTPSTrend
(
int
instanceId
,
Step
step
,
List
<
DurationPoint
>
durationPoints
);
long
getRespTimeMetric
(
int
instanceId
,
long
timeBucket
);
List
<
Integer
>
getResponseTimeTrend
(
int
instanceId
,
Step
step
,
List
<
DurationPoint
>
durationPoints
);
class
InstanceMetric
{
private
final
int
instanceId
;
private
final
long
calls
;
private
final
long
durationSum
;
public
InstanceMetric
(
int
instanceId
,
long
calls
,
long
durationSum
)
{
this
.
instanceId
=
instanceId
;
this
.
calls
=
calls
;
this
.
durationSum
=
durationSum
;
}
public
int
getInstanceId
()
{
return
instanceId
;
}
public
long
getCalls
()
{
return
calls
;
}
public
long
getDurationSum
()
{
return
durationSum
;
}
}
}
apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/CPUTrend.java
浏览文件 @
8585e42c
...
...
@@ -25,4 +25,12 @@ import java.util.List;
*/
public
class
CPUTrend
{
private
List
<
Integer
>
cost
;
public
List
<
Integer
>
getCost
()
{
return
cost
;
}
public
void
setCost
(
List
<
Integer
>
cost
)
{
this
.
cost
=
cost
;
}
}
apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java
浏览文件 @
8585e42c
...
...
@@ -18,13 +18,16 @@
package
org.apache.skywalking.apm.collector.storage.es.dao
;
import
com.google.gson.JsonArray
;
import
java.util.LinkedList
;
import
java.util.List
;
import
org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient
;
import
org.apache.skywalking.apm.collector.core.util.Const
;
import
org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO
;
import
org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO
;
import
org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable
;
import
org.elasticsearch.action.get.GetResponse
;
import
org.apache.skywalking.apm.collector.storage.ui.common.Step
;
import
org.apache.skywalking.apm.collector.storage.utils.DurationPoint
;
import
org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder
;
import
org.elasticsearch.action.get.MultiGetItemResponse
;
import
org.elasticsearch.action.get.MultiGetRequestBuilder
;
import
org.elasticsearch.action.get.MultiGetResponse
;
...
...
@@ -38,37 +41,26 @@ public class CpuMetricEsUIDAO extends EsDAO implements ICpuMetricUIDAO {
super
(
client
);
}
@Override
public
int
getMetric
(
int
instanceId
,
long
timeBucket
)
{
String
id
=
timeBucket
+
Const
.
ID_SPLIT
+
instanceId
;
GetResponse
getResponse
=
getClient
().
prepareGet
(
CpuMetricTable
.
TABLE
,
id
).
get
();
if
(
getResponse
.
isExists
())
{
return
((
Number
)
getResponse
.
getSource
().
get
(
CpuMetricTable
.
COLUMN_USAGE_PERCENT
)).
intValue
();
}
return
0
;
}
@Override
public
JsonArray
getMetric
(
int
instanceId
,
long
startTimeBucket
,
long
endTimeBucket
)
{
@Override
public
List
<
Integer
>
getCPUTrend
(
int
instanceId
,
Step
step
,
List
<
DurationPoint
>
durationPoints
)
{
MultiGetRequestBuilder
prepareMultiGet
=
getClient
().
prepareMultiGet
();
String
tableName
=
TimePyramidTableNameBuilder
.
build
(
step
,
CpuMetricTable
.
TABLE
);
long
timeBucket
=
startTimeBucket
;
do
{
// timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND, timeBucket, 1);
String
id
=
timeBucket
+
Const
.
ID_SPLIT
+
instanceId
;
prepareMultiGet
.
add
(
CpuMetricTable
.
TABLE
,
CpuMetricTable
.
TABLE_TYPE
,
id
);
}
while
(
timeBucket
<=
endTimeBucket
);
durationPoints
.
forEach
(
durationPoint
->
{
String
id
=
durationPoint
.
getPoint
()
+
Const
.
ID_SPLIT
+
instanceId
;
prepareMultiGet
.
add
(
tableName
,
CpuMetricTable
.
TABLE_TYPE
,
id
);
});
JsonArray
metrics
=
new
JsonArray
();
List
<
Integer
>
cpuTrends
=
new
LinkedList
<>
();
MultiGetResponse
multiGetResponse
=
prepareMultiGet
.
get
();
for
(
MultiGetItemResponse
response
:
multiGetResponse
.
getResponses
())
{
if
(
response
.
getResponse
().
isExists
())
{
double
cpuUsed
=
((
Number
)
response
.
getResponse
().
getSource
().
get
(
CpuMetricTable
.
COLUMN_USAGE_PERCENT
)).
doubleValue
();
metrics
.
add
((
int
)(
cpuUsed
*
100
));
long
times
=
((
Number
)
response
.
getResponse
().
getSource
().
get
(
CpuMetricTable
.
COLUMN_TIMES
)).
longValue
();
cpuTrends
.
add
((
int
)((
cpuUsed
/
times
)
*
100
));
}
else
{
metric
s
.
add
(
0
);
cpuTrend
s
.
add
(
0
);
}
}
return
metric
s
;
return
cpuTrend
s
;
}
}
apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java
浏览文件 @
8585e42c
...
...
@@ -29,18 +29,9 @@ import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetric
import
org.apache.skywalking.apm.collector.storage.ui.common.Step
;
import
org.apache.skywalking.apm.collector.storage.utils.DurationPoint
;
import
org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder
;
import
org.elasticsearch.action.get.GetResponse
;
import
org.elasticsearch.action.get.MultiGetItemResponse
;
import
org.elasticsearch.action.get.MultiGetRequestBuilder
;
import
org.elasticsearch.action.get.MultiGetResponse
;
import
org.elasticsearch.action.search.SearchRequestBuilder
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.action.search.SearchType
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.search.aggregations.AggregationBuilders
;
import
org.elasticsearch.search.aggregations.metrics.sum.Sum
;
import
org.elasticsearch.search.sort.SortOrder
;
/**
* @author peng-yongsheng
...
...
@@ -51,38 +42,6 @@ public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO
super
(
client
);
}
@Override
public
InstanceMetric
get
(
long
[]
timeBuckets
,
int
instanceId
)
{
SearchRequestBuilder
searchRequestBuilder
=
getClient
().
prepareSearch
(
InstanceMetricTable
.
TABLE
);
searchRequestBuilder
.
setTypes
(
InstanceMetricTable
.
TABLE_TYPE
);
searchRequestBuilder
.
setSearchType
(
SearchType
.
DFS_QUERY_THEN_FETCH
);
BoolQueryBuilder
boolQuery
=
QueryBuilders
.
boolQuery
();
boolQuery
.
must
().
add
(
QueryBuilders
.
termQuery
(
InstanceMetricTable
.
COLUMN_INSTANCE_ID
,
instanceId
));
boolQuery
.
must
().
add
(
QueryBuilders
.
termsQuery
(
InstanceMetricTable
.
COLUMN_TIME_BUCKET
,
timeBuckets
));
searchRequestBuilder
.
setQuery
(
boolQuery
);
searchRequestBuilder
.
setSize
(
0
);
searchRequestBuilder
.
addSort
(
InstanceMetricTable
.
COLUMN_INSTANCE_ID
,
SortOrder
.
ASC
);
searchRequestBuilder
.
addAggregation
(
AggregationBuilders
.
sum
(
InstanceMetricTable
.
COLUMN_TRANSACTION_CALLS
).
field
(
InstanceMetricTable
.
COLUMN_TRANSACTION_CALLS
));
searchRequestBuilder
.
addAggregation
(
AggregationBuilders
.
sum
(
InstanceMetricTable
.
COLUMN_TRANSACTION_DURATION_SUM
).
field
(
InstanceMetricTable
.
COLUMN_TRANSACTION_DURATION_SUM
));
SearchResponse
searchResponse
=
searchRequestBuilder
.
execute
().
actionGet
();
Sum
sumCalls
=
searchResponse
.
getAggregations
().
get
(
InstanceMetricTable
.
COLUMN_TRANSACTION_CALLS
);
Sum
sumCostTotal
=
searchResponse
.
getAggregations
().
get
(
InstanceMetricTable
.
COLUMN_TRANSACTION_DURATION_SUM
);
return
new
InstanceMetric
(
instanceId
,
(
long
)
sumCalls
.
getValue
(),
(
long
)
sumCostTotal
.
getValue
());
}
@Override
public
long
getTpsMetric
(
int
instanceId
,
long
timeBucket
)
{
String
id
=
timeBucket
+
Const
.
ID_SPLIT
+
instanceId
;
GetResponse
getResponse
=
getClient
().
prepareGet
(
InstanceMetricTable
.
TABLE
,
id
).
get
();
if
(
getResponse
.
isExists
())
{
return
((
Number
)
getResponse
.
getSource
().
get
(
InstanceMetricTable
.
COLUMN_TRANSACTION_CALLS
)).
longValue
();
}
return
0
;
}
@Override
public
List
<
Integer
>
getServerTPSTrend
(
int
instanceId
,
Step
step
,
List
<
DurationPoint
>
durationPoints
)
{
MultiGetRequestBuilder
prepareMultiGet
=
getClient
().
prepareMultiGet
();
String
tableName
=
TimePyramidTableNameBuilder
.
build
(
step
,
InstanceMetricTable
.
TABLE
);
...
...
@@ -107,18 +66,6 @@ public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO
return
throughputTrend
;
}
@Override
public
long
getRespTimeMetric
(
int
instanceId
,
long
timeBucket
)
{
String
id
=
timeBucket
+
Const
.
ID_SPLIT
+
instanceId
;
GetResponse
getResponse
=
getClient
().
prepareGet
(
InstanceMetricTable
.
TABLE
,
id
).
get
();
if
(
getResponse
.
isExists
())
{
long
callTimes
=
((
Number
)
getResponse
.
getSource
().
get
(
InstanceMetricTable
.
COLUMN_TRANSACTION_CALLS
)).
longValue
();
long
costTotal
=
((
Number
)
getResponse
.
getSource
().
get
(
InstanceMetricTable
.
COLUMN_TRANSACTION_DURATION_SUM
)).
longValue
();
return
costTotal
/
callTimes
;
}
return
0
;
}
@Override
public
List
<
Integer
>
getResponseTimeTrend
(
int
instanceId
,
Step
step
,
List
<
DurationPoint
>
durationPoints
)
{
MultiGetRequestBuilder
prepareMultiGet
=
getClient
().
prepareMultiGet
();
String
tableName
=
TimePyramidTableNameBuilder
.
build
(
step
,
InstanceMetricTable
.
TABLE
);
...
...
apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java
浏览文件 @
8585e42c
...
...
@@ -18,10 +18,9 @@
package
org.apache.skywalking.apm.collector.storage.h2.dao
;
import
com.google.gson.JsonArray
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.util.
Array
List
;
import
java.util.
Linked
List
;
import
java.util.List
;
import
org.apache.skywalking.apm.collector.client.h2.H2Client
;
import
org.apache.skywalking.apm.collector.client.h2.H2ClientException
;
...
...
@@ -30,6 +29,9 @@ import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import
org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO
;
import
org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO
;
import
org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable
;
import
org.apache.skywalking.apm.collector.storage.ui.common.Step
;
import
org.apache.skywalking.apm.collector.storage.utils.DurationPoint
;
import
org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -44,48 +46,28 @@ public class CpuMetricH2UIDAO extends H2DAO implements ICpuMetricUIDAO {
super
(
client
);
}
@Override
public
int
getMetric
(
int
instanceId
,
long
timeBucket
)
{
String
id
=
timeBucket
+
Const
.
ID_SPLIT
+
instanceId
;
@Override
public
List
<
Integer
>
getCPUTrend
(
int
instanceId
,
Step
step
,
List
<
DurationPoint
>
durationPoints
)
{
H2Client
client
=
getClient
();
String
sql
=
SqlBuilder
.
buildSql
(
GET_CPU_METRIC_SQL
,
CpuMetricTable
.
TABLE
,
CpuMetricTable
.
COLUMN_ID
);
Object
[]
params
=
new
Object
[]
{
id
};
try
(
ResultSet
rs
=
client
.
executeQuery
(
sql
,
params
))
{
if
(
rs
.
next
())
{
return
rs
.
getInt
(
CpuMetricTable
.
COLUMN_USAGE_PERCENT
);
}
}
catch
(
SQLException
|
H2ClientException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
return
0
;
}
@Override
public
JsonArray
getMetric
(
int
instanceId
,
long
startTimeBucket
,
long
endTimeBucket
)
{
H2Client
client
=
getClient
();
String
sql
=
SqlBuilder
.
buildSql
(
GET_CPU_METRIC_SQL
,
CpuMetricTable
.
TABLE
,
CpuMetricTable
.
COLUMN_ID
);
String
tableName
=
TimePyramidTableNameBuilder
.
build
(
step
,
CpuMetricTable
.
TABLE
);
String
sql
=
SqlBuilder
.
buildSql
(
GET_CPU_METRIC_SQL
,
tableName
,
CpuMetricTable
.
COLUMN_ID
);
long
timeBucket
=
startTimeBucket
;
List
<
String
>
idList
=
new
ArrayList
<>();
do
{
// timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND, timeBucket, 1);
String
id
=
timeBucket
+
Const
.
ID_SPLIT
+
instanceId
;
idList
.
add
(
id
);
}
while
(
timeBucket
<=
endTimeBucket
);
List
<
Integer
>
cpuTrends
=
new
LinkedList
<>();
durationPoints
.
forEach
(
durationPoint
->
{
String
id
=
durationPoint
.
getPoint
()
+
Const
.
ID_SPLIT
+
instanceId
;
JsonArray
metrics
=
new
JsonArray
();
idList
.
forEach
(
id
->
{
try
(
ResultSet
rs
=
client
.
executeQuery
(
sql
,
new
String
[]
{
id
}))
{
if
(
rs
.
next
())
{
double
cpuUsed
=
rs
.
getDouble
(
CpuMetricTable
.
COLUMN_USAGE_PERCENT
);
metrics
.
add
((
int
)(
cpuUsed
*
100
));
long
times
=
rs
.
getLong
(
CpuMetricTable
.
COLUMN_TIMES
);
cpuTrends
.
add
((
int
)((
cpuUsed
/
times
)
*
100
));
}
else
{
metric
s
.
add
(
0
);
cpuTrend
s
.
add
(
0
);
}
}
catch
(
SQLException
|
H2ClientException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
});
return
metric
s
;
return
cpuTrend
s
;
}
}
apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java
浏览文件 @
8585e42c
...
...
@@ -42,58 +42,13 @@ import org.slf4j.LoggerFactory;
public
class
InstanceMetricH2UIDAO
extends
H2DAO
implements
IInstanceMetricUIDAO
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
InstanceMetricH2UIDAO
.
class
);
private
static
final
String
GET_INSTANCE_METRIC_SQL
=
"select * from {0} where {1} = ? and {2} in ("
;
private
static
final
String
GET_TPS_METRIC_SQL
=
"select * from {0} where {1} = ?"
;
public
InstanceMetricH2UIDAO
(
H2Client
client
)
{
super
(
client
);
}
@Override
public
InstanceMetric
get
(
long
[]
timeBuckets
,
int
instanceId
)
{
H2Client
client
=
getClient
();
logger
.
info
(
"the inst performance inst id = {}"
,
instanceId
);
String
sql
=
SqlBuilder
.
buildSql
(
GET_INSTANCE_METRIC_SQL
,
InstanceMetricTable
.
TABLE
,
InstanceMetricTable
.
COLUMN_INSTANCE_ID
,
InstanceMetricTable
.
COLUMN_TIME_BUCKET
);
StringBuilder
builder
=
new
StringBuilder
();
for
(
long
timeBucket
:
timeBuckets
)
{
builder
.
append
(
"?,"
);
}
builder
.
delete
(
builder
.
length
()
-
1
,
builder
.
length
());
builder
.
append
(
")"
);
sql
=
sql
+
builder
;
Object
[]
params
=
new
Object
[
timeBuckets
.
length
+
1
];
for
(
int
i
=
0
;
i
<
timeBuckets
.
length
;
i
++)
{
params
[
i
+
1
]
=
timeBuckets
[
i
];
}
params
[
0
]
=
instanceId
;
try
(
ResultSet
rs
=
client
.
executeQuery
(
sql
,
params
))
{
if
(
rs
.
next
())
{
long
callTimes
=
rs
.
getInt
(
InstanceMetricTable
.
COLUMN_TRANSACTION_CALLS
);
long
costTotal
=
rs
.
getInt
(
InstanceMetricTable
.
COLUMN_TRANSACTION_DURATION_SUM
);
return
new
InstanceMetric
(
instanceId
,
callTimes
,
costTotal
);
}
}
catch
(
SQLException
|
H2ClientException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
return
null
;
}
@Override
public
long
getTpsMetric
(
int
instanceId
,
long
timeBucket
)
{
logger
.
info
(
"getTpMetric instanceId = {}, startTimeBucket = {}"
,
instanceId
,
timeBucket
);
H2Client
client
=
getClient
();
String
sql
=
SqlBuilder
.
buildSql
(
GET_TPS_METRIC_SQL
,
InstanceMetricTable
.
TABLE
,
InstanceMetricTable
.
COLUMN_ID
);
Object
[]
params
=
new
Object
[]
{
instanceId
};
try
(
ResultSet
rs
=
client
.
executeQuery
(
sql
,
params
))
{
if
(
rs
.
next
())
{
return
rs
.
getLong
(
InstanceMetricTable
.
COLUMN_TRANSACTION_CALLS
);
}
}
catch
(
SQLException
|
H2ClientException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
return
0
;
}
@Override
public
List
<
Integer
>
getServerTPSTrend
(
int
instanceId
,
Step
step
,
List
<
DurationPoint
>
durationPoints
)
{
@Override
public
List
<
Integer
>
getServerTPSTrend
(
int
instanceId
,
Step
step
,
List
<
DurationPoint
>
durationPoints
)
{
H2Client
client
=
getClient
();
String
tableName
=
TimePyramidTableNameBuilder
.
build
(
step
,
InstanceMetricTable
.
TABLE
);
...
...
@@ -117,22 +72,6 @@ public class InstanceMetricH2UIDAO extends H2DAO implements IInstanceMetricUIDAO
return
throughputTrend
;
}
@Override
public
long
getRespTimeMetric
(
int
instanceId
,
long
timeBucket
)
{
H2Client
client
=
getClient
();
String
sql
=
SqlBuilder
.
buildSql
(
GET_TPS_METRIC_SQL
,
InstanceMetricTable
.
TABLE
,
InstanceMetricTable
.
COLUMN_ID
);
Object
[]
params
=
new
Object
[]
{
instanceId
};
try
(
ResultSet
rs
=
client
.
executeQuery
(
sql
,
params
))
{
if
(
rs
.
next
())
{
long
callTimes
=
rs
.
getLong
(
InstanceMetricTable
.
COLUMN_TRANSACTION_CALLS
);
long
costTotal
=
rs
.
getLong
(
InstanceMetricTable
.
COLUMN_TRANSACTION_DURATION_SUM
);
return
costTotal
/
callTimes
;
}
}
catch
(
SQLException
|
H2ClientException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
return
0
;
}
@Override
public
List
<
Integer
>
getResponseTimeTrend
(
int
instanceId
,
Step
step
,
List
<
DurationPoint
>
durationPoints
)
{
H2Client
client
=
getClient
();
...
...
apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServerQuery.java
浏览文件 @
8585e42c
...
...
@@ -76,8 +76,10 @@ public class ServerQuery implements Query {
return
getServerService
().
getServerTPSTrend
(
serverId
,
duration
.
getStep
(),
start
,
end
);
}
public
CPUTrend
getCPUTrend
(
int
serverId
,
Duration
duration
)
{
return
null
;
public
CPUTrend
getCPUTrend
(
int
serverId
,
Duration
duration
)
throws
ParseException
{
long
start
=
DurationUtils
.
INSTANCE
.
exchangeToTimeBucket
(
duration
.
getStart
());
long
end
=
DurationUtils
.
INSTANCE
.
exchangeToTimeBucket
(
duration
.
getEnd
());
return
getServerService
().
getCPUTrend
(
serverId
,
duration
.
getStep
(),
start
,
end
);
}
public
GCTrend
getGCTrend
(
int
serverId
,
Duration
duration
)
{
...
...
apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceJVMService.java
浏览文件 @
8585e42c
...
...
@@ -16,7 +16,6 @@
*
*/
package
org.apache.skywalking.apm.collector.ui.service
;
import
com.google.gson.Gson
;
...
...
@@ -25,14 +24,14 @@ import java.util.Set;
import
org.apache.skywalking.apm.collector.core.UnexpectedException
;
import
org.apache.skywalking.apm.collector.core.module.ModuleManager
;
import
org.apache.skywalking.apm.collector.core.util.ObjectUtils
;
import
org.apache.skywalking.apm.collector.storage.StorageModule
;
import
org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO
;
import
org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO
;
import
org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO
;
import
org.apache.skywalking.apm.collector.storage.table.register.Instance
;
import
org.apache.skywalking.apm.collector.storage.StorageModule
;
import
org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO
;
import
org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO
;
import
org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO
;
import
org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO
;
import
org.apache.skywalking.apm.collector.storage.table.register.Instance
;
import
org.apache.skywalking.apm.network.proto.PoolType
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -75,13 +74,10 @@ public class InstanceJVMService {
JsonObject
metrics
=
new
JsonObject
();
for
(
String
metricType
:
metricTypes
)
{
if
(
metricType
.
toLowerCase
().
equals
(
MetricType
.
cpu
.
name
()))
{
metrics
.
addProperty
(
MetricType
.
cpu
.
name
(),
cpuMetricDAO
.
getMetric
(
instanceId
,
timeBucket
));
}
else
if
(
metricType
.
toLowerCase
().
equals
(
MetricType
.
gc
.
name
()))
{
metrics
.
add
(
MetricType
.
gc
.
name
(),
gcMetricDAO
.
getMetric
(
instanceId
,
timeBucket
));
}
else
if
(
metricType
.
toLowerCase
().
equals
(
MetricType
.
tps
.
name
()))
{
metrics
.
addProperty
(
MetricType
.
tps
.
name
(),
instanceMetricUIDAO
.
getTpsMetric
(
instanceId
,
timeBucket
));
}
else
if
(
metricType
.
toLowerCase
().
equals
(
MetricType
.
resptime
.
name
()))
{
metrics
.
addProperty
(
MetricType
.
resptime
.
name
(),
instanceMetricUIDAO
.
getRespTimeMetric
(
instanceId
,
timeBucket
));
}
else
if
(
metricType
.
toLowerCase
().
equals
(
MetricType
.
heapmemory
.
name
()))
{
metrics
.
add
(
MetricType
.
heapmemory
.
name
(),
memoryMetricDAO
.
getMetric
(
instanceId
,
timeBucket
,
true
));
}
else
if
(
metricType
.
toLowerCase
().
equals
(
MetricType
.
nonheapmemory
.
name
()))
{
...
...
@@ -108,7 +104,6 @@ public class InstanceJVMService {
JsonObject
metrics
=
new
JsonObject
();
for
(
String
metricType
:
metricTypes
)
{
if
(
metricType
.
toLowerCase
().
equals
(
MetricType
.
cpu
.
name
()))
{
metrics
.
add
(
MetricType
.
cpu
.
name
(),
cpuMetricDAO
.
getMetric
(
instanceId
,
startTimeBucket
,
endTimeBucket
));
}
else
if
(
metricType
.
toLowerCase
().
equals
(
MetricType
.
gc
.
name
()))
{
metrics
.
add
(
MetricType
.
gc
.
name
(),
gcMetricDAO
.
getMetric
(
instanceId
,
startTimeBucket
,
endTimeBucket
));
}
else
if
(
metricType
.
toLowerCase
().
equals
(
MetricType
.
tps
.
name
()))
{
...
...
apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServerService.java
浏览文件 @
8585e42c
...
...
@@ -28,12 +28,14 @@ import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import
org.apache.skywalking.apm.collector.core.util.Const
;
import
org.apache.skywalking.apm.collector.core.util.StringUtils
;
import
org.apache.skywalking.apm.collector.storage.StorageModule
;
import
org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO
;
import
org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO
;
import
org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO
;
import
org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend
;
import
org.apache.skywalking.apm.collector.storage.ui.common.Step
;
import
org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend
;
import
org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo
;
import
org.apache.skywalking.apm.collector.storage.ui.server.CPUTrend
;
import
org.apache.skywalking.apm.collector.storage.utils.DurationPoint
;
import
org.apache.skywalking.apm.collector.ui.utils.DurationUtils
;
...
...
@@ -43,16 +45,18 @@ import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
public
class
ServerService
{
private
final
Gson
gson
=
new
Gson
();
private
final
IInstanceUIDAO
instanceDAO
;
private
final
IInstanceUIDAO
instanceUIDAO
;
private
final
ICpuMetricUIDAO
cpuMetricUIDAO
;
private
final
IInstanceMetricUIDAO
instanceMetricUIDAO
;
public
ServerService
(
ModuleManager
moduleManager
)
{
this
.
instanceDAO
=
moduleManager
.
find
(
StorageModule
.
NAME
).
getService
(
IInstanceUIDAO
.
class
);
this
.
instanceUIDAO
=
moduleManager
.
find
(
StorageModule
.
NAME
).
getService
(
IInstanceUIDAO
.
class
);
this
.
cpuMetricUIDAO
=
moduleManager
.
find
(
StorageModule
.
NAME
).
getService
(
ICpuMetricUIDAO
.
class
);
this
.
instanceMetricUIDAO
=
moduleManager
.
find
(
StorageModule
.
NAME
).
getService
(
IInstanceMetricUIDAO
.
class
);
}
public
List
<
AppServerInfo
>
searchServer
(
String
keyword
,
long
start
,
long
end
)
{
List
<
AppServerInfo
>
serverInfos
=
instanceDAO
.
searchServer
(
keyword
,
start
,
end
);
List
<
AppServerInfo
>
serverInfos
=
instance
UI
DAO
.
searchServer
(
keyword
,
start
,
end
);
serverInfos
.
forEach
(
serverInfo
->
{
if
(
serverInfo
.
getId
()
==
Const
.
NONE_INSTANCE_ID
)
{
serverInfos
.
remove
(
serverInfo
);
...
...
@@ -64,7 +68,7 @@ public class ServerService {
}
public
List
<
AppServerInfo
>
getAllServer
(
int
applicationId
,
long
start
,
long
end
)
{
List
<
AppServerInfo
>
serverInfos
=
instanceDAO
.
getAllServer
(
applicationId
,
start
,
end
);
List
<
AppServerInfo
>
serverInfos
=
instance
UI
DAO
.
getAllServer
(
applicationId
,
start
,
end
);
buildAppServerInfo
(
serverInfos
);
return
serverInfos
;
}
...
...
@@ -86,6 +90,14 @@ public class ServerService {
return
throughputTrend
;
}
public
CPUTrend
getCPUTrend
(
int
instanceId
,
Step
step
,
long
start
,
long
end
)
throws
ParseException
{
CPUTrend
cpuTrend
=
new
CPUTrend
();
List
<
DurationPoint
>
durationPoints
=
DurationUtils
.
INSTANCE
.
getDurationPoints
(
step
,
start
,
end
);
List
<
Integer
>
trends
=
cpuMetricUIDAO
.
getCPUTrend
(
instanceId
,
step
,
durationPoints
);
cpuTrend
.
setCost
(
trends
);
return
cpuTrend
;
}
private
void
buildAppServerInfo
(
List
<
AppServerInfo
>
serverInfos
)
{
serverInfos
.
forEach
(
serverInfo
->
{
if
(
StringUtils
.
isNotEmpty
(
serverInfo
.
getOsInfo
()))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录