Search in sources :

Example 26 with Command

use of com.shulie.instrument.simulator.api.annotation.Command in project LinkAgent by shulieTech.

the class GcModule method info.

@Command(value = "info", description = "获取当前进程的 gc 信息")
public CommandResponse info(final Map<String, String> args) {
    try {
        List<GarbageCollectorMXBean> garbageCollectorMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
        GcInfo gcInfo = new GcInfo();
        for (GarbageCollectorMXBean gcMXBean : garbageCollectorMxBeans) {
            String name = gcMXBean.getName();
            if (youngGcNames.contains(name)) {
                gcInfo.setYoungGcCount(gcMXBean.getCollectionCount());
                gcInfo.setYoungGcTime(gcMXBean.getCollectionTime());
            } else if (oldGcNames.contains(name)) {
                gcInfo.setOldGcCount(gcMXBean.getCollectionCount());
                gcInfo.setOldGcTime(gcMXBean.getCollectionTime());
            }
        }
        return CommandResponse.success(gcInfo);
    } catch (Throwable e) {
        return CommandResponse.failure(e);
    }
}
Also used : GcInfo(com.shulie.instrument.simulator.module.model.gc.GcInfo) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) Command(com.shulie.instrument.simulator.api.annotation.Command)

Example 27 with Command

use of com.shulie.instrument.simulator.api.annotation.Command in project LinkAgent by shulieTech.

the class HeapDumpModule method heapdump.

@Command(value = "dump", description = "dump 内存")
public CommandResponse heapdump(final Map<String, String> args) {
    try {
        String dumpFile = args.get("file");
        boolean live = ParameterUtils.getBoolean(args, "live", true);
        if (dumpFile == null || dumpFile.isEmpty()) {
            String date = sdf.get().format(new Date());
            File file = File.createTempFile("heapdump-" + date + (live ? "-live" : ""), ".hprof");
            dumpFile = file.getAbsolutePath();
            file.delete();
        }
        if (JvmUtils.supportsVersion(JvmVersion.JAVA_7)) {
            run(dumpFile, live);
            return CommandResponse.success(dumpFile);
        } else {
            final String bashCommand = (new StringBuilder("nohup sh ").append(simulatorConfig.getSimulatorHome()).append("/bin/dump.sh ").append(dumpFile).append(" ").append(RuntimeUtils.getPid()).append(" ").append(live)).append(" ").append("&").toString();
            execute(bashCommand);
            if (new File(dumpFile + ".finished").exists()) {
                new File(dumpFile + ".finished").delete();
                return CommandResponse.success(dumpFile);
            }
        }
        return CommandResponse.failure("heapdump execute failed. please retry it later!");
    } catch (NoSuchMethodError e) {
        return CommandResponse.failure("dumpheap is not supported in this jdk version");
    } catch (NoClassDefFoundError e) {
        return CommandResponse.failure("dumpheap is not supported in this jdk version");
    } catch (Throwable e) {
        return CommandResponse.failure(e);
    }
}
Also used : File(java.io.File) Date(java.util.Date) Command(com.shulie.instrument.simulator.api.annotation.Command)

Aggregations

Command (com.shulie.instrument.simulator.api.annotation.Command)27 ArrayList (java.util.ArrayList)10 EventWatchBuilder (com.shulie.instrument.simulator.api.listener.ext.EventWatchBuilder)5 EventWatcher (com.shulie.instrument.simulator.api.listener.ext.EventWatcher)5 ModuleEventWatcher (com.shulie.instrument.simulator.api.resource.ModuleEventWatcher)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 File (java.io.File)4 Method (java.lang.reflect.Method)3 List (java.util.List)3 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)3 PullLogResponse (com.shulie.instrument.module.log.data.pusher.log.PullLogResponse)2 NameRegexFilter (com.shulie.instrument.simulator.api.filter.NameRegexFilter)2 ModuleInf (com.shulie.instrument.simulator.module.mgr.model.ModuleInf)2 GcInfo (com.shulie.instrument.simulator.module.model.gc.GcInfo)2 MemoryInfo (com.shulie.instrument.simulator.module.model.memory.MemoryInfo)2 HotSpotDiagnosticMXBean (com.sun.management.HotSpotDiagnosticMXBean)2 VMOption (com.sun.management.VMOption)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 JSONObject (com.alibaba.fastjson.JSONObject)1