HBASE-3223 Get VersionInfo for Running HBase Process

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1040280 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2010-11-29 20:46:00 +00:00
parent c799c5cc83
commit eb3beb9c24
2 changed files with 152 additions and 0 deletions

View File

@ -0,0 +1,96 @@
/**
* Copyright 2010 The Apache Software Foundation
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.metrics;
import org.apache.hadoop.hbase.metrics.MetricsMBeanBase;
import org.apache.hadoop.metrics.MetricsContext;
import org.apache.hadoop.metrics.MetricsRecord;
import org.apache.hadoop.metrics.MetricsUtil;
import org.apache.hadoop.metrics.util.MBeanUtil;
import org.apache.hadoop.metrics.util.MetricsRegistry;
import javax.management.ObjectName;
/**
* Exports HBase system information as an MBean for JMX observation.
*/
public class HBaseInfo {
protected static class HBaseInfoMBean extends MetricsMBeanBase {
private final ObjectName mbeanName;
public HBaseInfoMBean(MetricsRegistry registry, String rsName) {
super(registry, "HBaseInfo");
mbeanName = MBeanUtil.registerMBean("HBase",
"Info", this);
}
public void shutdown() {
if (mbeanName != null)
MBeanUtil.unregisterMBean(mbeanName);
}
}
protected final MetricsRecord mr;
protected final HBaseInfoMBean mbean;
protected MetricsRegistry registry = new MetricsRegistry();
private static HBaseInfo theInstance = null;
public synchronized static HBaseInfo init() {
if (theInstance == null) {
theInstance = new HBaseInfo();
}
return theInstance;
}
// HBase jar info
private MetricsString date = new MetricsString("date", registry,
org.apache.hadoop.hbase.util.VersionInfo.getDate());
private MetricsString revision = new MetricsString("revision", registry,
org.apache.hadoop.hbase.util.VersionInfo.getRevision());
private MetricsString url = new MetricsString("url", registry,
org.apache.hadoop.hbase.util.VersionInfo.getUrl());
private MetricsString user = new MetricsString("user", registry,
org.apache.hadoop.hbase.util.VersionInfo.getUser());
private MetricsString version = new MetricsString("version", registry,
org.apache.hadoop.hbase.util.VersionInfo.getVersion());
// Info on the HDFS jar that HBase has (aka: HDFS Client)
private MetricsString hdfsDate = new MetricsString("hdfsDate", registry,
org.apache.hadoop.util.VersionInfo.getDate());
private MetricsString hdfsRev = new MetricsString("hdfsRevision", registry,
org.apache.hadoop.util.VersionInfo.getRevision());
private MetricsString hdfsUrl = new MetricsString("hdfsUrl", registry,
org.apache.hadoop.util.VersionInfo.getUrl());
private MetricsString hdfsUser = new MetricsString("hdfsUser", registry,
org.apache.hadoop.util.VersionInfo.getUser());
private MetricsString hdfsVer = new MetricsString("hdfsVersion", registry,
org.apache.hadoop.util.VersionInfo.getVersion());
protected HBaseInfo() {
MetricsContext context = MetricsUtil.getContext("hbase");
mr = MetricsUtil.createRecord(context, "info");
String name = Thread.currentThread().getName();
mr.setTag("Info", name);
// export for JMX
mbean = new HBaseInfoMBean(this.registry, name);
}
}

View File

@ -0,0 +1,56 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.metrics;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.metrics.MetricsRecord;
import org.apache.hadoop.metrics.util.MetricsBase;
import org.apache.hadoop.metrics.util.MetricsRegistry;
/**
* Publishes a string to the metrics collector
*/
public class MetricsString extends MetricsBase {
private static final Log LOG = LogFactory.getLog("org.apache.hadoop.hbase.metrics");
private String value;
public MetricsString(final String name, final MetricsRegistry registry,
final String value) {
super(name, NO_DESCRIPTION);
this.value = value;
registry.add(name, this);
}
public MetricsString(final String name, final String description,
final MetricsRegistry registry, final String value) {
super(name, description);
this.value = value;
registry.add(name, this);
}
public String getValue() {
return this.value;
}
@Override
public synchronized void pushMetric(final MetricsRecord mr) {
// NOOP
// MetricsMBeanBase.getAttribute is where we actually fill the data
}
}