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());
}
}
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;
}
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());
}
}
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);
}
}
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);
}
}
Aggregations