View Javadoc

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