2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org
.apache
.hadoop
.hbase
.regionserver
;
19 import java
.io
.IOException
;
20 import java
.io
.PrintWriter
;
21 import java
.io
.StringWriter
;
22 import java
.lang
.management
.ManagementFactory
;
23 import javax
.management
.MBeanServer
;
24 import javax
.management
.MalformedObjectNameException
;
25 import javax
.management
.ObjectName
;
26 import org
.apache
.hadoop
.hbase
.util
.JSONBean
;
27 import org
.apache
.yetus
.audience
.InterfaceAudience
;
30 * Utility for doing JSON and MBeans.
32 @InterfaceAudience.Private
33 public final class DumpRegionServerMetrics
{
35 * Dump out a subset of regionserver mbeans only, not all of them, as json on System.out.
37 public static String
dumpMetrics() throws MalformedObjectNameException
, IOException
{
38 StringWriter sw
= new StringWriter(1024 * 100); // Guess this size
39 try (PrintWriter writer
= new PrintWriter(sw
)) {
40 JSONBean dumper
= new JSONBean();
41 try (JSONBean
.Writer jsonBeanWriter
= dumper
.open(writer
)) {
42 MBeanServer mbeanServer
= ManagementFactory
.getPlatformMBeanServer();
43 jsonBeanWriter
.write(mbeanServer
,
44 new ObjectName("java.lang:type=Memory"), null, false);
45 jsonBeanWriter
.write(mbeanServer
,
46 new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=IPC"), null, false);
47 jsonBeanWriter
.write(mbeanServer
,
48 new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Replication"), null, false);
49 jsonBeanWriter
.write(mbeanServer
,
50 new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Server"), null, false);
57 public static void main(String
[] args
) throws IOException
, MalformedObjectNameException
{
58 String str
= dumpMetrics();
59 System
.out
.println(str
);
62 private DumpRegionServerMetrics() {}