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, "HBaseInfo");
40        mbeanName = MBeanUtil.registerMBean("HBase",
41            "Info", this);
42      }
43    
44      public void shutdown() {
45        if (mbeanName != null)
46          MBeanUtil.unregisterMBean(mbeanName);
47      }
48    }
49  
50    protected final MetricsRecord mr;
51    protected final HBaseInfoMBean mbean;
52    protected MetricsRegistry registry = new MetricsRegistry();
53  
54    private static HBaseInfo theInstance = null;
55    public synchronized static HBaseInfo init() {
56        if (theInstance == null) {
57          theInstance = new HBaseInfo();
58        }
59        return theInstance;
60    }
61    
62    // HBase jar info
63    private MetricsString date = new MetricsString("date", registry,
64        org.apache.hadoop.hbase.util.VersionInfo.getDate());
65    private MetricsString revision = new MetricsString("revision", registry, 
66        org.apache.hadoop.hbase.util.VersionInfo.getRevision());
67    private MetricsString url = new MetricsString("url", registry,
68        org.apache.hadoop.hbase.util.VersionInfo.getUrl());
69    private MetricsString user = new MetricsString("user", registry,
70        org.apache.hadoop.hbase.util.VersionInfo.getUser());
71    private MetricsString version = new MetricsString("version", registry,
72        org.apache.hadoop.hbase.util.VersionInfo.getVersion());
73  
74    // Info on the HDFS jar that HBase has (aka: HDFS Client)
75    private MetricsString hdfsDate = new MetricsString("hdfsDate", registry,
76        org.apache.hadoop.util.VersionInfo.getDate());
77    private MetricsString hdfsRev = new MetricsString("hdfsRevision", registry,
78        org.apache.hadoop.util.VersionInfo.getRevision());
79    private MetricsString hdfsUrl = new MetricsString("hdfsUrl", registry,
80        org.apache.hadoop.util.VersionInfo.getUrl());
81    private MetricsString hdfsUser = new MetricsString("hdfsUser", registry,
82        org.apache.hadoop.util.VersionInfo.getUser());
83    private MetricsString hdfsVer = new MetricsString("hdfsVersion", registry,
84        org.apache.hadoop.util.VersionInfo.getVersion());
85  
86    protected HBaseInfo() {
87      MetricsContext context = MetricsUtil.getContext("hbase");
88      mr = MetricsUtil.createRecord(context, "info");
89      String name = Thread.currentThread().getName();
90      mr.setTag("Info", name);
91  
92      // export for JMX
93      mbean = new HBaseInfoMBean(this.registry, name);
94    }
95  
96  }