actuator 提供了很多端点信息,如:内存,cpu,hump文件,健康信息等,但没提供一个方便获取的项目,springboot admin就适时而生
注意:springboot admin 2.0 无法获取springboot1.5.x 的很多端点信息
最好admin 2.x 对应boot的2.x
这里拿生成dump 文件举例
端点类:HeapDumpWebEndpoint
步骤
1,生成临时文件
2,往临时文件写入dump信息
3,响应给客户端
protected static class HotSpotDiagnosticMXBeanHeapDumper implements HeapDumper { private Object diagnosticMXBean; private Method dumpHeapMethod; @SuppressWarnings("unchecked") protected HotSpotDiagnosticMXBeanHeapDumper() { try { Class<?> diagnosticMXBeanClass = ClassUtils .resolveClassName("com.sun.management.HotSpotDiagnosticMXBean", null); this.diagnosticMXBean = ManagementFactory .getPlatformMXBean((Class<PlatformManagedObject>) diagnosticMXBeanClass); this.dumpHeapMethod = ReflectionUtils.findMethod(diagnosticMXBeanClass, "dumpHeap", String.class, Boolean.TYPE); } catch (Throwable ex) { throw new HeapDumperUnavailableException("Unable to locate HotSpotDiagnosticMXBean", ex); } } @Override public void dumpHeap(File file, boolean live) { ReflectionUtils.invokeMethod(this.dumpHeapMethod, this.diagnosticMXBean, file.getAbsolutePath(), live); } }
发现是利用HotSpotDiagnosticMXBean 生成的
那我就有疑问了,非hotspot 的jvm是不是就不行呢,本地用的是zulu的jdk,发现是可以生成dump的
4,将具体某个实例请求转发到actuator,拦截instances/{instanceId}/actuator/** 和 applications/{applicationName}/actuator/** 请求
InstancesProxyController