Search in sources :

Example 1 with HeartBeatClientAgent

use of com.creditease.agent.feature.HeartBeatClientAgent in project uavstack by uavorg.

the class HBClientDefaultHandler method handleClientOut.

@Override
public void handleClientOut(HeartBeatEvent data) {
    /**
     * sync node info
     */
    NodeInfo ni = new NodeInfo();
    // node id
    ni.setId(this.getConfigManager().getContext(IConfigurationManager.NODEUUID));
    String[] hosts = NetworkHelper.getHosts();
    // host
    ni.setHost(hosts[0]);
    // ip
    ni.setIp(hosts[1]);
    // node name
    String nodeName = this.getConfigManager().getContext(IConfigurationManager.NODEAPPNAME);
    ni.setName(nodeName);
    // node group
    String nodeGroup = this.getConfigManager().getContext(IConfigurationManager.NODEGROUP);
    ni.setGroup(nodeGroup);
    // mac address
    ni.putInfo(InfoType.OS, "mac", NetworkHelper.getMACAddress());
    // OS type
    ni.putInfo(InfoType.OS, "type", System.getProperty("os.name"));
    // OS arch
    ni.putInfo(InfoType.OS, "arch", System.getProperty("os.arch"));
    // CPU number
    ni.putInfo(InfoType.OS, "cpu.number", String.valueOf(Runtime.getRuntime().availableProcessors()));
    OperatingSystemMXBean osmb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    // max physical memory
    ni.putInfo(InfoType.OS, "cpu.maxmem", String.valueOf(osmb.getTotalPhysicalMemorySize()));
    // free physical memory
    ni.putInfo(InfoType.OS, "cpu.freemem", String.valueOf(osmb.getFreePhysicalMemorySize()));
    // CPU load
    ni.putInfo(InfoType.OS, "cpu.load", String.valueOf(Math.round(osmb.getSystemCpuLoad() * 100)));
    // CPU avg load
    ni.putInfo(InfoType.OS, "cpu.avgload", String.valueOf(Math.round(osmb.getSystemLoadAverage() * 100)));
    // Current Connections
    ni.putInfo(InfoType.OS, "conn.cur", getCurrentConnectionCount());
    // IO DISK INFO
    String str = "{}";
    try {
        str = getIODiskInfo();
    } catch (Exception e) {
        log.err(this, "error occur during get diskinfo:" + e);
    }
    ni.putInfo(InfoType.OS, "io.disk", str);
    // java version
    ni.putInfo(InfoType.OS, "java.ver", System.getProperty("java.version"));
    // java vm name
    ni.putInfo(InfoType.OS, "java.vm", System.getProperty("java.vm.name"));
    // java home
    ni.putInfo(InfoType.OS, "java.home", System.getProperty("java.home"));
    // node info
    ni.putInfo(InfoType.Node, "root", ConfigurationManager.getInstance().getContext(IConfigurationManager.ROOT));
    ni.putInfo(InfoType.Node, "profile", ConfigurationManager.getInstance().getContext(IConfigurationManager.PROFILENAME));
    ni.putInfo(InfoType.Node, "hbserver", ((HeartBeatClientReqWorker) ConfigurationManager.getInstance().getComponent(this.feature, "HeartBeatClientReqWorker")).getCurrentHBServerURL());
    ni.putInfo(InfoType.Node, "pid", getPID());
    /**
     * node.state>0, means node alive node.state==0, means node is dying node.state<0, means node is dead
     */
    ni.putInfo(InfoType.Node, "state", "1");
    // node feature info
    Map<String, List<String>> featureInfo = getFeatureInfo();
    ni.putInfo(InfoType.Node, "feature", JSONHelper.toString(featureInfo));
    // node services info
    Map<String, String> services = getServiceURLs();
    String servicesStr = JSONHelper.toString(services);
    ni.putInfo(InfoType.Node, "services", servicesStr);
    ni.putInfo(InfoType.Node, "version", getConfigManager().getContext(IConfigurationManager.NODEAPPVERSION));
    // set time stamp
    ni.setClientTimestamp(System.currentTimeMillis());
    // set -1 mean no set by server at client side
    ni.setServerTimestamp(-1);
    // get the hbagent queue if this is non-master hbserver node
    HeartBeatClientAgent hbagent = (HeartBeatClientAgent) this.getConfigManager().getComponent(this.feature, "HeartBeatClientAgent");
    // get node ext info
    if (null != hbagent) {
        Map<String, Object> nodeExtInfo = hbagent.getNodeExtInfo();
        for (String key : nodeExtInfo.keySet()) {
            ni.putInfo(InfoType.Node, key, JSONHelper.toString(nodeExtInfo.get(key)));
        }
    }
    List<String> nodeInfos = new ArrayList<String>();
    // add node info of this node
    String nodeInfoOfThisNode = ni.toJSONString();
    nodeInfos.add(nodeInfoOfThisNode);
    if (null != hbagent) {
        List<List<String>> nodeInfoLists = hbagent.pollNodeInfoQueue();
        if (nodeInfoLists.size() > 0) {
            for (List<String> nodeInfoList : nodeInfoLists) {
                nodeInfos.addAll(nodeInfoList);
            }
        }
    }
    data.putParam(HeartBeatProtocol.EVENT_DEFAULT, HeartBeatProtocol.EVENT_KEY_NODE_INFO, nodeInfos);
    // record hb request start time
    hbStartTime = System.currentTimeMillis();
}
Also used : HeartBeatClientAgent(com.creditease.agent.feature.HeartBeatClientAgent) ArrayList(java.util.ArrayList) NodeInfo(com.creditease.agent.feature.hbagent.node.NodeInfo) ArrayList(java.util.ArrayList) List(java.util.List) OperatingSystemMXBean(com.sun.management.OperatingSystemMXBean)

Aggregations

HeartBeatClientAgent (com.creditease.agent.feature.HeartBeatClientAgent)1 NodeInfo (com.creditease.agent.feature.hbagent.node.NodeInfo)1 OperatingSystemMXBean (com.sun.management.OperatingSystemMXBean)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1