com.shulie.druid.support.console.DruidStat Maven / Gradle / Ivy
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.shulie.druid.support.console;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import com.shulie.druid.stat.DruidStatService;
import com.shulie.druid.support.json.JSONUtils;
import com.sun.tools.attach.AgentInitializationException;
import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
public class DruidStat {
private static final String LOCAL_CONNECTOR_ADDRESS_PROP = "com.sun.management.jmxremote.localConnectorAddress";
public static void main(String[] args) throws Exception {
Option opt = null;
if (Option.isPrintHelp(args)) {
Option.printHelp();
return;
}
try {
opt = Option.parseOptions(args);
} catch (OptionParseException e) {
Option.printHelp(e.getMessage());
return;
}
printDruidStat(opt);
}
@SuppressWarnings("all")
public static void printDruidStat(Option option) throws Exception {
PrintStream out = option.getPrintStream();
String address = loadManagementAgentAndGetAddress(option.getPid());
JMXServiceURL jmxUrl = new JMXServiceURL(address);
JMXConnector jmxc = JMXConnectorFactory.connect(jmxUrl);
MBeanServerConnection jmxConn = jmxc.getMBeanServerConnection();
if (option.printDataSourceData()) {
List