In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the function of nacos client's MetricsMonitor". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the role of nacos client's MetricsMonitor?"
Order
This paper mainly studies the MetricsMonitor of nacos client.
MetricsMonitor
Nacos-1.1.3/client/src/main/java/com/alibaba/nacos/client/monitor/MetricsMonitor.java
Public class MetricsMonitor {private static Gauge nacosMonitor = Gauge.build () .name ("nacos_monitor"). LabelNames ("module", "name") .help ("nacos_monitor") .register (); private static Histogram nacosClientRequestHistogram = Histogram.build () .labelNames ("module", "method", "url", "code") .name ("nacos_client_request"). Help ("nacos_client_request") .register () Public static Gauge.Child getServiceInfoMapSizeMonitor () {return nacosMonitor.labels ("naming", "serviceInfoMapSize");} public static Gauge.Child getDom2BeatSizeMonitor () {return nacosMonitor.labels ("naming", "dom2BeatSize");} public static Gauge.Child getListenConfigCountMonitor () {return nacosMonitor.labels ("naming", "listenConfigCount") } public static Histogram.Timer getConfigRequestMonitor (String method, String url, String code) {return nacosClientRequestHistogram.labels ("config", method, url, code). StartTimer ();} public static Histogram.Child getNamingRequestMonitor (String method, String url, String code) {return nacosClientRequestHistogram.labels ("naming", method, url, code);}}
MetricsMonitor has built-in nacosMonitor and nacosClientRequestHistogram; and provides getServiceInfoMapSizeMonitor, getDom2BeatSizeMonitor, getListenConfigCountMonitor, getConfigRequestMonitor, getNamingRequestMonitor static methods
MetricsHttpAgent
Nacos-1.1.3/client/src/main/java/com/alibaba/nacos/client/config/http/MetricsHttpAgent.java
Public class MetricsHttpAgent implements HttpAgent {private HttpAgent httpAgent; public MetricsHttpAgent (HttpAgent httpAgent) {this.httpAgent = httpAgent;} @ Override public void start () throws NacosException {httpAgent.start ();} @ Override public HttpResult httpGet (String path, List headers, List paramValues, String encoding, long readTimeoutMs) throws IOException {Histogram.Timer timer = MetricsMonitor.getConfigRequestMonitor ("GET", path, "NA"); HttpResult result = null Try {result = httpAgent.httpGet (path, headers, paramValues, encoding, readTimeoutMs);} catch (IOException e) {throw e;} finally {timer.observeDuration (); timer.close ();} return result } @ Override public HttpResult httpPost (String path, List headers, List paramValues, String encoding, long readTimeoutMs) throws IOException {Histogram.Timer timer = MetricsMonitor.getConfigRequestMonitor ("POST", path, "NA"); HttpResult result = null; try {result = httpAgent.httpPost (path, headers, paramValues, encoding, readTimeoutMs);} catch (IOException e) {throw e } finally {timer.observeDuration (); timer.close ();} return result;} @ Override public HttpResult httpDelete (String path, List headers, List paramValues, String encoding, long readTimeoutMs) throws IOException {Histogram.Timer timer = MetricsMonitor.getConfigRequestMonitor ("DELETE", path, "NA"); HttpResult result = null Try {result = httpAgent.httpDelete (path, headers, paramValues, encoding, readTimeoutMs);} catch (IOException e) {throw e;} finally {timer.observeDuration (); timer.close ();} return result;} @ Override public String getName () {return httpAgent.getName () } @ Override public String getNamespace () {return httpAgent.getNamespace ();} @ Override public String getTenant () {return httpAgent.getTenant ();} @ Override public String getEncode () {return httpAgent.getEncode ();}}
MetricsHttpAgent proxies httpAgent, which obtains Histogram.Timer through MetricsMonitor.getConfigRequestMonitor before and after the execution of httpGet, httpPost, httpDelete methods, and records the response time.
NamingProxy
Nacos-1.1.3/client/src/main/java/com/alibaba/nacos/client/naming/net/NamingProxy.java
Public class NamingProxy {private static final int DEFAULT_SERVER_PORT = 8848; private int serverPort = DEFAULT_SERVER_PORT; private String namespaceId; private String endpoint; private String nacosDomain; private List serverList; private List serversFromEndpoint = new ArrayList (); private long lastSrvRefTime = 0L; private long vipSrvRefInterMillis = TimeUnit.SECONDS.toMillis (30); private Properties properties; public NamingProxy (String namespaceId, String endpoint, String serverList) {this.namespaceId = namespaceId; this.endpoint = endpoint If (StringUtils.isNotEmpty (serverList)) {this.serverList = Arrays.asList (serverList.split (","); if (this.serverList.size () = = 1) {this.nacosDomain = serverList;}} initRefreshSrvIfNeed ();} / /. Public String callServer (String api, Map params, String curServer, String method) throws NacosException {long start = System.currentTimeMillis (); long end = 0; checkSignature (params); List headers = builderHeaders (); String url; if (curServer.startsWith (UtilAndComs.HTTPS) | | curServer.startsWith (UtilAndComs.HTTP)) {url = curServer + api } else {if (! curServer.contains (UtilAndComs.SERVER_ADDR_IP_SPLITER)) {curServer = curServer + UtilAndComs.SERVER_ADDR_IP_SPLITER + serverPort;} url = HttpClient.getPrefix () + curServer + api;} HttpClient.HttpResult result = HttpClient.request (url, headers, params, UtilAndComs.ENCODING, method); end = System.currentTimeMillis () MetricsMonitor.getNamingRequestMonitor (method, url, String.valueOf (result.code)). Observe (end-start); if (HttpURLConnection.HTTP_OK = = result.code) {return result.content;} if (HttpURLConnection.HTTP_NOT_MODIFIED = = result.code) {return StringUtils.EMPTY } throw new NacosException (NacosException.SERVER_ERROR, "failed to req API:" + curServer + api + ". Code: "+ result.code +" msg: "+ result.content);} /.}
NamingProxy's callServer method records the request time through MetricsMonitor.getNamingRequestMonitor after the http request has been executed
Summary
MetricsMonitor has built-in nacosMonitor and nacosClientRequestHistogram; and provides getServiceInfoMapSizeMonitor, getDom2BeatSizeMonitor, getListenConfigCountMonitor, getConfigRequestMonitor, getNamingRequestMonitor static methods
At this point, I believe you have a deeper understanding of "what is the role of nacos client's MetricsMonitor". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.