我是靠谱客的博主 心灵美金针菇,最近开发中收集的这篇文章主要介绍普罗米修斯java_Prometheus 普罗米修斯监控,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

public class WebInterceptor extendsHandlerInterceptorAdapter {private static Logger logger = Logger.getLogger(WebInterceptor.class);private static final String SYSTEM_ID= "BLOAN-GJJ";private static final String APP_ID= "gjj-ics-credit";private static final String TYPE = "java";private static final Histogram requestLatency =Histogram.build()

.name("service_requests_latency_seconds")

.help("Request latency in seconds.")

.labelNames("systemId", "appId", "type", "name", "method").register();private ThreadLocaltimerThreadLocal;

@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throwsException {return super.preHandle(request, response, handler);

}

@Overridepublic void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throwsException {

String name= this.getName(request, handler).toLowerCase();

String method=request.getMethod().toUpperCase();

timerThreadLocal= new ThreadLocal<>();

timerThreadLocal.set(requestLatency.labels(SYSTEM_ID, APP_ID, TYPE, name, method).startTimer());super.postHandle(request, response, handler, modelAndView);

}

@Overridepublic void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throwsException {super.afterCompletion(request, response, handler, ex);if (timerThreadLocal.get() != null) {

timerThreadLocal.get().observeDuration();

}

}

@Overridepublic void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throwsException {super.afterConcurrentHandlingStarted(request, response, handler);

}privateString getName(HttpServletRequest request, Object handler) {

String name= "";try{if (handler != null

&& handler instanceofHandlerMethod) {

HandlerMethod method=(HandlerMethod) handler;

String className=((HandlerMethod) handler).getBeanType().getName();

name= className + "." +method.getMethod().getName();

}else{

name=request.getRequestURI();

}

}catch(Exception ex) {

logger.error("getName", ex);

}finally{returnname;

}

}

}

最后

以上就是心灵美金针菇为你收集整理的普罗米修斯java_Prometheus 普罗米修斯监控的全部内容,希望文章能够帮你解决普罗米修斯java_Prometheus 普罗米修斯监控所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部