1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.master.metrics;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.hadoop.hbase.metrics.MetricsRate;
23 import org.apache.hadoop.metrics.MetricsContext;
24 import org.apache.hadoop.metrics.MetricsRecord;
25 import org.apache.hadoop.metrics.MetricsUtil;
26 import org.apache.hadoop.metrics.Updater;
27 import org.apache.hadoop.metrics.jvm.JvmMetrics;
28 import org.apache.hadoop.metrics.util.MetricsRegistry;
29
30
31
32
33
34
35
36
37
38 public class MasterMetrics implements Updater {
39 private final Log LOG = LogFactory.getLog(this.getClass());
40 private final MetricsRecord metricsRecord;
41 private final MetricsRegistry registry = new MetricsRegistry();
42 private final MasterStatistics masterStatistics;
43
44
45
46 private final MetricsRate cluster_requests =
47 new MetricsRate("cluster_requests", registry);
48
49 public MasterMetrics(final String name) {
50 MetricsContext context = MetricsUtil.getContext("hbase");
51 metricsRecord = MetricsUtil.createRecord(context, "master");
52 metricsRecord.setTag("Master", name);
53 context.registerUpdater(this);
54 JvmMetrics.init("Master", name);
55
56
57 masterStatistics = new MasterStatistics(this.registry);
58
59 LOG.info("Initialized");
60 }
61
62 public void shutdown() {
63 if (masterStatistics != null)
64 masterStatistics.shutdown();
65 }
66
67
68
69
70
71
72 public void doUpdates(MetricsContext unused) {
73 synchronized (this) {
74 this.cluster_requests.pushMetric(metricsRecord);
75 }
76 this.metricsRecord.update();
77 }
78
79 public void resetAllMinMax() {
80
81 }
82
83
84
85
86 public float getRequests() {
87 return this.cluster_requests.getPreviousIntervalValue();
88 }
89
90
91
92
93 public void incrementRequests(final int inc) {
94 this.cluster_requests.inc(inc);
95 }
96 }