本文整理汇总了Java中java.lang.management.ManagementFactory.getPlatformMXBeans方法的典型用法代码示例。如果您正苦于以下问题:Java ManagementFactory.getPlatformMXBeans方法的具体用法?Java ManagementFactory.getPlatformMXBeans怎么用?Java ManagementFactory.getPlatformMXBeans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.management.ManagementFactory
的用法示例。
在下文中一共展示了ManagementFactory.getPlatformMXBeans方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sense
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
public void sense(final MetricRecorder.Context metricContext)
{
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for (BufferPoolMXBean mxBean : pools) {
//TODO: something else?
String name = mxBean.getName();
Metric countMetric = Metric.define("BufferPoolCount_"+name);
Metric usedMetric = Metric.define("BufferPoolUsed_"+name);
Metric maxMetric = Metric.define("BufferPoolMax_"+name);
metricContext.record(countMetric, mxBean.getCount(), Unit.NONE);
metricContext.record(usedMetric, mxBean.getMemoryUsed() / M, Unit.MEGABYTE);
metricContext.record(maxMetric, mxBean.getTotalCapacity() / M, Unit.MEGABYTE);
}
}
示例2: testByteBufferMXBeanMethods
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public void testByteBufferMXBeanMethods() {
List<BufferPoolMXBean> byteBufferPools =
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for (int counter = 0; counter < 10; counter++) {
for (BufferPoolMXBean bean: byteBufferPools) {
// Name should not be blank or null
assertNotNull ("MXBean name is null", bean.getName());
assertFalse ("MXBean name is blank", bean.getName().equalsIgnoreCase(""));
// Total capacity should not be negative
assertTrue (bean.getName() + "'s total capacity was not greater than zero", bean.getTotalCapacity() >= 0);
// Likewise memoryUsed
assertTrue (bean.getName() + "'s memory used was not greater than zero", bean.getMemoryUsed() >= 0);
assertTrue (bean.getName() + "'s object name is null or blank",
bean.getObjectName() != null && bean.getObjectName().toString() != "");
}
}
}
示例3: heartbeat
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
protected void heartbeat() {
// Let them know we are alive
// Print some stats about the ByteBuffers
List<BufferPoolMXBean> byteBufferPools =
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
String direct = "direct";
String mapped = "mapped";
for (BufferPoolMXBean bean: byteBufferPools) {
if (bean.getName().equalsIgnoreCase(direct)) {
direct += " - " + bean.getMemoryUsed() + "/" + bean.getTotalCapacity();
}
if (bean.getName().equalsIgnoreCase(mapped)) {
mapped += " - " + bean.getMemoryUsed() + "/" + bean.getTotalCapacity();
}
}
logMessage(direct + " , " + mapped);
logMessage("Currently connected clients: " + getConnectedClients().size());
logMessage("Total bytes received : " + bytesReceived);
logMessage("Total clients connected : " + clientsConnected);
logMessage("Total clients disconnected : " + clientsDisconnected);
synchronized (connectionsPerSecond) {
if (!connectionsPerSecond.isEmpty()) {
logMessage("CPS Max: " + Collections.max(connectionsPerSecond.values()) );
}
}
synchronized (connectionsPerMinute) {
if (!connectionsPerMinute.isEmpty()) {
logMessage("CPM Max: " + Collections.max(connectionsPerMinute.values()) );
}
}
logMessage();
}
示例4: getDirectBean
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private BufferPoolMXBean getDirectBean() {
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for (BufferPoolMXBean b : pools) {
if (b.getName().equals("direct")) {
return b;
}
}
throw new IllegalStateException("Unable to find direct buffer bean. JVM must be too old.");
}
示例5: SystemManager
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public SystemManager(){
memoryBean = ManagementFactory.getMemoryMXBean();
BufferPoolMXBean localBean = null;
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for(BufferPoolMXBean b : pools){
if(b.getName().equals("direct")){
localBean = b;
}
}
directBean = localBean;
}
示例6: getDirectPool
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private static BufferPoolMXBean getDirectPool() {
final List<BufferPoolMXBean> pools =
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for (BufferPoolMXBean pool : pools) {
if (pool.getName().equals("direct")) {
return pool;
}
}
throw new Error("could not find direct pool");
}
示例7: main
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
List<HotSpotDiagnosticMXBean> list =
ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
HotSpotDiagnosticMXBean mbean = list.get(0);
checkDiagnosticOptions(mbean);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
HotSpotDiagnosticMXBean.class);
checkDiagnosticOptions(mbean);
}
示例8: main
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
List<HotSpotDiagnosticMXBean> list =
ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
HotSpotDiagnosticMXBean mbean = list.get(0);
checkVMOption(mbean);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
HotSpotDiagnosticMXBean.class);
checkVMOption(mbean);
}
示例9: main
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
List<HotSpotDiagnosticMXBean> list =
ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
HotSpotDiagnosticMXBean mbean = list.get(0);
setAllVMOptions(mbean);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
HotSpotDiagnosticMXBean.class);
setAllVMOptions(mbean);
}
示例10: getDirectBean
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
* @return Direct buffer JMX bean
*/
public static BufferPoolMXBean getDirectBean() {
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for (BufferPoolMXBean b : pools) {
if (b.getName().equals("direct")) {
return b;
}
}
throw new IllegalStateException("Unable to find direct buffer bean. JVM must be too old.");
}
示例11: jvmStats
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static JvmStats jvmStats() {
MemoryUsage memUsage = memoryMXBean.getHeapMemoryUsage();
long heapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
long heapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
long heapMax = memUsage.getMax() < 0 ? 0 : memUsage.getMax();
memUsage = memoryMXBean.getNonHeapMemoryUsage();
long nonHeapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
long nonHeapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
List<MemoryPool> pools = new ArrayList<>();
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
try {
MemoryUsage usage = memoryPoolMXBean.getUsage();
MemoryUsage peakUsage = memoryPoolMXBean.getPeakUsage();
String name = GcNames.getByMemoryPoolName(memoryPoolMXBean.getName(), null);
if (name == null) { // if we can't resolve it, its not interesting.... (Per Gen, Code Cache)
continue;
}
pools.add(new MemoryPool(name,
usage.getUsed() < 0 ? 0 : usage.getUsed(),
usage.getMax() < 0 ? 0 : usage.getMax(),
peakUsage.getUsed() < 0 ? 0 : peakUsage.getUsed(),
peakUsage.getMax() < 0 ? 0 : peakUsage.getMax()
));
} catch (Exception ex) {
/* ignore some JVMs might barf here with:
* java.lang.InternalError: Memory Pool not found
* we just omit the pool in that case!*/
}
}
Mem mem = new Mem(heapCommitted, heapUsed, heapMax, nonHeapCommitted, nonHeapUsed, Collections.unmodifiableList(pools));
Threads threads = new Threads(threadMXBean.getThreadCount(), threadMXBean.getPeakThreadCount());
List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
GarbageCollector[] collectors = new GarbageCollector[gcMxBeans.size()];
for (int i = 0; i < collectors.length; i++) {
GarbageCollectorMXBean gcMxBean = gcMxBeans.get(i);
collectors[i] = new GarbageCollector(GcNames.getByGcName(gcMxBean.getName(), gcMxBean.getName()),
gcMxBean.getCollectionCount(), gcMxBean.getCollectionTime());
}
GarbageCollectors garbageCollectors = new GarbageCollectors(collectors);
List<BufferPool> bufferPoolsList = Collections.emptyList();
try {
List<BufferPoolMXBean> bufferPools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
bufferPoolsList = new ArrayList<>(bufferPools.size());
for (BufferPoolMXBean bufferPool : bufferPools) {
bufferPoolsList.add(new BufferPool(bufferPool.getName(), bufferPool.getCount(),
bufferPool.getTotalCapacity(), bufferPool.getMemoryUsed()));
}
} catch (Exception e) {
// buffer pools are not available
}
Classes classes = new Classes(classLoadingMXBean.getLoadedClassCount(), classLoadingMXBean.getTotalLoadedClassCount(),
classLoadingMXBean.getUnloadedClassCount());
return new JvmStats(System.currentTimeMillis(), runtimeMXBean.getUptime(), mem, threads,
garbageCollectors, bufferPoolsList, classes);
}
示例12: main
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Random rand = new Random();
// allocate a few direct buffers
int bufferCount = 5 + rand.nextInt(20);
buffers = new ArrayList<ByteBuffer>(bufferCount);
long totalCapacity = 0L;
for (int i=0; i<bufferCount; i++) {
int cap = 1024 + rand.nextInt(4096);
buffers.add( ByteBuffer.allocateDirect(cap) );
totalCapacity += cap;
}
// create a mapped buffer
Path tmpfile = Files.createTempFile("blah", null);
tmpfile.toFile().deleteOnExit();
try (FileChannel fc = FileChannel.open(tmpfile, READ, WRITE)) {
mbb = fc.map(FileChannel.MapMode.READ_WRITE, 10, 100);
bufferCount++;
totalCapacity += mbb.capacity();
}
// use platform MXBeans directly
List<BufferPoolMXBean> pools =
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
check(pools, bufferCount, totalCapacity);
// use MBeanServer
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> mbeans = server.queryNames(
new ObjectName("java.nio:type=BufferPool,*"), null);
pools = new ArrayList<BufferPoolMXBean>();
for (ObjectName name: mbeans) {
BufferPoolMXBean pool = ManagementFactory
.newPlatformMXBeanProxy(server, name.toString(), BufferPoolMXBean.class);
pools.add(pool);
}
check(pools, bufferCount, totalCapacity);
// attempt to unmap mapped buffer
WeakReference<MappedByteBuffer> ref = new WeakReference<>(mbb);
mbb = null;
do {
System.gc();
Thread.sleep(250);
} while (ref.get() != null);
}
示例13: testGetPlatformMXBeans
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public void testGetPlatformMXBeans() {
// BufferPoolMXBean
List<BufferPoolMXBean> byteBufferPools =
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
assertTrue("No BufferPoolMXBeans returned", byteBufferPools.size() > 0);
// ThreadMXBean
List<ThreadMXBean> threadMXBeans =
ManagementFactory.getPlatformMXBeans(ThreadMXBean.class);
assertTrue("No ThreadMXBeans returned", threadMXBeans.size() > 0);
// ClassLoadingMXBean
List<ClassLoadingMXBean> classloadingMXBeans =
ManagementFactory.getPlatformMXBeans(ClassLoadingMXBean.class);
assertTrue("No ClassLoadingMXBeans returned", classloadingMXBeans.size() > 0);
// GarbageCollectorMXBean
List<GarbageCollectorMXBean> gcMXBeans =
ManagementFactory.getPlatformMXBeans(GarbageCollectorMXBean.class);
assertTrue("No GarbageCollectorMXBeans returned", gcMXBeans.size() > 0);
// MemoryManagerMXBean
List<MemoryManagerMXBean> memoryManagerBeans =
ManagementFactory.getPlatformMXBeans(MemoryManagerMXBean.class);
assertTrue("No MemoryManagerMXBeans returned", memoryManagerBeans.size() > 0);
// MemoryPoolMXBean
List<MemoryPoolMXBean> memoryPoolBeans =
ManagementFactory.getPlatformMXBeans(MemoryPoolMXBean.class);
assertTrue("No MemoryPoolMXBeans returned", memoryPoolBeans.size() > 0);
// RuntimeMXBean
List<RuntimeMXBean> runtimeBeans =
ManagementFactory.getPlatformMXBeans(RuntimeMXBean.class);
assertTrue("No RuntimeMXBeans returned", runtimeBeans.size() > 0);
}