我想将Micrometer TomcatMetrics度量标准类插入到没有Spring集成的现有tomcat应用程序中
从源代码的外观来看,只需调用
public static void monitor(MeterRegistry registry, @Nullable Manager manager, String... tags)
但是,我似乎无法弄清楚如何获得org.apache.catalina.Manager
实例。
没有经理(空),它可以工作,但是缺少我想要的会话信息。
那么如何以适当的方式(servletContextListener之类)来掌握它
答案 0 :(得分:0)
private static Manager manager;
private static synchronized Manager getManager(ServletContext servletContext) {
if (manager == null) {
try {
Field applicationContextField = servletContext.getClass().getDeclaredField("context");
applicationContextField.setAccessible(true);
ApplicationContext appContextObj = (ApplicationContext) applicationContextField.get(servletContext);
Field standardContextField = appContextObj.getClass().getDeclaredField("context");
standardContextField.setAccessible(true);
StandardContext standardContextObj = (StandardContext) standardContextField.get(appContextObj);
manager = standardContextObj.getManager();
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
return manager;
}