From ef96b15f226dae073c048d142f4eb4336fe7ae27 Mon Sep 17 00:00:00 2001 From: xcaspar Date: Thu, 1 Nov 2018 14:16:11 +0800 Subject: [PATCH] Improve log info and condition about fetching metrics (#219) - Receiving "No metrics" response won't cause error log - Improve log about fetching metrics --- .../csp/sentinel/dashboard/discovery/MachineInfo.java | 9 +++++++++ .../csp/sentinel/dashboard/metric/MetricFetcher.java | 11 +++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/MachineInfo.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/MachineInfo.java index 67db4f4b..dba7fe6c 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/MachineInfo.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/discovery/MachineInfo.java @@ -130,4 +130,13 @@ public class MachineInfo implements Comparable { public int hashCode() { return Objects.hash(app, ip, port); } + + /** + * Information for log + * + * @return + */ + public String toLogString() { + return app + "|" + ip + "|" + port + "|" + version; + } } diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/metric/MetricFetcher.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/metric/MetricFetcher.java index 6ffd2b78..f2a747d6 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/metric/MetricFetcher.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/metric/MetricFetcher.java @@ -64,15 +64,14 @@ import org.springframework.stereotype.Component; @Component public class MetricFetcher { - private static Logger logger = LoggerFactory.getLogger(MetricFetcher.class); - private static final int HTTP_OK = 200; - public static final long MAX_CLIENT_LIVE_TIME_MS = 1000 * 60 * 5; + public static final String NO_METRICS = "No metrics"; + private static final int HTTP_OK = 200; private static final long MAX_LAST_FETCH_INTERVAL_MS = 1000 * 15; private static final long FETCH_INTERVAL_SECOND = 6; private static final Charset DEFAULT_CHARSET = Charset.forName(SentinelConfig.charset()); private final static String METRIC_URL_PATH = "metric"; - + private static Logger logger = LoggerFactory.getLogger(MetricFetcher.class); private final long intervalSecond = 1; private Map appLastFetchTime = new ConcurrentHashMap<>(); @@ -279,7 +278,7 @@ public class MetricFetcher { } catch (Exception ignore) { } String body = EntityUtils.toString(response.getEntity(), charset != null ? charset : DEFAULT_CHARSET); - if (StringUtil.isEmpty(body)) { + if (StringUtil.isEmpty(body) || body.startsWith(NO_METRICS)) { //logger.info(machine.getApp() + ":" + machine.getIp() + ":" + machine.getPort() + ", bodyStr is empty"); return; } @@ -322,7 +321,7 @@ public class MetricFetcher { map.put(key, entity); } } catch (Exception e) { - logger.info("handleBody line error: {}", line); + logger.warn("handleBody line exception, machine: {}, line: {}", machine.toLogString(), line); } } }