Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿信在这里
SkyWalking
提交
a84cb315
S
SkyWalking
项目概览
阿信在这里
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / 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,发现更多精彩内容 >>
提交
a84cb315
编写于
8月 17, 2017
作者:
P
pengys5
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Provide the service that use for get last heart beat time.
#351
上级
b671d634
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
207 addition
and
2 deletion
+207
-2
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IInstanceDAO.java
...ava/org/skywalking/apm/collector/ui/dao/IInstanceDAO.java
+10
-0
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceEsDAO.java
...va/org/skywalking/apm/collector/ui/dao/InstanceEsDAO.java
+63
-0
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceH2DAO.java
...va/org/skywalking/apm/collector/ui/dao/InstanceH2DAO.java
+16
-0
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java
.../ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java
+36
-0
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/InstanceLastTimeGetHandler.java
...tor/ui/jetty/handler/time/InstanceLastTimeGetHandler.java
+46
-0
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/InstanceHealthService.java
...lking/apm/collector/ui/service/InstanceHealthService.java
+8
-0
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/TimeSynchronousService.java
...king/apm/collector/ui/service/TimeSynchronousService.java
+24
-0
apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/es_dao.define
...ctor-ui/src/main/resources/META-INF/defines/es_dao.define
+2
-1
apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/h2_dao.define
...ctor-ui/src/main/resources/META-INF/defines/h2_dao.define
+2
-1
未找到文件。
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IInstanceDAO.java
0 → 100644
浏览文件 @
a84cb315
package
org.skywalking.apm.collector.ui.dao
;
/**
* @author pengys5
*/
public
interface
IInstanceDAO
{
Long
lastHeartBeatTime
();
Long
instanceLastHeartBeatTime
(
long
applicationInstanceId
);
}
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceEsDAO.java
0 → 100644
浏览文件 @
a84cb315
package
org.skywalking.apm.collector.ui.dao
;
import
org.elasticsearch.action.search.SearchRequestBuilder
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.action.search.SearchType
;
import
org.elasticsearch.index.query.AbstractQueryBuilder
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.MatchQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.index.query.RangeQueryBuilder
;
import
org.elasticsearch.search.SearchHit
;
import
org.elasticsearch.search.sort.SortBuilders
;
import
org.elasticsearch.search.sort.SortMode
;
import
org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO
;
import
org.skywalking.apm.collector.storage.table.node.NodeComponentTable
;
import
org.skywalking.apm.collector.storage.table.register.InstanceTable
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author pengys5
*/
public
class
InstanceEsDAO
extends
EsDAO
implements
IInstanceDAO
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
InstanceEsDAO
.
class
);
@Override
public
Long
lastHeartBeatTime
()
{
long
fiveMinuteBefore
=
System
.
currentTimeMillis
()
-
5
*
60
*
1000
;
RangeQueryBuilder
rangeQueryBuilder
=
QueryBuilders
.
rangeQuery
(
InstanceTable
.
COLUMN_HEARTBEAT_TIME
).
gt
(
fiveMinuteBefore
);
return
heartBeatTime
(
rangeQueryBuilder
);
}
@Override
public
Long
instanceLastHeartBeatTime
(
long
applicationInstanceId
)
{
long
fiveMinuteBefore
=
System
.
currentTimeMillis
()
-
5
*
60
*
1000
;
BoolQueryBuilder
boolQueryBuilder
=
new
BoolQueryBuilder
();
RangeQueryBuilder
rangeQueryBuilder
=
QueryBuilders
.
rangeQuery
(
InstanceTable
.
COLUMN_HEARTBEAT_TIME
).
gt
(
fiveMinuteBefore
);
MatchQueryBuilder
matchQueryBuilder
=
QueryBuilders
.
matchQuery
(
InstanceTable
.
COLUMN_INSTANCE_ID
,
applicationInstanceId
);
boolQueryBuilder
.
must
(
rangeQueryBuilder
);
boolQueryBuilder
.
must
(
matchQueryBuilder
);
return
heartBeatTime
(
boolQueryBuilder
);
}
private
Long
heartBeatTime
(
AbstractQueryBuilder
queryBuilder
)
{
SearchRequestBuilder
searchRequestBuilder
=
getClient
().
prepareSearch
(
InstanceTable
.
TABLE
);
searchRequestBuilder
.
setTypes
(
NodeComponentTable
.
TABLE_TYPE
);
searchRequestBuilder
.
setSearchType
(
SearchType
.
DFS_QUERY_THEN_FETCH
);
searchRequestBuilder
.
setQuery
(
queryBuilder
);
searchRequestBuilder
.
setSize
(
1
);
searchRequestBuilder
.
setFetchSource
(
InstanceTable
.
COLUMN_HEARTBEAT_TIME
,
null
);
searchRequestBuilder
.
addSort
(
SortBuilders
.
fieldSort
(
InstanceTable
.
COLUMN_HEARTBEAT_TIME
).
sortMode
(
SortMode
.
MAX
));
SearchResponse
searchResponse
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHit
[]
searchHits
=
searchResponse
.
getHits
().
getHits
();
Long
heartBeatTime
=
0L
;
for
(
SearchHit
searchHit
:
searchHits
)
{
heartBeatTime
=
(
Long
)
searchHit
.
getSource
().
get
(
InstanceTable
.
COLUMN_HEARTBEAT_TIME
);
logger
.
debug
(
"heartBeatTime: {}"
,
heartBeatTime
);
heartBeatTime
=
heartBeatTime
-
5
;
}
return
heartBeatTime
;
}
}
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceH2DAO.java
0 → 100644
浏览文件 @
a84cb315
package
org.skywalking.apm.collector.ui.dao
;
import
org.skywalking.apm.collector.storage.h2.dao.H2DAO
;
/**
* @author pengys5
*/
public
class
InstanceH2DAO
extends
H2DAO
implements
IInstanceDAO
{
@Override
public
Long
lastHeartBeatTime
()
{
return
null
;
}
@Override
public
Long
instanceLastHeartBeatTime
(
long
applicationInstanceId
)
{
return
null
;
}
}
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java
0 → 100644
浏览文件 @
a84cb315
package
org.skywalking.apm.collector.ui.jetty.handler.time
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
javax.servlet.http.HttpServletRequest
;
import
org.skywalking.apm.collector.server.jetty.ArgumentsParseException
;
import
org.skywalking.apm.collector.server.jetty.JettyHandler
;
import
org.skywalking.apm.collector.ui.service.TimeSynchronousService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author pengys5
*/
public
class
AllInstanceLastTimeGetHandler
extends
JettyHandler
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
AllInstanceLastTimeGetHandler
.
class
);
@Override
public
String
pathSpec
()
{
return
"/time/allInstance"
;
}
private
TimeSynchronousService
service
=
new
TimeSynchronousService
();
@Override
protected
JsonElement
doGet
(
HttpServletRequest
req
)
throws
ArgumentsParseException
{
Long
time
=
service
.
allInstanceLastTime
();
logger
.
debug
(
"all instance last time: {}"
,
time
);
JsonObject
timeJson
=
new
JsonObject
();
timeJson
.
addProperty
(
"time"
,
time
);
return
timeJson
;
}
@Override
protected
JsonElement
doPost
(
HttpServletRequest
req
)
throws
ArgumentsParseException
{
throw
new
UnsupportedOperationException
();
}
}
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/time/InstanceLastTimeGetHandler.java
0 → 100644
浏览文件 @
a84cb315
package
org.skywalking.apm.collector.ui.jetty.handler.time
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
javax.servlet.http.HttpServletRequest
;
import
org.skywalking.apm.collector.server.jetty.ArgumentsParseException
;
import
org.skywalking.apm.collector.server.jetty.JettyHandler
;
import
org.skywalking.apm.collector.ui.service.TimeSynchronousService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author pengys5
*/
public
class
InstanceLastTimeGetHandler
extends
JettyHandler
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
InstanceLastTimeGetHandler
.
class
);
@Override
public
String
pathSpec
()
{
return
"/time/instanceId"
;
}
private
TimeSynchronousService
service
=
new
TimeSynchronousService
();
@Override
protected
JsonElement
doGet
(
HttpServletRequest
req
)
throws
ArgumentsParseException
{
String
applicationInstanceIdStr
=
req
.
getParameter
(
"applicationInstanceId"
);
logger
.
debug
(
"applicationInstanceId: {}"
,
applicationInstanceIdStr
);
int
applicationInstanceId
;
try
{
applicationInstanceId
=
Integer
.
parseInt
(
applicationInstanceIdStr
);
}
catch
(
NumberFormatException
e
)
{
throw
new
ArgumentsParseException
(
"application instance id must be integer"
);
}
Long
time
=
service
.
instanceLastTime
(
applicationInstanceId
);
logger
.
debug
(
"application instance id: {}, instance last time: {}"
,
applicationInstanceId
,
time
);
JsonObject
timeJson
=
new
JsonObject
();
timeJson
.
addProperty
(
"time"
,
time
);
return
timeJson
;
}
@Override
protected
JsonElement
doPost
(
HttpServletRequest
req
)
throws
ArgumentsParseException
{
throw
new
UnsupportedOperationException
();
}
}
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/InstanceHealthService.java
0 → 100644
浏览文件 @
a84cb315
package
org.skywalking.apm.collector.ui.service
;
/**
* @author pengys5
*/
public
class
InstanceHealthService
{
}
apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/TimeSynchronousService.java
0 → 100644
浏览文件 @
a84cb315
package
org.skywalking.apm.collector.ui.service
;
import
org.skywalking.apm.collector.storage.dao.DAOContainer
;
import
org.skywalking.apm.collector.ui.dao.IInstanceDAO
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author pengys5
*/
public
class
TimeSynchronousService
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SegmentTopService
.
class
);
public
Long
allInstanceLastTime
()
{
IInstanceDAO
instanceDAO
=
(
IInstanceDAO
)
DAOContainer
.
INSTANCE
.
get
(
IInstanceDAO
.
class
.
getName
());
return
instanceDAO
.
lastHeartBeatTime
();
}
public
Long
instanceLastTime
(
int
applicationInstanceId
)
{
IInstanceDAO
instanceDAO
=
(
IInstanceDAO
)
DAOContainer
.
INSTANCE
.
get
(
IInstanceDAO
.
class
.
getName
());
return
instanceDAO
.
instanceLastHeartBeatTime
(
applicationInstanceId
);
}
}
apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/es_dao.define
浏览文件 @
a84cb315
...
...
@@ -6,4 +6,5 @@ org.skywalking.apm.collector.ui.dao.SegmentCostEsDAO
org.skywalking.apm.collector.ui.dao.GlobalTraceEsDAO
org.skywalking.apm.collector.ui.dao.SegmentEsDAO
org.skywalking.apm.collector.ui.dao.ApplicationEsDAO
org.skywalking.apm.collector.ui.dao.ServiceNameEsDAO
\ No newline at end of file
org.skywalking.apm.collector.ui.dao.ServiceNameEsDAO
org.skywalking.apm.collector.ui.dao.InstanceEsDAO
\ No newline at end of file
apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/h2_dao.define
浏览文件 @
a84cb315
...
...
@@ -6,4 +6,5 @@ org.skywalking.apm.collector.ui.dao.SegmentCostH2DAO
org.skywalking.apm.collector.ui.dao.GlobalTraceH2DAO
org.skywalking.apm.collector.ui.dao.SegmentH2DAO
org.skywalking.apm.collector.ui.dao.ApplicationH2DAO
org.skywalking.apm.collector.ui.dao.ServiceNameH2DAO
\ No newline at end of file
org.skywalking.apm.collector.ui.dao.ServiceNameH2DAO
org.skywalking.apm.collector.ui.dao.InstanceH2DAO
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录