Search in sources :

Example 6 with OSProcess

use of com.creditease.agent.helpers.osproc.OSProcess 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)

Aggregations

OSProcess (com.creditease.agent.helpers.osproc.OSProcess)6 AgentFeatureComponent (com.creditease.agent.spi.AgentFeatureComponent)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1