Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
山不在高_有仙则灵
SkyWalking
提交
6c5636f2
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,发现更多精彩内容 >>
提交
6c5636f2
编写于
7月 18, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Shorten the cycle of collecting JVM info. #296
上级
9080b28d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
36 deletion
+28
-36
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java
.../main/java/org/skywalking/apm/agent/core/conf/Config.java
+7
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java
...in/java/org/skywalking/apm/agent/core/jvm/JVMService.java
+21
-36
未找到文件。
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java
浏览文件 @
6c5636f2
...
...
@@ -60,6 +60,13 @@ public class Config {
public
static
String
DISCOVERY_SERVICE_NAME
=
"/grpc/addresses"
;
}
public
static
class
Jvm
{
/**
* The buffer size of collected JVM info.
*/
public
static
int
BUFFER_SIZE
=
60
*
10
;
}
public
static
class
Buffer
{
public
static
int
CHANNEL_SIZE
=
5
;
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java
浏览文件 @
6c5636f2
...
...
@@ -5,11 +5,13 @@ import java.text.SimpleDateFormat;
import
java.util.Date
;
import
java.util.LinkedList
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.ScheduledFuture
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.locks.ReentrantLock
;
import
org.skywalking.apm.agent.core.boot.BootService
;
import
org.skywalking.apm.agent.core.boot.ServiceManager
;
import
org.skywalking.apm.agent.core.conf.Config
;
import
org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig
;
import
org.skywalking.apm.agent.core.dictionary.DictionaryUtil
;
import
org.skywalking.apm.agent.core.jvm.cpu.CPUProvider
;
...
...
@@ -36,16 +38,14 @@ import static org.skywalking.apm.agent.core.remote.GRPCChannelStatus.CONNECTED;
*/
public
class
JVMService
implements
BootService
,
Runnable
{
private
static
final
ILog
logger
=
LogManager
.
getLogger
(
JVMService
.
class
);
private
ReentrantLock
lock
=
new
ReentrantLock
();
private
volatile
LinkedList
<
JVMMetric
>
buffer
=
new
LinkedList
<
JVMMetric
>();
private
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"ss"
);
private
LinkedBlockingQueue
<
JVMMetric
>
queue
;
private
volatile
ScheduledFuture
<?>
collectMetricFuture
;
private
volatile
ScheduledFuture
<?>
sendMetricFuture
;
private
volatile
int
lastBlockIdx
=
-
1
;
private
Sender
sender
;
@Override
public
void
beforeBoot
()
throws
Throwable
{
queue
=
new
LinkedBlockingQueue
(
Config
.
Jvm
.
BUFFER_SIZE
);
sender
=
new
Sender
();
ServiceManager
.
INSTANCE
.
findService
(
GRPCChannelManager
.
class
).
addChannelListener
(
sender
);
}
...
...
@@ -57,7 +57,7 @@ public class JVMService implements BootService, Runnable {
.
scheduleAtFixedRate
(
this
,
0
,
1
,
TimeUnit
.
SECONDS
);
sendMetricFuture
=
Executors
.
newSingleThreadScheduledExecutor
()
.
scheduleAtFixedRate
(
sender
,
0
,
1
5
,
TimeUnit
.
SECONDS
);
.
scheduleAtFixedRate
(
sender
,
0
,
1
,
TimeUnit
.
SECONDS
);
}
@Override
...
...
@@ -71,32 +71,21 @@ public class JVMService implements BootService, Runnable {
&&
RemoteDownstreamConfig
.
Agent
.
APPLICATION_INSTANCE_ID
!=
DictionaryUtil
.
nullValue
()
)
{
long
currentTimeMillis
=
System
.
currentTimeMillis
();
Date
day
=
new
Date
(
currentTimeMillis
);
String
second
=
sdf
.
format
(
day
);
int
blockIndex
=
Integer
.
parseInt
(
second
)
/
15
;
if
(
blockIndex
!=
lastBlockIdx
)
{
lastBlockIdx
=
blockIndex
;
try
{
JVMMetric
.
Builder
jvmBuilder
=
JVMMetric
.
newBuilder
();
jvmBuilder
.
setTime
(
currentTimeMillis
);
jvmBuilder
.
setCpu
(
CPUProvider
.
INSTANCE
.
getCpuMetric
());
jvmBuilder
.
addAllMemory
(
MemoryProvider
.
INSTANCE
.
getMemoryMetricList
());
jvmBuilder
.
addAllMemoryPool
(
MemoryPoolProvider
.
INSTANCE
.
getMemoryPoolMetricList
());
jvmBuilder
.
addAllGc
(
GCProvider
.
INSTANCE
.
getGCList
());
try
{
JVMMetric
.
Builder
jvmBuilder
=
JVMMetric
.
newBuilder
();
jvmBuilder
.
setTime
(
currentTimeMillis
);
jvmBuilder
.
setCpu
(
CPUProvider
.
INSTANCE
.
getCpuMetric
());
jvmBuilder
.
addAllMemory
(
MemoryProvider
.
INSTANCE
.
getMemoryMetricList
());
jvmBuilder
.
addAllMemoryPool
(
MemoryPoolProvider
.
INSTANCE
.
getMemoryPoolMetricList
());
jvmBuilder
.
addAllGc
(
GCProvider
.
INSTANCE
.
getGCList
());
JVMMetric
jvmMetric
=
jvmBuilder
.
build
();
lock
.
lock
();
try
{
buffer
.
add
(
jvmMetric
);
while
(
buffer
.
size
()
>
4
)
{
buffer
.
removeFirst
();
}
}
finally
{
lock
.
unlock
();
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
"Collect JVM info fail."
);
JVMMetric
jvmMetric
=
jvmBuilder
.
build
();
if
(
queue
.
offer
(
jvmMetric
))
{
queue
.
poll
();
queue
.
offer
(
jvmMetric
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
"Collect JVM info fail."
);
}
}
}
...
...
@@ -113,13 +102,9 @@ public class JVMService implements BootService, Runnable {
if
(
status
==
GRPCChannelStatus
.
CONNECTED
)
{
try
{
JVMMetrics
.
Builder
builder
=
JVMMetrics
.
newBuilder
();
lock
.
lock
();
try
{
builder
.
addAllMetrics
(
buffer
);
buffer
.
clear
();
}
finally
{
lock
.
unlock
();
}
LinkedList
<
JVMMetric
>
buffer
=
new
LinkedList
<
JVMMetric
>();
queue
.
drainTo
(
buffer
);
builder
.
addAllMetrics
(
buffer
);
builder
.
setApplicationInstanceId
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_INSTANCE_ID
);
stub
.
collect
(
builder
.
build
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录