Search in sources :

Example 1 with Command

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

the class PerfPlugin method info.

@Command("info")
public CommandResponse info(Map<String, String> args) {
    try {
        CommandResponse<List<ThreadInfo>> threadResp = moduleCommandInvoker.invokeCommand(PerfConstants.MODULE_ID_THREAD, PerfConstants.MODULE_COMMAND_THREAD_INFO, threadParams);
        CommandResponse<GcInfo> gcResp = moduleCommandInvoker.invokeCommand(PerfConstants.MODULE_ID_GC, PerfConstants.MODULE_COMMAND_GC_INFO);
        CommandResponse<MemoryInfo> memoryResp = moduleCommandInvoker.invokeCommand(PerfConstants.MODULE_ID_MEMORY, PerfConstants.MODULE_COMMAND_MEMORY_INFO);
        List<ThreadInfo> threadInfos = Collections.EMPTY_LIST;
        if (!threadResp.isSuccess()) {
            logger.error("Perf: collect perf thread info err! {}", threadResp.getMessage());
        } else {
            threadInfos = threadResp.getResult();
        }
        GcInfo gcInfo = null;
        if (!gcResp.isSuccess()) {
            logger.error("Perf: collect perf gc info err! {}", gcResp.getMessage());
        } else {
            gcInfo = gcResp.getResult();
        }
        MemoryInfo memoryInfo = null;
        if (!memoryResp.isSuccess()) {
            logger.error("Perf: collect perf memory info err! {}", memoryResp.getMessage());
        } else {
            memoryInfo = memoryResp.getResult();
        }
        PerfResponse response = PerfResponseBuilder.build(threadInfos, gcInfo, memoryInfo);
        return CommandResponse.success(response);
    } catch (Throwable e) {
        logger.error("Perf: collect perf data occurred a unknow error. ", e);
        return CommandResponse.failure(e);
    }
}
Also used : MemoryInfo(com.shulie.instrument.simulator.module.model.memory.MemoryInfo) PerfResponse(com.shulie.instrument.simulator.perf.entity.PerfResponse) ThreadInfo(com.shulie.instrument.simulator.module.model.thread.ThreadInfo) GcInfo(com.shulie.instrument.simulator.module.model.gc.GcInfo) List(java.util.List) Command(com.shulie.instrument.simulator.api.annotation.Command)

Example 2 with Command

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

the class ConfigFetcherModule method getSimulatorDetail.

/**
 * 获取simulator配置的接口,目前只获取静默开关状态
 * @param args
 * @return
 */
@Command("getSimulatorDetail")
public CommandResponse<Object> getSimulatorDetail(Map<String, String> args) {
    SimulatorDetail simulatorDetail = new SimulatorDetail();
    simulatorDetail.setIsSilent(PradarSwitcher.silenceSwitchOn() == true ? 1 : 0);
    CommandResponse<Object> commandResponse = new CommandResponse<Object>();
    commandResponse.setSuccess(true);
    commandResponse.setResult(simulatorDetail);
    return commandResponse;
}
Also used : SimulatorDetail(com.shulie.instrument.module.config.fetcher.config.SimulatorDetail) CommandResponse(com.shulie.instrument.simulator.api.CommandResponse) Command(com.shulie.instrument.simulator.api.annotation.Command)

Example 3 with Command

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

the class ModuleHttpServlet method matchingModuleMethod.

/**
 * 匹配模块中复合HTTP请求路径的方法
 * 匹配方法的方式是:HttpMethod和HttpPath全匹配
 *
 * @param path          HTTP请求路径
 * @param moduleId      模块ID
 * @param classOfModule 模块类
 * @return 返回匹配上的方法,如果没有找到匹配方法则返回null
 */
private Method matchingModuleMethod(final String path, final String moduleId, final Class<?> classOfModule) {
    // 查找@Command注解的方法
    for (final Method method : getMethodsListWithAnnotation(classOfModule, Command.class)) {
        final Command commandAnnotation = method.getAnnotation(Command.class);
        if (null == commandAnnotation) {
            continue;
        }
        // 兼容 value 是否以 / 开头的写法
        String cmd = appendSlash(commandAnnotation.value());
        final String pathOfCmd = "/" + moduleId + cmd;
        if (StringUtils.equals(path, pathOfCmd)) {
            return method;
        }
    }
    // 找不到匹配方法,返回null
    return null;
}
Also used : Command(com.shulie.instrument.simulator.api.annotation.Command) Method(java.lang.reflect.Method)

Example 4 with Command

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

the class ScModule method sc.

@Command(value = "sc", description = "查找类")
public CommandResponse sc(final Map<String, String> param) {
    try {
        final String cnPattern = getParameter(param, "class");
        final String type = getParameter(param, "type");
        if (StringUtils.isBlank(type)) {
            Set<Class<?>> classes = loadedClassDataSource.find(new NameRegexFilter(cnPattern, ".*", true, true));
            List<String> classNames = new ArrayList<String>();
            for (Class<?> clazz : classes) {
                String name = clazz.getCanonicalName() + " " + clazz.getClassLoader().toString();
                classNames.add(name);
            }
            return CommandResponse.success(classNames);
        } else if (StringUtils.equals("s", type)) {
            Set<Class<?>> classes = loadedClassDataSource.find(new SuperNameRegexFilter(cnPattern, ".*", true, true));
            List<String> classNames = new ArrayList<String>();
            for (Class<?> clazz : classes) {
                String name = clazz.getCanonicalName() + " " + clazz.getClassLoader().toString();
                classNames.add(name);
            }
            return CommandResponse.success(classNames);
        } else if (StringUtils.equals("i", type)) {
            Set<Class<?>> classes = loadedClassDataSource.find(new InterfaceNameRegexFilter(cnPattern, ".*", true, true));
            List<String> classNames = new ArrayList<String>();
            for (Class<?> clazz : classes) {
                String name = clazz.getCanonicalName() + " " + clazz.getClassLoader().toString();
                classNames.add(name);
            }
            return CommandResponse.success(classNames);
        }
        return CommandResponse.failure("Unsupported type value:" + type);
    } catch (Throwable e) {
        return CommandResponse.failure(e);
    }
}
Also used : SuperNameRegexFilter(com.shulie.instrument.simulator.module.util.SuperNameRegexFilter) SuperNameRegexFilter(com.shulie.instrument.simulator.module.util.SuperNameRegexFilter) InterfaceNameRegexFilter(com.shulie.instrument.simulator.module.util.InterfaceNameRegexFilter) NameRegexFilter(com.shulie.instrument.simulator.api.filter.NameRegexFilter) Set(java.util.Set) ArrayList(java.util.ArrayList) InterfaceNameRegexFilter(com.shulie.instrument.simulator.module.util.InterfaceNameRegexFilter) ArrayList(java.util.ArrayList) List(java.util.List) Command(com.shulie.instrument.simulator.api.annotation.Command)

Example 5 with Command

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

the class StackModule method info.

@Command(value = "info", description = "查看方法执行线程堆栈")
public CommandResponse info(Map<String, String> args) {
    final String classPattern = args.get("class");
    final String methodPattern = args.get("method");
    final String type = args.get("pattenType");
    final int wait = ParameterUtils.getInt(args, "wait", 5000);
    final int patternType = PatternType.of(type);
    if (StringUtils.isBlank(classPattern)) {
        return CommandResponse.failure("class can't be empty.");
    }
    if (StringUtils.isBlank(methodPattern)) {
        return CommandResponse.failure("method can't be empty.");
    }
    if (!hasClass(classPattern, patternType)) {
        return CommandResponse.failure("class is not found with patternType :" + PatternType.name(patternType) + "! " + classPattern);
    }
    CountDownLatch latch = new CountDownLatch(1);
    EventWatcher watcher = null;
    try {
        List list = new ArrayList();
        watcher = new EventWatchBuilder(moduleEventWatcher).onClass(classPattern).onAnyBehavior(methodPattern).withInvoke().onListener(Listeners.of(StackListener.class, new Object[] { latch, list })).onClass().onWatch();
        if (wait <= 0) {
            latch.wait();
        } else {
            latch.await(wait, TimeUnit.SECONDS);
        }
        return CommandResponse.success(list);
    } catch (Throwable e) {
        return CommandResponse.failure("get [" + classPattern + "] [" + methodPattern + "] stack error!", e);
    } finally {
        if (watcher != null) {
            watcher.onUnWatched();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) EventWatcher(com.shulie.instrument.simulator.api.listener.ext.EventWatcher) ModuleEventWatcher(com.shulie.instrument.simulator.api.resource.ModuleEventWatcher) ArrayList(java.util.ArrayList) List(java.util.List) EventWatchBuilder(com.shulie.instrument.simulator.api.listener.ext.EventWatchBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) 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