Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify log info about fetching metrics #219

Merged
merged 1 commit into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,13 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(app, ip, port);
}

/**
* Information for log
*
* @return
*/
public String toLogString() {
return app + "|" + ip + "|" + port + "|" + version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@
@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<String, AtomicLong> appLastFetchTime = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -279,7 +278,7 @@ private void handleResponse(final HttpResponse response, MachineInfo machine,
} 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;
}
Expand Down Expand Up @@ -322,7 +321,7 @@ private void handleBody(String[] lines, MachineInfo machine, Map<String, MetricE
map.put(key, entity);
}
} catch (Exception e) {
logger.info("handleBody line error: {}", line);
logger.warn("handleBody line exception, machine: {}, line: {}", machine.toLogString(), line);
}
}
}
Expand Down