client metrics
This commit is contained in:
parent
2a5df09a53
commit
d1a09847fe
@ -27,6 +27,18 @@
|
||||
|
||||
<name>nacos-client ${project.version}</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@ -107,5 +119,10 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -34,6 +34,7 @@ import com.alibaba.nacos.client.config.utils.TenantUtil;
|
||||
import com.alibaba.nacos.client.logger.Logger;
|
||||
import com.alibaba.nacos.client.logger.support.LoggerHelper;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
@ -41,6 +42,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Config Impl
|
||||
@ -131,9 +133,11 @@ public class NacosConfigService implements ConfigService {
|
||||
|
||||
try {
|
||||
content = worker.getServerConfig(dataId, group, tenant, timeoutMs);
|
||||
|
||||
cr.setContent(content);
|
||||
configFilterChainManager.doFilter(null, cr);
|
||||
content = cr.getContent();
|
||||
|
||||
return content;
|
||||
} catch (NacosException ioe) {
|
||||
if (NacosException.NO_RIGHT == ioe.getErrCode()) {
|
||||
@ -159,6 +163,8 @@ public class NacosConfigService implements ConfigService {
|
||||
}
|
||||
|
||||
private boolean removeConfigInner(String tenant, String dataId, String group, String tag) throws NacosException {
|
||||
long start = 0;
|
||||
long end = 0;
|
||||
group = null2defaultGroup(group);
|
||||
ParamUtils.checkKeyParam(dataId, group);
|
||||
String url = Constants.CONFIG_CONTROLLER_PATH;
|
||||
@ -177,8 +183,23 @@ public class NacosConfigService implements ConfigService {
|
||||
}
|
||||
HttpResult result = null;
|
||||
try {
|
||||
start = System.currentTimeMillis();
|
||||
result = agent.httpDelete(url, null, params, encode, POST_TIMEOUT);
|
||||
end = System.currentTimeMillis();
|
||||
Metrics.timer("nacos_client_request",
|
||||
"module", "config",
|
||||
"method", "DELETE",
|
||||
"url", Constants.CONFIG_CONTROLLER_PATH,
|
||||
"code", String.valueOf(result.code))
|
||||
.record(end - start, TimeUnit.MILLISECONDS);
|
||||
} catch (IOException ioe) {
|
||||
end = System.currentTimeMillis();
|
||||
Metrics.timer("nacos_client_request",
|
||||
"module", "config",
|
||||
"method", "DELETE",
|
||||
"url", Constants.CONFIG_CONTROLLER_PATH,
|
||||
"code", "0")
|
||||
.record(end - start, TimeUnit.MILLISECONDS);
|
||||
log.warn("[remove] error, " + dataId + ", " + group + ", " + tenant + ", msg: " + ioe.toString());
|
||||
return false;
|
||||
}
|
||||
@ -199,6 +220,9 @@ public class NacosConfigService implements ConfigService {
|
||||
|
||||
private boolean publishConfigInner(String tenant, String dataId, String group, String tag, String appName,
|
||||
String betaIps, String content) throws NacosException {
|
||||
long start = 0;
|
||||
long end = 0;
|
||||
|
||||
group = null2defaultGroup(group);
|
||||
ParamUtils.checkParam(dataId, group, content);
|
||||
|
||||
@ -239,8 +263,25 @@ public class NacosConfigService implements ConfigService {
|
||||
|
||||
HttpResult result = null;
|
||||
try {
|
||||
start = System.currentTimeMillis();
|
||||
result = agent.httpPost(url, headers, params, encode, POST_TIMEOUT);
|
||||
end = System.currentTimeMillis();
|
||||
|
||||
Metrics.timer("nacos_client_request",
|
||||
"module", "config",
|
||||
"method", "POST",
|
||||
"url", Constants.CONFIG_CONTROLLER_PATH,
|
||||
"code", String.valueOf(result.code))
|
||||
.record(end - start, TimeUnit.MILLISECONDS);
|
||||
} catch (IOException ioe) {
|
||||
end = System.currentTimeMillis();
|
||||
|
||||
Metrics.timer("nacos_client_request",
|
||||
"module", "config",
|
||||
"method", "POST",
|
||||
"url", Constants.CONFIG_CONTROLLER_PATH,
|
||||
"code", "0")
|
||||
.record(end - start, TimeUnit.MILLISECONDS);
|
||||
log.warn("NACOS-0006",
|
||||
LoggerHelper.getErrorCodeStr("NACOS", "NACOS-0006", "环境问题", "[publish-single] exception"));
|
||||
log.warn(agent.getName(), "[publish-single] exception, dataId={}, group={}, msg={}", dataId, group,
|
||||
|
@ -30,6 +30,9 @@ import com.alibaba.nacos.client.logger.support.LoggerHelper;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import io.micrometer.core.instrument.Gauge;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -37,7 +40,9 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.ToDoubleFunction;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.LINE_SEPARATOR;
|
||||
import static com.alibaba.nacos.api.common.Constants.WORD_SEPARATOR;
|
||||
@ -100,6 +105,8 @@ public class ClientWorker {
|
||||
cacheMap.set(copy);
|
||||
}
|
||||
log.info(agent.getName(), "[unsubscribe] {}", groupKey);
|
||||
|
||||
cacheSize.set(cacheMap.get().size());
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("JLM_JSR166_UTILCONCURRENT_MONITORENTER")
|
||||
@ -111,6 +118,8 @@ public class ClientWorker {
|
||||
cacheMap.set(copy);
|
||||
}
|
||||
log.info(agent.getName(), "[unsubscribe] {}", groupKey);
|
||||
|
||||
cacheSize.set(cacheMap.get().size());
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("JLM_JSR166_UTILCONCURRENT_MONITORENTER")
|
||||
@ -143,6 +152,8 @@ public class ClientWorker {
|
||||
|
||||
log.info(agent.getName(), "[subscribe] {}", key);
|
||||
|
||||
cacheSize.set(cacheMap.get().size());
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
@ -170,6 +181,9 @@ public class ClientWorker {
|
||||
cacheMap.set(copy);
|
||||
}
|
||||
log.info(agent.getName(), "[subscribe] {}", key);
|
||||
|
||||
cacheSize.set(cacheMap.get().size());
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
@ -186,6 +200,9 @@ public class ClientWorker {
|
||||
|
||||
public String getServerConfig(String dataId, String group, String tenant, long readTimeout)
|
||||
throws NacosException {
|
||||
long start = 0;
|
||||
long end = 0;
|
||||
|
||||
if (StringUtils.isBlank(group)) {
|
||||
group = Constants.DEFAULT_GROUP;
|
||||
}
|
||||
@ -198,8 +215,27 @@ public class ClientWorker {
|
||||
} else {
|
||||
params = Arrays.asList("dataId", dataId, "group", group, "tenant", tenant);
|
||||
}
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
result = agent.httpGet(Constants.CONFIG_CONTROLLER_PATH, null, params, agent.getEncode(), readTimeout);
|
||||
end = System.currentTimeMillis();
|
||||
|
||||
Metrics.timer("nacos_client_request",
|
||||
"module", "config",
|
||||
"method", "GET",
|
||||
"url", Constants.CONFIG_CONTROLLER_PATH,
|
||||
"code", String.valueOf(result.code))
|
||||
.record(end - start, TimeUnit.MILLISECONDS);
|
||||
} catch (IOException e) {
|
||||
end = System.currentTimeMillis();
|
||||
|
||||
Metrics.timer("nacos_client_request",
|
||||
"module", "config",
|
||||
"method", "GET",
|
||||
"url", Constants.CONFIG_CONTROLLER_PATH,
|
||||
"code", "0")
|
||||
.record(end - start, TimeUnit.MILLISECONDS);
|
||||
|
||||
log.error(agent.getName(), "NACOS-XXXX",
|
||||
"[sub-server] get server config exception, dataId={}, group={}, tenant={}, msg={}", dataId, group,
|
||||
tenant, e.toString());
|
||||
@ -409,6 +445,10 @@ public class ClientWorker {
|
||||
public ClientWorker(final ServerHttpAgent agent, final ConfigFilterChainManager configFilterChainManager) {
|
||||
this.agent = agent;
|
||||
this.configFilterChainManager = configFilterChainManager;
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
tags.add(Tag.of("module", "config"));
|
||||
tags.add(Tag.of("name", "configListenSize"));
|
||||
Metrics.gauge("nacos_monitor", tags, cacheSize);
|
||||
executor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
@ -522,9 +562,10 @@ public class ClientWorker {
|
||||
*/
|
||||
AtomicReference<Map<String, CacheData>> cacheMap = new AtomicReference<Map<String, CacheData>>(
|
||||
new HashMap<String, CacheData>());
|
||||
AtomicInteger cacheSize = new AtomicInteger(0);
|
||||
|
||||
ServerHttpAgent agent;
|
||||
ConfigFilterChainManager configFilterChainManager;
|
||||
private boolean isHealthServer = true;
|
||||
private double currentLongingTaskCount = 0;
|
||||
|
||||
}
|
||||
|
@ -21,10 +21,15 @@ import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.client.naming.net.NamingProxy;
|
||||
import com.alibaba.nacos.client.naming.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author harold
|
||||
@ -46,20 +51,28 @@ public class BeatReactor {
|
||||
private NamingProxy serverProxy;
|
||||
|
||||
public final Map<String, BeatInfo> dom2Beat = new ConcurrentHashMap<String, BeatInfo>();
|
||||
private AtomicInteger dom2BeatSize = new AtomicInteger();
|
||||
|
||||
public BeatReactor(NamingProxy serverProxy) {
|
||||
this.serverProxy = serverProxy;
|
||||
executorService.scheduleAtFixedRate(new BeatProcessor(), 0, clientBeatInterval, TimeUnit.MILLISECONDS);
|
||||
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
tags.add(Tag.of("module", "naming"));
|
||||
tags.add(Tag.of("name", "pubServiceCount"));
|
||||
Metrics.gauge("nacos_monitor", tags, dom2BeatSize);
|
||||
}
|
||||
|
||||
public void addBeatInfo(String dom, BeatInfo beatInfo) {
|
||||
LogUtils.LOG.info("BEAT", "adding service:" + dom + " to beat map.");
|
||||
dom2Beat.put(buildKey(dom, beatInfo.getIp(), beatInfo.getPort()), beatInfo);
|
||||
dom2BeatSize.set(dom2Beat.size());
|
||||
}
|
||||
|
||||
public void removeBeatInfo(String dom, String ip, int port) {
|
||||
LogUtils.LOG.info("BEAT", "removing service:" + dom + " from beat map.");
|
||||
dom2Beat.remove(buildKey(dom, ip, port));
|
||||
dom2BeatSize.set(dom2Beat.size());
|
||||
}
|
||||
|
||||
public String buildKey(String dom, String ip, int port) {
|
||||
|
@ -26,9 +26,12 @@ import com.alibaba.nacos.client.naming.utils.NetUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.StringUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author xuanyin
|
||||
@ -43,6 +46,8 @@ public class HostReactor {
|
||||
|
||||
private Map<String, ServiceInfo> serviceInfoMap;
|
||||
|
||||
private AtomicInteger serviceInfoMapSize = new AtomicInteger();
|
||||
|
||||
private Map<String, Object> updatingMap;
|
||||
|
||||
private PushRecver pushRecver;
|
||||
@ -69,6 +74,11 @@ public class HostReactor {
|
||||
this.updatingMap = new ConcurrentHashMap<String, Object>();
|
||||
this.failoverReactor = new FailoverReactor(this, cacheDir);
|
||||
this.pushRecver = new PushRecver(this);
|
||||
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
tags.add(Tag.of("module", "naming"));
|
||||
tags.add(Tag.of("name", "subServiceCount"));
|
||||
Metrics.gauge("nacos_monitor", tags, serviceInfoMapSize);
|
||||
}
|
||||
|
||||
private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
||||
@ -182,6 +192,8 @@ public class HostReactor {
|
||||
DiskCache.write(serviceInfo, cacheDir);
|
||||
}
|
||||
|
||||
serviceInfoMapSize.set(serviceInfoMap.size());
|
||||
|
||||
LogUtils.LOG.info("current ips:(" + serviceInfo.ipCount() + ") service: " + serviceInfo.getName() +
|
||||
" -> " + JSON.toJSONString(serviceInfo.getHosts()));
|
||||
|
||||
|
@ -26,6 +26,7 @@ import com.alibaba.nacos.api.selector.SelectorType;
|
||||
import com.alibaba.nacos.api.selector.ExpressionSelector;
|
||||
import com.alibaba.nacos.client.naming.utils.*;
|
||||
import com.alibaba.nacos.common.util.UuidUtils;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
@ -289,6 +290,8 @@ public class NamingProxy {
|
||||
|
||||
public String callServer(String api, Map<String, String> params, String curServer, String method)
|
||||
throws NacosException {
|
||||
long start = 0;
|
||||
long end = 0;
|
||||
|
||||
List<String> headers = Arrays.asList("Client-Version", UtilAndComs.VERSION,
|
||||
"Accept-Encoding", "gzip,deflate,sdch",
|
||||
@ -302,9 +305,15 @@ public class NamingProxy {
|
||||
}
|
||||
|
||||
url = HttpClient.getPrefix() + curServer + api;
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
HttpClient.HttpResult result = HttpClient.request(url, headers, params, UtilAndComs.ENCODING, method);
|
||||
|
||||
end = System.currentTimeMillis();
|
||||
Metrics.timer("nacos_client_request",
|
||||
"module", "naming",
|
||||
"method", method,
|
||||
"url", api,
|
||||
"code", String.valueOf(result.code))
|
||||
.record(end - start, TimeUnit.MILLISECONDS);
|
||||
if (HttpURLConnection.HTTP_OK == result.code) {
|
||||
return result.content;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user