public static void start(String cfgPath) {

        if (!started.compareAndSet(false, true)) {
            return;
        }

        try {
            MonitorCfg cfg = MonitorCfgLoader.load(cfgPath);

            agent.setRegistryAddress(cfg.getRegistryAddress());
            agent.setClusterName(cfg.getClusterName());
            if (StringUtils.isNotEmpty(cfg.getBindIp())) {
                agent.setBindIp(cfg.getBindIp());
            }
            if (StringUtils.isNotEmpty(cfg.getIdentity())) {
                agent.setIdentity(cfg.getIdentity());
            }
            for (Map.Entry<String, String> config : cfg.getConfigs().entrySet()) {
                agent.addConfig(config.getKey(), config.getValue());
            }

            agent.start();

            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
                @Override
                public void run() {
                    agent.stop();
                }
            }));

        } catch (CfgException e) {
            System.err.println("Monitor Startup Error: " + e.getMessage());
            e.printStackTrace();
        }
    }
@author Robert HG (254963746@qq.com) on 3/5/16.
lts-monitor/src/main/java/com/github/ltsopensource/monitor/MonitorAgentStartup.java