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