Skip to content

Commit

Permalink
Merge pull request alibaba#612 from alibaba/feature_metrics
Browse files Browse the repository at this point in the history
surpport metrics
  • Loading branch information
Fury Zhu authored Jan 11, 2019
2 parents 84a64d3 + 5891ae0 commit f82e080
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public HttpResult httpPost(String path, List<String> headers, List<String> param
long end = 0;
HttpResult result = null;
try {
result = httpAgent.httpGet(path, headers, paramValues, encoding, readTimeoutMs);
result = httpAgent.httpPost(path, headers, paramValues, encoding, readTimeoutMs);
} catch (IOException e) {
end = System.currentTimeMillis();
MetricsMonitor.getConfigRequestMonitor("POST", path, "NA").record(end - start, TimeUnit.MILLISECONDS);
Expand All @@ -84,7 +84,7 @@ public HttpResult httpDelete(String path, List<String> headers, List<String> par
long end = 0;
HttpResult result = null;
try {
result = httpAgent.httpGet(path, headers, paramValues, encoding, readTimeoutMs);
result = httpAgent.httpDelete(path, headers, paramValues, encoding, readTimeoutMs);
} catch (IOException e) {
end = System.currentTimeMillis();
MetricsMonitor.getConfigRequestMonitor("DELETE", path, "NA").record(end - start, TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,40 @@ private void start() {
}

@Scheduled(cron = "0 0 0 * * ?")
public void refresh() {
public void refreshMetrics() {
PushService.setFailedPush(0);
PushService.setTotalPush(0);
MetricsMonitor.getHttpHealthCheckMonitor().set(0);
MetricsMonitor.getMysqlHealthCheckMonitor().set(0);
MetricsMonitor.getTcpHealthCheckMonitor().set(0);
}

@Scheduled(cron = "0/15 * * * * ?")
public void collectmetrics() {
int domCount = domainsManager.getDomCount();
MetricsMonitor.getDomCountMonitor().set(domCount);

int ipCount = domainsManager.getIPCount();
MetricsMonitor.getIpCountMonitor().set(ipCount);

long maxPushCost = getMaxPushCost();
MetricsMonitor.getMaxPushCostMonitor().set(maxPushCost);

long avgPushCost = getAvgPushCost();
MetricsMonitor.getAvgPushCostMonitor().set(avgPushCost);

MetricsMonitor.getTotalPushMonitor().set(PushService.getTotalPush());
MetricsMonitor.getFailedPushMonitor().set(PushService.getFailedPushCount());

if (RaftCore.isLeader()) {
MetricsMonitor.getLeaderStatusMonitor().set(1);
} else if (RaftCore.getPeerSet().local().state == FOLLOWER) {
MetricsMonitor.getLeaderStatusMonitor().set(0);
} else {
MetricsMonitor.getLeaderStatusMonitor().set(2);
}
}

class AllDomNamesTask implements Runnable {

@Override
Expand All @@ -113,27 +139,9 @@ class PerformanceLogTask implements Runnable {
public void run() {
try {
int domCount = domainsManager.getDomCount();
MetricsMonitor.getDomCountMonitor().set(domCount);

int ipCount = domainsManager.getIPCount();
MetricsMonitor.getIpCountMonitor().set(ipCount);

long maxPushCost = getMaxPushCost();
MetricsMonitor.getMaxPushCostMonitor().set(maxPushCost);

long avgPushCost = getAvgPushCost();
MetricsMonitor.getAvgPushCostMonitor().set(avgPushCost);

MetricsMonitor.getTotalPushMonitor().set(PushService.getTotalPush());
MetricsMonitor.getFailedPushMonitor().set(PushService.getFailedPushCount());

if (RaftCore.isLeader()) {
MetricsMonitor.getLeaderStatusMonitor().set(1);
} else if (RaftCore.getPeerSet().local().state == FOLLOWER) {
MetricsMonitor.getLeaderStatusMonitor().set(0);
} else {
MetricsMonitor.getLeaderStatusMonitor().set(2);
}

Loggers.PERFORMANCE_LOG.info("PERFORMANCE:" + "|" + domCount + "|" + ipCount + "|" + maxPushCost + "|" + avgPushCost);
} catch (Exception e) {
Expand Down

0 comments on commit f82e080

Please sign in to comment.