From 5852af0c7804e83cd13efd993f56a15af064a6dd Mon Sep 17 00:00:00 2001 From: luyi Date: Fri, 21 Sep 2018 15:02:21 +0800 Subject: [PATCH] upgrade to 1.5.1 and do some refactors (#41) * fix log debug npe bug * optimize the usage of lookoutclient * change wiki link to doc site in readme --- client/README.md | 4 +-- client/lookout-api/pom.xml | 2 +- client/lookout-client/pom.xml | 2 +- .../lookout/client/AbstractLookoutClient.java | 4 +++ .../lookout/client/DefaultLookoutClient.java | 6 +++- client/lookout-common/pom.xml | 2 +- client/lookout-core/pom.xml | 2 +- client/lookout-ext-jvm/pom.xml | 2 +- client/lookout-ext-os/pom.xml | 2 +- client/lookout-reg-dropwizard/pom.xml | 2 +- client/lookout-reg-prometheus/pom.xml | 2 +- client/lookout-reg-server/pom.xml | 2 +- .../lookout/remote/report/HttpObserver.java | 10 ++----- .../http/DefaultHttpRequestProcessor.java | 30 +++++++++---------- .../support/http/HttpRequestProcessor.java | 2 -- .../report/support/http/ReportDecider.java | 16 ++++++++-- .../lookout/MockHttpRequestProcessor.java | 5 ---- .../remote/report/HttpObserverTest.java | 4 --- .../support/HttpRequestProcessorTest.java | 4 ++- .../http/DefaultHttpRequestProcessorTest.java | 4 ++- .../support/http/ReportDeciderTest.java | 8 ++--- client/lookout-sofa-boot-starter/pom.xml | 2 +- client/pom.xml | 2 +- .../lookout-client-samples-boot/pom.xml | 2 +- .../pom.xml | 2 +- .../lookout-client-samples-java/README.md | 4 ++- .../lookout-client-samples-java/pom.xml | 2 +- .../samples/DefaultLookoutClientDemo.java | 12 +++++--- .../lookout-client-samples-prometheus/pom.xml | 2 +- 29 files changed, 77 insertions(+), 66 deletions(-) diff --git a/client/README.md b/client/README.md index e45abe2..b3ae8bd 100644 --- a/client/README.md +++ b/client/README.md @@ -10,7 +10,7 @@ SOFALookout Client 项目支持 Maven 3.2.5+,JDK 6+ 进行编译。 ## 2. API 埋点需知 -lookout-api 支持被单独依赖和使用,方便植入您的项目代码,收集需要的 metrics,更多信息参考 [WIKI 文档](http://www.sofastack.tech/sofa-lookout/docs/Home)。 +lookout-api 支持被单独依赖和使用,方便植入您的项目代码,收集需要的 metrics,更多信息参考 [官方文档](http://www.sofastack.tech/sofa-lookout/docs/Home)。 ## 3. 扩展能力 @@ -49,4 +49,4 @@ lookout 客户端提供了 SPI 机制(只需要实现 `com.alipay.lookout.spi. ## 6.如何使用 -参考 [WIKI 文档](http://www.sofastack.tech/sofa-lookout/docs/Home)的快速开始和用户手册。 +参考 [官方文档](http://www.sofastack.tech/sofa-lookout/docs/Home)的快速开始和用户手册。 diff --git a/client/lookout-api/pom.xml b/client/lookout-api/pom.xml index 2e6557d..10dedac 100644 --- a/client/lookout-api/pom.xml +++ b/client/lookout-api/pom.xml @@ -5,7 +5,7 @@ com.alipay.sofa.lookout lookout-client-parent - 1.5.0 + 1.5.1 ../pom.xml diff --git a/client/lookout-client/pom.xml b/client/lookout-client/pom.xml index a9832a1..1814850 100644 --- a/client/lookout-client/pom.xml +++ b/client/lookout-client/pom.xml @@ -6,7 +6,7 @@ com.alipay.sofa.lookout lookout-client-parent - 1.5.0 + 1.5.1 ../pom.xml diff --git a/client/lookout-client/src/main/java/com/alipay/lookout/client/AbstractLookoutClient.java b/client/lookout-client/src/main/java/com/alipay/lookout/client/AbstractLookoutClient.java index f94ed40..169dd28 100644 --- a/client/lookout-client/src/main/java/com/alipay/lookout/client/AbstractLookoutClient.java +++ b/client/lookout-client/src/main/java/com/alipay/lookout/client/AbstractLookoutClient.java @@ -50,6 +50,10 @@ public AbstractLookoutClient(String appName) { Assert.checkArg(StringUtils.isNotEmpty(appName), "appName is required!"); } + protected String getAppName() { + return appName; + } + protected void addRegistry(MetricRegistry registry) { Preconditions.checkArgument(!(registry instanceof CompositeRegistry), "The registry can not be compositeRegistry!"); diff --git a/client/lookout-client/src/main/java/com/alipay/lookout/client/DefaultLookoutClient.java b/client/lookout-client/src/main/java/com/alipay/lookout/client/DefaultLookoutClient.java index 47a90ca..5f8e054 100644 --- a/client/lookout-client/src/main/java/com/alipay/lookout/client/DefaultLookoutClient.java +++ b/client/lookout-client/src/main/java/com/alipay/lookout/client/DefaultLookoutClient.java @@ -20,7 +20,7 @@ import com.alipay.lookout.api.MetricRegistry; import com.alipay.lookout.core.config.MetricConfig; import com.alipay.lookout.remote.step.LookoutRegistry; - +import static com.alipay.lookout.core.config.LookoutConfig.APP_NAME; import static com.alipay.lookout.core.config.LookoutConfig.LOOKOUT_EXPORTER_ENABLE; /** @@ -50,6 +50,10 @@ public synchronized void addRegistry(MetricRegistry registry) { if (registry instanceof LookoutRegistry) { MetricConfig config = ((LookoutRegistry) registry).getConfig(); + if (!config.containsKey(APP_NAME)) { + //HttpObserver needs + config.setProperty(APP_NAME, getAppName()); + } if (!config.getBoolean(LOOKOUT_EXPORTER_ENABLE, false)) { return; } diff --git a/client/lookout-common/pom.xml b/client/lookout-common/pom.xml index ddc6012..c975033 100644 --- a/client/lookout-common/pom.xml +++ b/client/lookout-common/pom.xml @@ -6,7 +6,7 @@ com.alipay.sofa.lookout lookout-client-parent - 1.5.0 + 1.5.1 ../pom.xml diff --git a/client/lookout-core/pom.xml b/client/lookout-core/pom.xml index 2203e3c..3263ba2 100644 --- a/client/lookout-core/pom.xml +++ b/client/lookout-core/pom.xml @@ -6,7 +6,7 @@ com.alipay.sofa.lookout lookout-client-parent - 1.5.0 + 1.5.1 ../pom.xml diff --git a/client/lookout-ext-jvm/pom.xml b/client/lookout-ext-jvm/pom.xml index e23b916..d113099 100644 --- a/client/lookout-ext-jvm/pom.xml +++ b/client/lookout-ext-jvm/pom.xml @@ -6,7 +6,7 @@ com.alipay.sofa.lookout lookout-client-parent - 1.5.0 + 1.5.1 ../pom.xml diff --git a/client/lookout-ext-os/pom.xml b/client/lookout-ext-os/pom.xml index 7851365..f8f439f 100644 --- a/client/lookout-ext-os/pom.xml +++ b/client/lookout-ext-os/pom.xml @@ -5,7 +5,7 @@ com.alipay.sofa.lookout lookout-client-parent - 1.5.0 + 1.5.1 ../pom.xml diff --git a/client/lookout-reg-dropwizard/pom.xml b/client/lookout-reg-dropwizard/pom.xml index 2dfefb6..c5f185a 100644 --- a/client/lookout-reg-dropwizard/pom.xml +++ b/client/lookout-reg-dropwizard/pom.xml @@ -6,7 +6,7 @@ com.alipay.sofa.lookout lookout-client-parent - 1.5.0 + 1.5.1 ../pom.xml diff --git a/client/lookout-reg-prometheus/pom.xml b/client/lookout-reg-prometheus/pom.xml index a15cf7e..5d2d5d7 100644 --- a/client/lookout-reg-prometheus/pom.xml +++ b/client/lookout-reg-prometheus/pom.xml @@ -6,7 +6,7 @@ com.alipay.sofa.lookout lookout-client-parent - 1.5.0 + 1.5.1 ../pom.xml diff --git a/client/lookout-reg-server/pom.xml b/client/lookout-reg-server/pom.xml index 26b0ed6..ba34a03 100644 --- a/client/lookout-reg-server/pom.xml +++ b/client/lookout-reg-server/pom.xml @@ -6,7 +6,7 @@ com.alipay.sofa.lookout lookout-client-parent - 1.5.0 + 1.5.1 ../pom.xml diff --git a/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/HttpObserver.java b/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/HttpObserver.java index 576880a..94e44c0 100644 --- a/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/HttpObserver.java +++ b/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/HttpObserver.java @@ -51,7 +51,6 @@ public class HttpObserver implements MetricObserver { private static final Logger logger = LookoutLoggerFactory .getLogger(HttpObserver.class); - static final String APP_HEADER_NAME = "app"; public static final String UTF_8 = "utf-8"; static final String AGENT_URL_PATTERN = "http://%s:%d/datas"; public static final String APPLICATION_OCTET_STREAM = "application/octet-stream"; @@ -77,7 +76,9 @@ public HttpObserver(LookoutConfig lookoutConfig, AddressService addrService) { } public HttpObserver(LookoutConfig lookoutConfig, AddressService addrService, Registry registry) { - this(lookoutConfig, addrService, registry, new DefaultHttpRequestProcessor(addrService)); + this(lookoutConfig, addrService, registry, new DefaultHttpRequestProcessor(addrService, + lookoutConfig)); + } public HttpObserver(LookoutConfig lookoutConfig, AddressService addrService, Registry registry, @@ -91,11 +92,6 @@ public HttpObserver(LookoutConfig lookoutConfig, AddressService addrService, Reg System.getProperty(LOOKOUT_AGENT_TEST_URL))); //inner port innerAgentPort = lookoutConfig.getInt(LOOKOUT_AGENT_SERVER_PORT, -1); - //add common metadatas - if (lookoutConfig.containsKey(LookoutConfig.APP_NAME)) { - httpRequestProcessor.addCommonHeader(APP_HEADER_NAME, - lookoutConfig.getString(LookoutConfig.APP_NAME)); - } this.reg = registry; } diff --git a/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/DefaultHttpRequestProcessor.java b/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/DefaultHttpRequestProcessor.java index ebc8871..e4f353b 100644 --- a/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/DefaultHttpRequestProcessor.java +++ b/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/DefaultHttpRequestProcessor.java @@ -21,7 +21,10 @@ import com.alipay.lookout.api.Registry; import com.alipay.lookout.common.log.LookoutLoggerFactory; import com.alipay.lookout.common.utils.NetworkUtil; +import com.alipay.lookout.core.config.LookoutConfig; +import com.alipay.lookout.core.config.MetricConfig; import com.alipay.lookout.remote.report.AddressService; +import org.apache.commons.lang.StringUtils; import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.client.ResponseHandler; @@ -37,7 +40,6 @@ import org.slf4j.Logger; import java.io.IOException; -import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -57,6 +59,8 @@ public final class DefaultHttpRequestProcessor extends ReportDecider { public static final String LOOKOUT_REPORT_FAIL_COUNT_ID = "lookout.report.fail"; public static final String WAIT_MINUTES = "Wait-Minutes"; static final String CLIENT_VERSION = "LOOKOUT-CLIENT-V1"; + static final String APP_HEADER_NAME = "app"; + private final String clientIp = NetworkUtil.getLocalAddress() .getHostAddress(); @@ -67,15 +71,8 @@ public final class DefaultHttpRequestProcessor extends ReportDecider { private static final AtomicBoolean httpClientInitialized = new AtomicBoolean(false); - private final Map commonMetadata = new HashMap(); - - public DefaultHttpRequestProcessor(AddressService addressService) { - super(addressService); - } - - @Override - public void addCommonHeader(String headerName, String headerValue) { - commonMetadata.put(headerName, headerValue); + public DefaultHttpRequestProcessor(AddressService addressService, MetricConfig metricConfig) { + super(addressService, metricConfig); } @Override @@ -140,14 +137,17 @@ public Boolean handleResponse(HttpResponse response) throws IOException { } - private void addCommonHeaders(HttpRequestBase httpPost, Map metadata) { - httpPost.setHeader(CLIENT_IP_HEADER_NAME, clientIp); + private void addCommonHeaders(HttpRequestBase httpMtd, Map metadata) { + httpMtd.setHeader(CLIENT_IP_HEADER_NAME, clientIp); + String app = getMetricConfig().getString(LookoutConfig.APP_NAME); + if (StringUtils.isNotEmpty(app)) { + httpMtd.setHeader(APP_HEADER_NAME, app); + } if (metadata == null) { - metadata = new HashMap(); + return; } - metadata.putAll(commonMetadata); for (Map.Entry entry : metadata.entrySet()) { - httpPost.setHeader(entry.getKey(), entry.getValue()); + httpMtd.setHeader(entry.getKey(), entry.getValue()); } } diff --git a/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/HttpRequestProcessor.java b/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/HttpRequestProcessor.java index 96b0b90..0a6efcc 100644 --- a/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/HttpRequestProcessor.java +++ b/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/HttpRequestProcessor.java @@ -28,8 +28,6 @@ */ public interface HttpRequestProcessor { - void addCommonHeader(String headerName, String headerValue); - boolean sendPostRequest(HttpPost httpPost, Map metadata) throws IOException; boolean sendGetRequest(HttpGet httpGet, Map metadata) throws IOException; diff --git a/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/ReportDecider.java b/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/ReportDecider.java index 8e0b3c6..b688bc1 100644 --- a/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/ReportDecider.java +++ b/client/lookout-reg-server/src/main/java/com/alipay/lookout/remote/report/support/http/ReportDecider.java @@ -17,8 +17,10 @@ package com.alipay.lookout.remote.report.support.http; import com.alipay.lookout.common.log.LookoutLoggerFactory; +import com.alipay.lookout.core.config.MetricConfig; import com.alipay.lookout.remote.report.Address; import com.alipay.lookout.remote.report.AddressService; +import com.google.common.base.Preconditions; import org.apache.http.client.methods.HttpGet; import org.slf4j.Logger; @@ -39,10 +41,18 @@ public abstract class ReportDecider implements HttpRequestProcessor { private long expiredTime = 65000; //65s private AddressService addressService; + private MetricConfig metricConfig; - public ReportDecider(AddressService addressService) { + public ReportDecider(AddressService addressService, MetricConfig metricConfig) { + Preconditions.checkNotNull(addressService, "An addressService is required!"); + Preconditions.checkNotNull(metricConfig, "A metricConfig is required!"); this.addressService = addressService; this.addressLastModifiedTime = System.currentTimeMillis() - expiredTime; + this.metricConfig = metricConfig; + } + + protected MetricConfig getMetricConfig() { + return metricConfig; } public boolean stillSilent() { @@ -79,6 +89,7 @@ void refreshAddressCache() { Address oldOne = addressHolder.get(); Address newOne = addressService.getAgentServerHost(); if (newOne == null) { + logger.debug("No gateway address found!"); return; } //check new address @@ -100,7 +111,8 @@ void refreshAddressCache() { return; } catch (Throwable e) { logger.debug("check gateway address {} fail:{}. old address:{}!", newOne.ip(), - e.getMessage(), oldOne.ip()); + e.getMessage(), oldOne == null ? "" : oldOne.ip()); + } } diff --git a/client/lookout-reg-server/src/test/java/com/alipay/lookout/MockHttpRequestProcessor.java b/client/lookout-reg-server/src/test/java/com/alipay/lookout/MockHttpRequestProcessor.java index f6729be..5ddb759 100644 --- a/client/lookout-reg-server/src/test/java/com/alipay/lookout/MockHttpRequestProcessor.java +++ b/client/lookout-reg-server/src/test/java/com/alipay/lookout/MockHttpRequestProcessor.java @@ -42,11 +42,6 @@ public boolean sendGetRequest(HttpGet httpGet, Map metadata) thr return false; } - @Override - public void addCommonHeader(String headerName, String headerValue) { - - } - @Override public Address getAvailableAddress() { return new Address("localhost", 8080); diff --git a/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/HttpObserverTest.java b/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/HttpObserverTest.java index 4588247..90c4ea4 100644 --- a/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/HttpObserverTest.java +++ b/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/HttpObserverTest.java @@ -66,10 +66,6 @@ public void testGetBatches() { } class TestHttpRequestProcessor implements HttpRequestProcessor { - @Override - public void addCommonHeader(String headerName, String headerValue) { - - } @Override public Address getAvailableAddress() { diff --git a/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/HttpRequestProcessorTest.java b/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/HttpRequestProcessorTest.java index 0f6012a..d2e228d 100644 --- a/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/HttpRequestProcessorTest.java +++ b/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/HttpRequestProcessorTest.java @@ -16,6 +16,7 @@ */ package com.alipay.lookout.remote.report.support; +import com.alipay.lookout.core.config.LookoutConfig; import com.alipay.lookout.remote.report.DefaultAddressService; import com.alipay.lookout.remote.report.support.http.DefaultHttpRequestProcessor; import org.apache.http.Header; @@ -33,7 +34,8 @@ */ public class HttpRequestProcessorTest { final DefaultHttpRequestProcessor httpRequestProcessor = new DefaultHttpRequestProcessor( - new DefaultAddressService()); + new DefaultAddressService(), + new LookoutConfig()); @Test public void testHandleErrorResponse401() { diff --git a/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/http/DefaultHttpRequestProcessorTest.java b/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/http/DefaultHttpRequestProcessorTest.java index 0370947..a45ff0c 100644 --- a/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/http/DefaultHttpRequestProcessorTest.java +++ b/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/http/DefaultHttpRequestProcessorTest.java @@ -16,6 +16,7 @@ */ package com.alipay.lookout.remote.report.support.http; +import com.alipay.lookout.core.config.LookoutConfig; import com.alipay.lookout.remote.report.AddressService; import com.alipay.lookout.remote.report.DefaultAddressService; import org.apache.http.client.methods.HttpPost; @@ -41,7 +42,8 @@ public void testGetHttpClient() { @Test(expected = IOException.class) public void testSendPostFail() throws IOException { AddressService addressService = new DefaultAddressService(); - DefaultHttpRequestProcessor p = new DefaultHttpRequestProcessor(addressService); + DefaultHttpRequestProcessor p = new DefaultHttpRequestProcessor(addressService, + new LookoutConfig()); HttpPost httpPost = new HttpPost("http://localhost/ok"); try { httpPost.setEntity(new StringEntity("a")); diff --git a/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/http/ReportDeciderTest.java b/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/http/ReportDeciderTest.java index 728cb2c..65ec146 100644 --- a/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/http/ReportDeciderTest.java +++ b/client/lookout-reg-server/src/test/java/com/alipay/lookout/remote/report/support/http/ReportDeciderTest.java @@ -16,6 +16,7 @@ */ package com.alipay.lookout.remote.report.support.http; +import com.alipay.lookout.core.config.LookoutConfig; import com.alipay.lookout.remote.report.AddressService; import com.alipay.lookout.remote.report.DefaultAddressService; import org.apache.http.client.methods.HttpGet; @@ -51,12 +52,7 @@ public void testRefreshAddressCache() { class ReportDecider2 extends ReportDecider { public ReportDecider2(AddressService addressService) { - super(addressService); - } - - @Override - public void addCommonHeader(String headerName, String headerValue) { - + super(addressService, new LookoutConfig()); } @Override diff --git a/client/lookout-sofa-boot-starter/pom.xml b/client/lookout-sofa-boot-starter/pom.xml index 3c72732..576143f 100644 --- a/client/lookout-sofa-boot-starter/pom.xml +++ b/client/lookout-sofa-boot-starter/pom.xml @@ -6,7 +6,7 @@ com.alipay.sofa.lookout lookout-client-parent - 1.5.0 + 1.5.1 ../pom.xml diff --git a/client/pom.xml b/client/pom.xml index d12ded7..6ed1d9c 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -5,7 +5,7 @@ com.alipay.sofa.lookout lookout-client-parent - 1.5.0 + 1.5.1 pom ${project.groupId}:${project.artifactId} It is a library which allows you to instrument your app with custom metrics diff --git a/client/samples/lookout-client-samples-boot/pom.xml b/client/samples/lookout-client-samples-boot/pom.xml index 14ed066..760d533 100644 --- a/client/samples/lookout-client-samples-boot/pom.xml +++ b/client/samples/lookout-client-samples-boot/pom.xml @@ -21,7 +21,7 @@ UTF-8 UTF-8 1.8 - 1.5.0 + 1.5.1 diff --git a/client/samples/lookout-client-samples-dropwizard-boot/pom.xml b/client/samples/lookout-client-samples-dropwizard-boot/pom.xml index 62af0c8..ab0523e 100644 --- a/client/samples/lookout-client-samples-dropwizard-boot/pom.xml +++ b/client/samples/lookout-client-samples-dropwizard-boot/pom.xml @@ -21,7 +21,7 @@ UTF-8 UTF-8 1.8 - 1.5.0 + 1.5.1 diff --git a/client/samples/lookout-client-samples-java/README.md b/client/samples/lookout-client-samples-java/README.md index 9d1a154..4baffdc 100644 --- a/client/samples/lookout-client-samples-java/README.md +++ b/client/samples/lookout-client-samples-java/README.md @@ -4,4 +4,6 @@ Wait the following logs on the console: ``` ==> [{"time":"2018-06-05T16:41:00+08:00","tags":{"app":"appName","ip":"10.15... -``` \ No newline at end of file +``` + +- we also add log4j2 dependency in order to print client logs in home directory. \ No newline at end of file diff --git a/client/samples/lookout-client-samples-java/pom.xml b/client/samples/lookout-client-samples-java/pom.xml index 18c9f36..091097d 100644 --- a/client/samples/lookout-client-samples-java/pom.xml +++ b/client/samples/lookout-client-samples-java/pom.xml @@ -23,7 +23,7 @@ com.alipay.sofa.lookout lookout-client - 1.5.0 + 1.5.1 diff --git a/client/samples/lookout-client-samples-java/src/main/java/com/alipay/sofa/lookout/client/samples/DefaultLookoutClientDemo.java b/client/samples/lookout-client-samples-java/src/main/java/com/alipay/sofa/lookout/client/samples/DefaultLookoutClientDemo.java index 306757b..725664e 100644 --- a/client/samples/lookout-client-samples-java/src/main/java/com/alipay/sofa/lookout/client/samples/DefaultLookoutClientDemo.java +++ b/client/samples/lookout-client-samples-java/src/main/java/com/alipay/sofa/lookout/client/samples/DefaultLookoutClientDemo.java @@ -36,15 +36,19 @@ public static void main(String[] args) { //构建一个全局的客户端实例 final DefaultLookoutClient client = new DefaultLookoutClient("appName"); - //主动上报型 - LookoutRegistry lookoutRegistry = new LookoutRegistry(new LookoutConfig()); - //被动采集型 + LookoutConfig lookoutConfig=new LookoutConfig(); + //主动上报型 + //向远程 Agent(gateway)server上报metrics,必须的设置; + //lookoutConfig.setProperty(LookoutConfig.LOOKOUT_AGENT_HOST_ADDRESS,"10.101.92.239"); + LookoutRegistry lookoutRegistry = new LookoutRegistry(lookoutConfig); //set common tag example lookoutRegistry.setCommonTag("instant", "machine-a"); - //本地观察metrics定时打印 + //本地观察metrics定时打印(optional) lookoutRegistry.addMetricObserver(new StdoutObserver()); + + //可以 add 多个不同类型的 Registry 实例 client.addRegistry(lookoutRegistry); //注册扩展的metrics,下面两种方式都可以 diff --git a/client/samples/lookout-client-samples-prometheus/pom.xml b/client/samples/lookout-client-samples-prometheus/pom.xml index 363a28e..fa62cb5 100644 --- a/client/samples/lookout-client-samples-prometheus/pom.xml +++ b/client/samples/lookout-client-samples-prometheus/pom.xml @@ -21,7 +21,7 @@ UTF-8 UTF-8 1.8 - 1.5.0 + 1.5.1