1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase;
19
20 import java.util.Map;
21 import org.apache.hadoop.hbase.classification.InterfaceAudience;
22 import org.apache.hadoop.hbase.executor.ExecutorService;
23 import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorStatus;
24 import org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource;
25 import org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceImpl;
26 import org.apache.hadoop.hbase.util.Pair;
27 import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry;
28 import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
29 import org.apache.hadoop.util.StringUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37 @InterfaceAudience.Private
38 public class ExecutorStatusChore extends ScheduledChore {
39 private static final Logger LOG = LoggerFactory.getLogger(HealthCheckChore.class);
40 public static final String WAKE_FREQ = "hbase.executors.status.collect.period";
41 public static final int DEFAULT_WAKE_FREQ = 60000;
42 private ExecutorService service;
43 private DynamicMetricsRegistry metricsRegistry;
44
45 public ExecutorStatusChore(int sleepTime, Stoppable stopper, ExecutorService service,
46 MetricsRegionServerSource metrics) {
47 super("ExecutorStatusChore", stopper, sleepTime);
48 LOG.info("ExecutorStatusChore runs every {} ", StringUtils.formatTime(sleepTime));
49 this.service = service;
50 this.metricsRegistry = ((MetricsRegionServerSourceImpl) metrics).getMetricsRegistry();
51 }
52
53 @Override
54 protected void chore() {
55 try{
56
57 Map<String, ExecutorStatus> statuses = service.getAllExecutorStatuses();
58 for (Map.Entry<String, ExecutorStatus> statusEntry : statuses.entrySet()) {
59 String name = statusEntry.getKey();
60
61
62 String poolName = name.split("-")[0];
63 ExecutorStatus status = statusEntry.getValue();
64 MutableGaugeLong queued = metricsRegistry.getGauge(poolName + "_queued", 0L);
65 MutableGaugeLong running = metricsRegistry.getGauge(poolName + "_running", 0L);
66 int queueSize = status.getQueuedEvents().size();
67 int runningSize = status.getRunning().size();
68 if (queueSize > 0) {
69 LOG.warn("{}'s size info, queued: {}, running: {}", poolName, queueSize, runningSize);
70 }
71 queued.set(queueSize);
72 running.set(runningSize);
73 }
74 } catch(Throwable e) {
75 LOG.error(e.getMessage(), e);
76 }
77 }
78
79 public Pair<Long, Long> getExecutorStatus(String poolName) {
80 MutableGaugeLong running = metricsRegistry.getGauge(poolName + "_running", 0L);
81 MutableGaugeLong queued = metricsRegistry.getGauge(poolName + "_queued", 0L);
82 return new Pair<Long, Long>(running.value(), queued.value());
83 }
84 }