use of java.lang.management.MemoryMXBean in project spring-framework by spring-projects.
the class MBeanClientInterceptorTests method mxBeanAttributeAccess.
@Test
void mxBeanAttributeAccess() throws Exception {
MBeanClientInterceptor interceptor = new MBeanClientInterceptor();
interceptor.setServer(ManagementFactory.getPlatformMBeanServer());
interceptor.setObjectName("java.lang:type=Memory");
interceptor.setManagementInterface(MemoryMXBean.class);
MemoryMXBean proxy = ProxyFactory.getProxy(MemoryMXBean.class, interceptor);
assertThat(proxy.getHeapMemoryUsage().getMax()).isGreaterThan(0);
}
use of java.lang.management.MemoryMXBean in project neo4j by neo4j.
the class JmxDump method heapDump.
public DiagnosticsReportSource heapDump() {
return new DiagnosticsReportSource() {
@Override
public String destinationPath() {
return "heapdump.hprof";
}
@Override
public InputStream newInputStream() throws IOException {
final Path heapdumpFile = createTempFile("neo4j-heapdump", ".hprof").toAbsolutePath();
heapDump(heapdumpFile.toString());
return new FileInputStream(heapdumpFile.toFile()) {
@Override
public void close() throws IOException {
super.close();
deleteIfExists(heapdumpFile);
}
};
}
@Override
public long estimatedSize() {
try {
final MemoryMXBean bean = ManagementFactory.getPlatformMXBean(mBeanServer, MemoryMXBean.class);
final long totalMemory = bean.getHeapMemoryUsage().getCommitted() + bean.getNonHeapMemoryUsage().getCommitted();
// We first write raw to disk then write to archive, 5x compression is a reasonable worst case estimation
return (long) (totalMemory * 1.2);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
};
}
use of java.lang.management.MemoryMXBean in project databus by linkedin.
the class JavaStatsRequestProcessor method processAllMemoryStats.
private void processAllMemoryStats(DatabusRequest request) throws IOException {
MemoryMXBean memStats = ManagementFactory.getMemoryMXBean();
writeJsonObjectToResponse(memStats, request);
}
use of java.lang.management.MemoryMXBean in project Axe by DongyuCai.
the class AxeRest method status.
@Request(path = "/status", method = RequestMethod.GET, desc = "获取系统状态")
public Map<String, Object> status() {
Map<String, Object> result = new HashMap<>();
// 启动时间
Date startupTime = FrameworkStatusHelper.getStartupTime();
result.put("startTime", new SimpleDateFormat("MM-dd HH:mm:ss").format(startupTime));
// 已经运行时长
long runTimeSec = (System.currentTimeMillis() - startupTime.getTime()) / 1000;
String runTime = "";
if (runTimeSec < 60) {
runTime = runTimeSec + "秒";
} else {
long runTimeMin = runTimeSec / 60;
if (runTimeMin < 60) {
runTimeSec = runTimeSec - (runTimeMin * 60);
runTime = runTimeMin + "分" + runTimeSec + "秒";
} else {
long runTimeHour = runTimeMin / 60;
if (runTimeHour < 24) {
runTimeMin = runTimeMin - runTimeHour * 60;
runTimeSec = runTimeSec - ((runTimeHour * 60) + runTimeMin) * 60;
runTime = runTimeHour + "时" + runTimeMin + "分" + runTimeSec + "秒";
} else {
long runTimeDay = runTimeHour / 24;
runTimeHour = runTimeHour - (runTimeDay * 24);
runTimeMin = runTimeMin - ((runTimeDay * 24) + runTimeHour) * 60;
runTimeSec = runTimeSec - ((((runTimeDay * 24) + runTimeHour) * 60) + runTimeMin) * 60;
runTime = runTimeDay + "天" + runTimeHour + "时" + runTimeMin + "分" + runTimeSec + "秒";
}
}
}
result.put("runTime", runTime);
// 系统负载
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
// 椎内存使用情况
MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage();
int M = 1024 * 1024;
// 已使用的内存
result.put("usedMemory", memoryUsage.getUsed() / M);
// 最大可用内存
result.put("maxMemory", memoryUsage.getMax() / M);
// Filter数量
result.put("filterSize", FilterHelper.getSortedFilterList().size());
// Interceptor数量
result.put("interceptorSize", InterceptorHelper.getInterceptorMap().size());
// Controller数量
int controllerSize = ClassHelper.getControllerClassSet().size();
result.put("controllerSize", controllerSize);
// Service数量
Set<Class<?>> serviceClassSet = ClassHelper.getServiceClassSet();
int serviceSize = serviceClassSet.size();
result.put("serviceSize", serviceSize);
// Component数量
int componentSize = ClassHelper.getComponentClassSet().size();
result.put("componentSize", componentSize);
// Tns数量
int tnsSize = 0;
for (Class<?> serviceClass : serviceClassSet) {
List<Method> methods = ReflectionUtil.getMethodByAnnotation(serviceClass, Tns.class);
if (CollectionUtil.isNotEmpty(methods)) {
tnsSize = tnsSize + methods.size();
}
}
result.put("tnsSize", tnsSize);
// Dao数量
int daoSize = ClassHelper.getClassSetByAnnotation(Dao.class).size();
result.put("daoSize", daoSize);
// Action数量
result.put("actionSize", ControllerHelper.getActionList().size());
// Table数量
result.put("tableSize", TableHelper.getEntityTableSchemaCachedMap().size());
// DataSource数量
result.put("dataSourceSize", DataSourceHelper.getDataSourceAll().size());
return result;
}
use of java.lang.management.MemoryMXBean in project openolat by klemens.
the class MemoryRenderer method render.
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
MemoryComponent cmp = (MemoryComponent) source;
MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
sb.append("<div class='progress' ");
if (!cmp.isDomReplacementWrapperRequired()) {
sb.append(" id='o_c").append(cmp.getDispatchID()).append("'");
}
if (cmp.getMemoryType() == MemoryType.HEAP) {
renderDetails(sb, memoryBean.getHeapMemoryUsage().getMax(), MemoryType.HEAP);
} else if (cmp.getMemoryType() == MemoryType.NON_HEAP) {
renderDetails(sb, memoryBean.getNonHeapMemoryUsage().getMax(), MemoryType.NON_HEAP);
}
sb.append("</div>");
}
Aggregations