Search in sources :

Example 6 with AgentFeatureComponent

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

the class MSCPGeneralAction method watchProc.

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

Example 7 with AgentFeatureComponent

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

the class OSProcessScanner method collectProcState.

@SuppressWarnings("unchecked")
private void collectProcState(Map<String, OSProcess> procs) {
    if (procs == null || procs.isEmpty()) {
        return;
    }
    /**
     * detect if the process is watching
     */
    AgentFeatureComponent procwatch = (AgentFeatureComponent) this.getConfigManager().getComponent("procwatch", "ProcWatchAgent");
    Set<String> pids = new HashSet<>();
    for (String pid : procs.keySet()) {
        pids.add(pid);
        if (procwatch != null) {
            Object res = procwatch.exchange("agent.procwatch.iswatch", pid);
            if (res != null) {
                procs.get(pid).addTag("watch", String.valueOf(res));
            }
        }
    }
    /**
     * collect proc state metrics
     */
    Map<String, Map<String, String>> procStates = null;
    if (JVMToolHelper.isWindows()) {
        // do not include windows
        try {
            procStates = OSProcessHelper.getWinProcessInfo(shellPath, pids);
        } catch (Exception e) {
            log.err(this, "Collect Proc State Fail.", e);
            return;
        }
    } else {
        try {
            procStates = OSProcessHelper.getProcessInfo(shellPath, pids);
        } catch (Exception e) {
            log.err(this, "Collect Proc State Fail.", e);
            return;
        }
    }
    if (procStates == null) {
        return;
    }
    for (Map.Entry<String, Map<String, String>> en : procStates.entrySet()) {
        String pid = en.getKey();
        if (procs.containsKey(pid)) {
            OSProcess process = procs.get(pid);
            Map<String, String> states = en.getValue();
            for (Map.Entry<String, String> state : states.entrySet()) {
                process.addTag(state.getKey(), state.getValue());
            }
        }
    }
    /**
     * collect disk read/write speed for each process
     */
    pdioc.collect(procs);
    /**
     * collect in/out network stream for each process
     */
    if (null == portFlux) {
        return;
    }
    String networkDetectIntervalStr = this.getConfigManager().getFeatureConfiguration(this.feature, "networkDetect.interval");
    int networkDetectInterval = (StringHelper.isEmpty(networkDetectIntervalStr)) ? 60000 : Integer.parseInt(networkDetectIntervalStr);
    if (System.currentTimeMillis() - portFluxTimestamp > (2 * networkDetectInterval)) {
        if (log.isDebugEnable()) {
            log.debug(this, "portFlux is out of date ");
        }
        return;
    }
    Map<String, String> portFluxMap = null;
    try {
        portFluxMap = JSONHelper.toObject(portFlux, Map.class);
    } catch (Exception e) {
        log.err(this, "portFlux" + portFlux + " Json2Map error:\n " + e.toString());
        return;
    }
    if (null == portFluxMap) {
        return;
    }
    for (String pid : procs.keySet()) {
        OSProcess proc = procs.get(pid);
        float in_proc = 0;
        float out_proc = 0;
        for (String port : proc.getPorts()) {
            if (portFluxMap.containsKey("in_" + port)) {
                proc.addTag("in_" + port, portFluxMap.get("in_" + port));
                proc.addTag("out_" + port, portFluxMap.get("out_" + port));
                in_proc += Float.parseFloat(portFluxMap.get("in_" + port));
                out_proc += Float.parseFloat(portFluxMap.get("out_" + port));
            }
        }
        proc.addTag("in", String.valueOf(in_proc));
        proc.addTag("out", String.valueOf(out_proc));
    }
}
Also used : OSProcess(com.creditease.agent.helpers.osproc.OSProcess) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) AgentFeatureComponent(com.creditease.agent.spi.AgentFeatureComponent) HashSet(java.util.HashSet)

Example 8 with AgentFeatureComponent

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

the class HBClientDefaultHandler method getFeatureInfo.

/**
 * get the node's feature info
 *
 * @return
 */
private Map<String, List<String>> getFeatureInfo() {
    Set<Object> components = this.getConfigManager().getComponents();
    Map<String, List<String>> featureInfo = new LinkedHashMap<String, List<String>>();
    for (Object comp : components) {
        if (!AgentFeatureComponent.class.isAssignableFrom(comp.getClass())) {
            continue;
        }
        AgentFeatureComponent afc = (AgentFeatureComponent) comp;
        String feature = afc.getFeature();
        List<String> fcomps = null;
        if (featureInfo.containsKey(feature)) {
            fcomps = featureInfo.get(feature);
        } else {
            fcomps = new ArrayList<String>();
            featureInfo.put(feature, fcomps);
        }
        fcomps.add(afc.getName());
    }
    return featureInfo;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AgentFeatureComponent(com.creditease.agent.spi.AgentFeatureComponent) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with AgentFeatureComponent

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

the class HBServerDefaultHandler method handleServerOut.

@Override
public void handleServerOut(HeartBeatEvent data) {
    if (!data.containEvent(HeartBeatProtocol.EVENT_DEFAULT)) {
        return;
    }
    @SuppressWarnings("unchecked") List<String> nodeInfoStringArray = (List<String>) data.getParam(HeartBeatProtocol.EVENT_DEFAULT, HeartBeatProtocol.EVENT_KEY_NODE_INFO);
    if (null != nodeInfoStringArray && nodeInfoStringArray.size() == 0) {
        return;
    }
    String checkIsMaster = this.getConfigManager().getFeatureConfiguration("hbserveragent", "ismaster");
    // is not master
    if (null == checkIsMaster || !"true".equalsIgnoreCase(checkIsMaster)) {
        AgentFeatureComponent afc = (AgentFeatureComponent) this.getConfigManager().getComponent("hbclientagent", "HeartBeatClientAgent");
        afc.exchange("hbclientagent.nodeinfo.upstream", nodeInfoStringArray);
    } else // is master
    {
        // AgentFeatureComponent ida = (AgentFeatureComponent) this.getConfigManager().getComponent("ida",
        // "IssueDiagnoseAssitAgent");
        // sync node info to storage
        cacheManager.beginBatch();
        for (String nodeInfoString : nodeInfoStringArray) {
            NodeInfo ni = NodeInfo.toNodeInfo(nodeInfoString);
            long curTime = System.currentTimeMillis();
            // set server side timestamp
            ni.setServerTimestamp(curTime);
            // /**
            // * push to IDA feature
            // */
            // if (ida != null) {
            // ida.exchange("ida.put.data", ni);
            // }
            cacheManager.putHash(HeartBeatProtocol.STORE_REGION_UAV, HeartBeatProtocol.STORE_KEY_NODEINFO, ni.getId(), ni.toJSONString());
            /**
             * sync node services to service list
             */
            String servicesStr = ni.getInfo(InfoType.Node, "services");
            @SuppressWarnings("rawtypes") Map services = JSONHelper.toObject(servicesStr, Map.class, true);
            for (Object s : services.keySet()) {
                String sId = (String) s;
                /**
                 * MSCP Services: state =1, means all right, expire time out is 60 seconds
                 */
                cacheManager.putHash(HeartBeatProtocol.STORE_REGION_UAV, HeartBeatProtocol.STORE_KEY_SERVICE_PREFIX + sId, (String) services.get(sId), "1");
                cacheManager.expire(HeartBeatProtocol.STORE_REGION_UAV, HeartBeatProtocol.STORE_KEY_SERVICE_PREFIX + sId, 60, TimeUnit.SECONDS);
            }
        }
        cacheManager.submitBatch();
    }
    // set return code
    data.putParam(HeartBeatProtocol.EVENT_DEFAULT, HeartBeatProtocol.EVENT_KEY_RETCODE, HeartBeatProtocol.RC_I0000);
    if (isEnableNTP == true) {
        data.putParam(HeartBeatProtocol.EVENT_DEFAULT, HeartBeatProtocol.EVENT_KEY_TIME, System.currentTimeMillis());
    }
}
Also used : NodeInfo(com.creditease.agent.feature.hbagent.node.NodeInfo) List(java.util.List) Map(java.util.Map) AgentFeatureComponent(com.creditease.agent.spi.AgentFeatureComponent)

Example 10 with AgentFeatureComponent

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

the class ProfileDataContainerTagsHandler method handle.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void handle(MonitorDataFrame data) {
    AgentFeatureComponent ps = (AgentFeatureComponent) this.getConfigManager().getComponent("procscan", "ProcDetectAgent");
    if (ps == null) {
        log.warn(this, "AgentFeatureComponent[procscan] NO Exist.");
        return;
    }
    Map<String, Long> appNames = new HashMap<String, Long>();
    long curTime = System.currentTimeMillis();
    // get all frames
    Map<String, List<Map>> frames = data.getDatas();
    for (String appid : frames.keySet()) {
        List<Map> appDatas = frames.get(appid);
        for (Map appData : appDatas) {
            // get PEId
            String peId = (String) appData.get("PEId");
            if (!"cpt".equals(peId)) {
                continue;
            }
            List<Map> instances = (List<Map>) appData.get("Instances");
            for (Map instance : instances) {
                // get instance id
                String instanceId = (String) instance.get("id");
                if (!"webapp".equalsIgnoreCase(instanceId)) {
                    continue;
                }
                // get instance fields
                Map<String, Object> fields = (Map<String, Object>) instance.get("values");
                // get appName as tag
                String tag = (String) fields.get("appname");
                if (!StringHelper.isEmpty(tag)) {
                    appNames.put(tag, curTime);
                }
            }
        }
    }
    ps.exchange("procscan.nodeinfo.tags", appNames);
}
Also used : HashMap(java.util.HashMap) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) 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