View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.metrics;
20  
21  import org.apache.hadoop.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.metrics.MetricsMBeanBase;
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.util.MBeanUtil;
27  import org.apache.hadoop.metrics.util.MetricsRegistry;
28  
29  import javax.management.ObjectName;
30  
31  /**
32   * Exports HBase system information as an MBean for JMX observation.
33   */
34  @Deprecated
35  @InterfaceAudience.Private
36  public class HBaseInfo {
37    protected static class HBaseInfoMBean extends MetricsMBeanBase {
38      private final ObjectName mbeanName;
39    
40      public HBaseInfoMBean(MetricsRegistry registry, String rsName) {
41        super(registry, "HBase cluster information");
42        // The name seems wrong to me; should include clusterid IMO.
43        // That would make it harder to locate and rare we have
44        // two clusters up on single machine. St.Ack 20120309
45        mbeanName = MBeanUtil.registerMBean("HBase", "Info", this);
46      }
47    
48      public void shutdown() {
49        if (mbeanName != null)
50          MBeanUtil.unregisterMBean(mbeanName);
51      }
52    }
53  
54    protected final MetricsRecord mr;
55    protected final HBaseInfoMBean mbean;
56    protected MetricsRegistry registry = new MetricsRegistry();
57  
58    private static HBaseInfo theInstance = null;
59    public synchronized static HBaseInfo init() {
60        if (theInstance == null) {
61          theInstance = new HBaseInfo();
62        }
63        return theInstance;
64    }
65    
66    {
67      // HBase jar info
68      new MetricsString("date", registry,
69          org.apache.hadoop.hbase.util.VersionInfo.getDate());
70      new MetricsString("revision", registry,
71          org.apache.hadoop.hbase.util.VersionInfo.getRevision());
72      new MetricsString("url", registry, org.apache.hadoop.hbase.util.VersionInfo
73          .getUrl());
74      new MetricsString("user", registry,
75          org.apache.hadoop.hbase.util.VersionInfo.getUser());
76      new MetricsString("version", registry,
77          org.apache.hadoop.hbase.util.VersionInfo.getVersion());
78  
79      // Info on the HDFS jar that HBase has (aka: HDFS Client)
80      new MetricsString("hdfsDate", registry, org.apache.hadoop.util.VersionInfo
81          .getDate());
82      new MetricsString("hdfsRevision", registry,
83          org.apache.hadoop.util.VersionInfo.getRevision());
84      new MetricsString("hdfsUrl", registry, org.apache.hadoop.util.VersionInfo
85          .getUrl());
86      new MetricsString("hdfsUser", registry, org.apache.hadoop.util.VersionInfo
87          .getUser());
88      new MetricsString("hdfsVersion", registry,
89          org.apache.hadoop.util.VersionInfo.getVersion());
90    }
91  
92    protected HBaseInfo() {
93      MetricsContext context = MetricsUtil.getContext("hbase");
94      mr = MetricsUtil.createRecord(context, "info");
95      String name = Thread.currentThread().getName();
96      mr.setTag("Info", name);
97  
98      // export for JMX
99      mbean = new HBaseInfoMBean(this.registry, name);
100   }
101 
102 }