-
Notifications
You must be signed in to change notification settings - Fork 737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ISSUE #301] 添加JMX监控采集类型 #390
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3575a4f
[ISSUE #301] add jmx monitor
KamToHung 45cea37
[ISSUE #301] add jmx monitor
KamToHung 04fd51c
[ISSUE #301] rename˚
KamToHung b9fb3e3
[ISSUE #301] remove @ConstructorProperties
KamToHung 2758fdb
[ISSUE #301] remove @Builder
KamToHung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
core/src/main/java/org/dromara/dynamictp/core/monitor/collector/jmx/JMXCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.dromara.dynamictp.core.monitor.collector.jmx; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.dromara.dynamictp.common.em.CollectorTypeEnum; | ||
import org.dromara.dynamictp.common.entity.ThreadPoolStats; | ||
import org.dromara.dynamictp.core.monitor.collector.AbstractCollector; | ||
import org.springframework.beans.BeanUtils; | ||
|
||
import javax.management.JMException; | ||
import javax.management.MBeanServer; | ||
import javax.management.ObjectName; | ||
import java.lang.management.ManagementFactory; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* ThreadPoolStatsInfo related | ||
* | ||
* @author <a href = "mailto:kamtohung@gmail.com">KamTo Hung</a> | ||
*/ | ||
@Slf4j | ||
public class JMXCollector extends AbstractCollector { | ||
|
||
public static final String DTP_METRIC_NAME_PREFIX = "dtp.thread.pool"; | ||
|
||
/** | ||
* thread pool stats map | ||
*/ | ||
private static final Map<String, ThreadPoolStats> GAUGE_CACHE = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public void collect(ThreadPoolStats threadPoolStats) { | ||
if (GAUGE_CACHE.containsKey(threadPoolStats.getPoolName())) { | ||
ThreadPoolStats poolStats = GAUGE_CACHE.get(threadPoolStats.getPoolName()); | ||
BeanUtils.copyProperties(threadPoolStats, poolStats); | ||
} else { | ||
try { | ||
MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | ||
ObjectName name = new ObjectName(DTP_METRIC_NAME_PREFIX + ":name=" + threadPoolStats.getPoolName()); | ||
ThreadPoolStatsJMX stats = new ThreadPoolStatsJMX(threadPoolStats); | ||
server.registerMBean(stats, name); | ||
} catch (JMException e) { | ||
log.error("collect thread pool stats error", e); | ||
} | ||
GAUGE_CACHE.put(threadPoolStats.getPoolName(), threadPoolStats); | ||
} | ||
} | ||
|
||
@Override | ||
public String type() { | ||
return CollectorTypeEnum.JMX.name().toLowerCase(); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
core/src/main/java/org/dromara/dynamictp/core/monitor/collector/jmx/ThreadPoolStatsJMX.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.dromara.dynamictp.core.monitor.collector.jmx; | ||
|
||
import org.dromara.dynamictp.common.entity.ThreadPoolStats; | ||
|
||
import java.beans.ConstructorProperties; | ||
|
||
/** | ||
* @author <a href = "mailto:kamtohung@gmail.com">KamTo Hung</a> | ||
*/ | ||
public class ThreadPoolStatsJMX implements ThreadPoolStatsMXBean { | ||
|
||
private ThreadPoolStats threadPoolStats; | ||
|
||
@ConstructorProperties({"threadPoolStats"}) | ||
public ThreadPoolStatsJMX(ThreadPoolStats threadPoolStats) { | ||
this.threadPoolStats = threadPoolStats; | ||
} | ||
|
||
@Override | ||
public ThreadPoolStats getThreadPoolStats() { | ||
return this.threadPoolStats; | ||
} | ||
|
||
@Override | ||
public void setThreadPoolStats(ThreadPoolStats threadPoolStats) { | ||
this.threadPoolStats = threadPoolStats; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...src/main/java/org/dromara/dynamictp/core/monitor/collector/jmx/ThreadPoolStatsMXBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.dromara.dynamictp.core.monitor.collector.jmx; | ||
|
||
import org.dromara.dynamictp.common.entity.ThreadPoolStats; | ||
|
||
import javax.management.MXBean; | ||
|
||
|
||
/** | ||
* ThreadPoolStatsMXBean related | ||
* | ||
* @author <a href = "mailto:kamtohung@gmail.com">KamTo Hung</a> | ||
*/ | ||
@MXBean | ||
public interface ThreadPoolStatsMXBean { | ||
|
||
/** | ||
* get thread pool stats | ||
* | ||
* @return thread pool stats | ||
*/ | ||
ThreadPoolStats getThreadPoolStats(); | ||
|
||
/** | ||
* set thread pool stats | ||
* | ||
* @param threadPoolStats thread pool stats | ||
*/ | ||
void setThreadPoolStats(ThreadPoolStats threadPoolStats); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里需要构造函数,但是不知道加这两个注解(加了@builder原因)好还是新增一个类复制这些属性好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没看到哪儿需要构造函数呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MXBean 里面成员对象需要构造函数
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
了解了,要不去掉@builder吧,用的地方好像就一处
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK,我改下