1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import java.util.concurrent.ConcurrentHashMap;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
27 import org.apache.hadoop.hbase.metrics.Interns;
28 import org.apache.hadoop.metrics2.MetricsCollector;
29 import org.apache.hadoop.metrics2.MetricsRecordBuilder;
30
31 @InterfaceAudience.Private
32 public class MetricsTableAggregateSourceImpl extends BaseSourceImpl
33 implements MetricsTableAggregateSource {
34
35 private static final Log LOG = LogFactory.getLog(MetricsTableAggregateSourceImpl.class);
36 private ConcurrentHashMap<String, MetricsTableSource> tableSources = new ConcurrentHashMap<>();
37
38 public MetricsTableAggregateSourceImpl() {
39 this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
40 }
41
42 public MetricsTableAggregateSourceImpl(String metricsName,
43 String metricsDescription,
44 String metricsContext,
45 String metricsJmxContext) {
46 super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
47 }
48
49 @Override
50 public void register(String table, MetricsTableSource source) {
51 tableSources.put(table, source);
52 }
53
54 @Override
55 public void deregister(String table) {
56 try {
57 tableSources.remove(table);
58 } catch (Exception e) {
59
60
61 LOG.info(
62 "Error trying to remove " + table + " from " + this.getClass().getSimpleName(),
63 e);
64 }
65 }
66
67
68
69
70
71
72
73
74
75 @Override
76 public void getMetrics(MetricsCollector collector, boolean all) {
77 MetricsRecordBuilder mrb = collector.addRecord(metricsName);
78
79 if (tableSources != null) {
80 for (MetricsTableSource tableMetricSource : tableSources.values()) {
81 if (tableMetricSource instanceof MetricsTableSourceImpl) {
82 ((MetricsTableSourceImpl) tableMetricSource).snapshot(mrb, all);
83 }
84 }
85 mrb.addGauge(Interns.info(NUM_TABLES, NUMBER_OF_TABLES_DESC), tableSources.size());
86 metricsRegistry.snapshot(mrb, all);
87 }
88 }
89 }