Search in sources :

Example 16 with Command

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

the class LogDataPusherModule method pullAgentLog.

@Command("pullAgentLog")
public CommandResponse pullAgentLog(final Map<String, String> params) {
    try {
        String fileName = params.get("fileName");
        int batchLines = ParameterUtils.getInt(params, "batchLines", 100);
        Integer lineStart = ParameterUtils.getInt(params, "lineStart", null);
        PullLogResponse pullLogResponse = new PullLogResponse();
        pullLogResponse.setAgentId(Pradar.AGENT_ID_NOT_CONTAIN_USER_INFO);
        pullLogResponse.setAppName(AppNameUtils.appName());
        pullLogResponse.setTraceId(params.get("traceId"));
        pullLogResponse.setType(AGENT);
        List<PullLogResponse.Log> logs = new ArrayList<PullLogResponse.Log>();
        pullLogResponse.setLogs(logs);
        if (null == fileName) {
            // 两个日志文件都查看
            // simulator.log
            readLog(logs, batchLines, lineStart, simulatorConfig.getLogPath() + "/simulator.log");
            // simulator-agent.log
            readLog(logs, batchLines, lineStart, simulatorConfig.getLogPath() + "/simulator-agent.log");
        } else {
            readLog(logs, batchLines, lineStart, simulatorConfig.getLogPath() + "/" + fileName);
        }
        return CommandResponse.success(pullLogResponse);
    } catch (Throwable e) {
        logger.error("SIMULATOR: pullAgentLog occured a unknow error! ", e);
        return CommandResponse.failure("pullAgentLog occured a unknow error! " + e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) PullLogResponse(com.shulie.instrument.module.log.data.pusher.log.PullLogResponse) Command(com.shulie.instrument.simulator.api.annotation.Command)

Example 17 with Command

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

the class DefaultModuleCommandInvoker method matchingModuleMethod.

/**
 * 匹配模块中复合HTTP请求路径的方法
 * 匹配方法的方式是:HttpMethod和HttpPath全匹配
 *
 * @param command       命令
 * @param classOfModule 模块类
 * @return 返回匹配上的方法,如果没有找到匹配方法则返回null
 */
private Method matchingModuleMethod(final String command, 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 = trimSlash(commandAnnotation.value());
        if (StringUtils.equals(cmd, command)) {
            return method;
        }
    }
    // 找不到匹配方法,返回null
    return null;
}
Also used : Command(com.shulie.instrument.simulator.api.annotation.Command) Method(java.lang.reflect.Method)

Example 18 with Command

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

the class LogDataPusherModule method pullAppLog.

@Command("pullAppLog")
public CommandResponse pullAppLog(final Map<String, String> params) {
    try {
        String filePath = params.get("filePath");
        int batchLines = ParameterUtils.getInt(params, "batchLines", 100);
        Integer lineStart = ParameterUtils.getInt(params, "lineStart", null);
        PullLogResponse pullLogResponse = new PullLogResponse();
        pullLogResponse.setAgentId(Pradar.AGENT_ID_NOT_CONTAIN_USER_INFO);
        pullLogResponse.setAppName(AppNameUtils.appName());
        pullLogResponse.setTraceId(params.get("traceId"));
        pullLogResponse.setType(APP);
        List<PullLogResponse.Log> logs = new ArrayList<PullLogResponse.Log>();
        pullLogResponse.setLogs(logs);
        File file = new File(filePath);
        if (!file.exists()) {
            PullLogResponse.Log log = new PullLogResponse.Log();
            log.setHasLogFile(Boolean.FALSE);
            log.setFileName(file.getName());
            log.setFilePath(filePath);
            logs.add(log);
        }
        readLog(logs, batchLines, lineStart, filePath);
        return CommandResponse.success(pullLogResponse);
    } catch (Throwable e) {
        logger.error("SIMULATOR: pullAppLog occured a unknow error! ", e);
        return CommandResponse.failure("pullAppLog occured a unknow error! " + e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) PullLogResponse(com.shulie.instrument.module.log.data.pusher.log.PullLogResponse) Command(com.shulie.instrument.simulator.api.annotation.Command)

Example 19 with Command

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

the class VMOptionModule method info.

@Command(value = "info", description = "查看虚拟机参数")
public CommandResponse info(final Map<String, String> args) {
    String name = args.get("name");
    try {
        HotSpotDiagnosticMXBean hotSpotDiagnosticMXBean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
        if (StringUtils.isBlank(name)) {
            // show all options
            final List<VMOption> diagnosticOptions = hotSpotDiagnosticMXBean.getDiagnosticOptions();
            List<VmOption> vmOptions = new ArrayList<VmOption>();
            for (VMOption vmOption : diagnosticOptions) {
                vmOptions.add(new VmOption(vmOption));
            }
            return CommandResponse.success(vmOptions);
        } else {
            // view the specified option
            VMOption option = hotSpotDiagnosticMXBean.getVMOption(name);
            if (option == null) {
                return CommandResponse.failure("In order to change the system properties, you must specify the property value.");
            } else {
                List<VmOption> vmOptions = new ArrayList<VmOption>();
                vmOptions.add(new VmOption(option));
                return CommandResponse.success(vmOptions);
            }
        }
    } catch (Throwable t) {
        return CommandResponse.failure(t);
    }
}
Also used : VmOption(com.shulie.instrument.simulator.module.model.vmoption.VmOption) HotSpotDiagnosticMXBean(com.sun.management.HotSpotDiagnosticMXBean) VMOption(com.sun.management.VMOption) ArrayList(java.util.ArrayList) Command(com.shulie.instrument.simulator.api.annotation.Command)

Example 20 with Command

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

the class VMOptionModule method setOption.

@Command(value = "setOption", description = "设置虚拟机参数")
public CommandResponse setOption(final Map<String, String> args) {
    String name = args.get("name");
    String value = args.get("value");
    try {
        HotSpotDiagnosticMXBean hotSpotDiagnosticMXBean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
        VMOption vmOption = hotSpotDiagnosticMXBean.getVMOption(name);
        String originValue = vmOption.getValue();
        // change vm option
        hotSpotDiagnosticMXBean.setVMOption(name, value);
        return CommandResponse.success(true);
    } catch (Throwable t) {
        return CommandResponse.failure(t);
    }
}
Also used : HotSpotDiagnosticMXBean(com.sun.management.HotSpotDiagnosticMXBean) VMOption(com.sun.management.VMOption) 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