Search in sources :

Example 21 with AgentFeatureComponent

use of com.creditease.agent.spi.AgentFeatureComponent in project uavstack by uavorg.

the class MSCPGeneralAction method unwatchProc.

/**
 * unwatchProc
 *
 * @param data
 */
private void unwatchProc(UAVHttpMessage data) {
    String pid = data.getRequest("pid");
    AgentFeatureComponent afc = (AgentFeatureComponent) this.getConfigManager().getComponent("procwatch", "ProcWatchAgent");
    if (afc != null) {
        Object res = afc.exchange("agent.procwatch.unwatch", pid);
        if (res != null) {
            data.putResponse("rs", String.valueOf(res));
            return;
        }
    }
    data.putResponse("rs", "ERR");
}
Also used : AgentFeatureComponent(com.creditease.agent.spi.AgentFeatureComponent)

Example 22 with AgentFeatureComponent

use of com.creditease.agent.spi.AgentFeatureComponent in project uavstack by uavorg.

the class NetworkIoDetector method run.

@Override
public void run() {
    if (portList == null) {
        return;
    }
    String result = null;
    String networkdetectTime = this.getConfigManager().getFeatureConfiguration(this.feature, "networkDetect.collectTime");
    String ip = NetworkHelper.getLocalIP();
    // windows
    if (JVMToolHelper.isWindows()) {
        JpcapCaptor jpcap = null;
        try {
            String Local_ip = "/" + ip;
            // 存端口流量
            HashMap<String, Integer> counter = new HashMap<String, Integer>();
            String[] split_ProtList = portList.split(" ");
            for (String str : split_ProtList) {
                counter.put("in_" + str, 0);
                counter.put("out_" + str, 0);
            }
            // 获取网卡设备列表
            NetworkInterface[] devices = JpcapCaptor.getDeviceList();
            // 确定网卡设备接口
            boolean true_devices = false;
            int i = 0;
            for (; i < devices.length; i++) {
                for (NetworkInterfaceAddress nia : devices[i].addresses) {
                    if (Local_ip.equals(nia.address.toString())) {
                        true_devices = true;
                        break;
                    }
                }
                if (true_devices) {
                    break;
                }
            }
            NetworkInterface nc = devices[i];
            // 打开网卡设备 ,创建某个卡口上的抓取对象,最大为65535个
            jpcap = JpcapCaptor.openDevice(nc, 65535, false, 20);
            // 设置过滤器
            jpcap.setFilter("tcp", true);
            // 抓包 统计流量
            result = portFlux(jpcap, counter, nc, networkdetectTime, Local_ip);
        } catch (Exception e) {
            log.err(this, "NetworkIo Monitor runs FAIL.", e);
        } finally {
            if (jpcap != null) {
                // 关闭
                jpcap.close();
            }
        }
    } else // linux
    {
        if (countDown != 0) {
            countDown--;
            return;
        }
        try {
            String netcardName = NetworkHelper.getNetCardName(ip);
            String command = "cd bin; sh networkIoDetect.sh " + netcardName + " " + ip + " " + networkdetectTime + " " + portList;
            result = RuntimeHelper.exec(10000, "/bin/sh", "-c", command);
            if (!result.contains("in_") || result.toLowerCase().contains("error") || result.toLowerCase().contains("traceback")) {
                log.err(this, "NetworkIo Monitor runs FAIL with TechError: error=" + result);
                countDown = 100;
                return;
            }
        } catch (Exception e) {
            log.err(this, "NetworkIo Monitor runs FAIL.", e);
            countDown = 100;
        }
    }
    AgentFeatureComponent afc = (AgentFeatureComponent) this.getConfigManager().getComponent(this.feature, "ProcDetectAgent");
    if (null != afc) {
        afc.exchange("procscan.nodeinfo.portFlux", result, System.currentTimeMillis());
    }
    if (log.isDebugEnable()) {
        log.debug(this, "NetworkIo Monitor Result: " + result);
    }
}
Also used : HashMap(java.util.HashMap) NetworkInterface(jpcap.NetworkInterface) JpcapCaptor(jpcap.JpcapCaptor) NetworkInterfaceAddress(jpcap.NetworkInterfaceAddress) AgentFeatureComponent(com.creditease.agent.spi.AgentFeatureComponent)

Example 23 with AgentFeatureComponent

use of com.creditease.agent.spi.AgentFeatureComponent in project uavstack by uavorg.

the class OSProcessScanner method run.

@Override
public void run() {
    Map<String, OSProcess> procs = new LinkedHashMap<String, OSProcess>();
    /**
     * get all process info
     */
    StringBuffer portList = new StringBuffer();
    if (JVMToolHelper.isWindows()) {
        scanWindowsProcesses(procs, portList, this.shellPath);
    } else {
        scanLinuxProcesses(procs, portList, this.shellPath);
    }
    AgentFeatureComponent afc = (AgentFeatureComponent) this.getConfigManager().getComponent(this.feature, "ProcDetectAgent");
    if (null != afc) {
        afc.exchange("networkdetect.portList", portList.toString());
    }
    /**
     * get java process ext info
     */
    List<Map<String, String>> jvmProcs = JVMToolHelper.getAllJVMProcesses(null);
    for (Map<String, String> jvmProc : jvmProcs) {
        String pid = jvmProc.get("pid");
        if (procs.containsKey(pid)) {
            /**
             * add service java info to process info
             */
            OSProcess p = procs.get(pid);
            addTagsToOSProcess(jvmProc, p);
        } else {
            /**
             * add the non-service java into process info
             */
            OSProcess p = new OSProcess();
            p.setName("java");
            p.setPid(pid);
            addTagsToOSProcess(jvmProc, p);
            procs.put(pid, p);
        }
    }
    if (log.isDebugEnable()) {
        log.debug(this, "Process Scan Result: " + JSONHelper.toString(procs));
    }
    // collect each process's cpu, mem and so on
    collectProcState(procs);
    /**
     * pass to NodeInfo
     */
    afc = (AgentFeatureComponent) this.getConfigManager().getComponent("hbclientagent", "HeartBeatClientAgent");
    Map<String, Object> extInfo = new LinkedHashMap<String, Object>();
    extInfo.put("procs", procs);
    extInfo.put("tags", this.containerTagsStr);
    if (afc != null) {
        afc.exchange("hbclientagent.nodeinfo.extinfo", extInfo);
    }
    /**
     * pass to ProcWatcher to check if the guiding process is alive
     */
    afc = (AgentFeatureComponent) this.getConfigManager().getComponent("procwatch", "ProcWatchAgent");
    if (afc != null) {
        afc.exchange("agent.procwatch.refresh", procs);
    }
    /**
     * refresh current processes states
     */
    this.curProcsState = procs;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) OSProcess(com.creditease.agent.helpers.osproc.OSProcess) AgentFeatureComponent(com.creditease.agent.spi.AgentFeatureComponent) LinkedHashMap(java.util.LinkedHashMap)

Example 24 with AgentFeatureComponent

use of com.creditease.agent.spi.AgentFeatureComponent in project uavstack by uavorg.

the class CollectDataAgent method doCallback.

private void doCallback(final String feature, final String component, final String eventKey, final String data, final List<CollectTask> fails) {
    if (log.isDebugEnable()) {
        log.debug(this, "task context callback feature=" + feature + ", component=" + component + ", eventKey=" + eventKey + ", data=" + data + ", fails=" + fails.size());
    }
    final AgentFeatureComponent afc = (AgentFeatureComponent) getConfigManager().getComponent(feature, component);
    if (afc != null) {
        final String failTasks = fails.size() == 0 ? null : JSONHelper.toString(fails);
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    afc.exchange(eventKey, data, failTasks);
                } catch (Exception e) {
                    log.err(this, "task callback FAILED. feature=" + feature + ", component=" + component + ", eventKey=" + eventKey, e);
                }
            }
        }).start();
    }
}
Also used : AgentFeatureComponent(com.creditease.agent.spi.AgentFeatureComponent) IOException(java.io.IOException)

Example 25 with AgentFeatureComponent

use of com.creditease.agent.spi.AgentFeatureComponent in project uavstack by uavorg.

the class DumpThreadAction method collectFile.

private String collectFile(String fileName, String user, List<Object> paramsList) {
    String ipport = getIPPort(fileName);
    String pid = "unknown";
    String time = System.currentTimeMillis() + "";
    if (paramsList.size() > 2) {
        pid = paramsList.get(0).toString();
        time = paramsList.get(1).toString();
    }
    String target = ipport + "_" + pid + "_" + time + "_" + user;
    AgentFeatureComponent afc = (AgentFeatureComponent) this.getConfigManager().getComponent("collectclient", "CollectDataAgent");
    if (afc == null) {
        return "ERR:归集客户端未启动";
    }
    String collectAct = "collectdata.add";
    String mqTopic = "JQ_JTA";
    // call CollectDataAgent, prepare parameters
    Map<String, Object> task = new HashMap<String, Object>();
    task.put("target", target);
    task.put("action", mqTopic);
    task.put("file", fileName);
    task.put("topic", mqTopic);
    task.put("unsplit", true);
    List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
    tasks.add(task);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("tasks", tasks);
    Map<String, Object> call = new HashMap<String, Object>();
    call.put("feature", "threadanalysis");
    call.put("component", "ThreadAnalysisAgent");
    call.put("eventKey", "collect.callback");
    params.put("callback", call);
    String collectTasks = JSONHelper.toString(params);
    afc.exchange(collectAct, collectTasks);
    return fileName;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) AgentFeatureComponent(com.creditease.agent.spi.AgentFeatureComponent)

Aggregations

AgentFeatureComponent (com.creditease.agent.spi.AgentFeatureComponent)25 Map (java.util.Map)6 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)4 OSProcess (com.creditease.agent.helpers.osproc.OSProcess)3 List (java.util.List)3 UAVHttpMessage (com.creditease.agent.http.api.UAVHttpMessage)2 ArrayList (java.util.ArrayList)2 NodeInfo (com.creditease.agent.feature.hbagent.node.NodeInfo)1 DetectorManager (com.creditease.agent.feature.monitoragent.detect.DetectorManager)1 JVMAgentInfo (com.creditease.agent.helpers.jvmtool.JVMAgentInfo)1 MonitorDataFrame (com.creditease.agent.monitor.api.MonitorDataFrame)1 AgentResourceComponent (com.creditease.agent.spi.AgentResourceComponent)1 DataStoreMsg (com.creditease.uav.datastore.api.DataStoreMsg)1 Message (com.creditease.uav.messaging.api.Message)1 MessageProducer (com.creditease.uav.messaging.api.MessageProducer)1 File (java.io.File)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1