package com.eactive.eai.rms.client.agent;

import org.apache.commons.lang3.StringUtils;

import com.eactive.eai.rms.client.SocketClient;
import com.eactive.eai.rms.client.context.RmsProperties;
import com.eactive.eai.rms.client.service.HostStatusService;
import com.eactive.eai.rms.onl.vo.HostStatusVo;

public class HostStatusAgent extends AbstractScheduledAgent {

    private HostStatusService hostStatusService;
    private RmsProperties rmsProperties;
    private SocketClient socketClient;

    public void run() {

        try {

            String path = rmsProperties.getStringProperty(RmsProperties.DISK_SPACE_PATH, "/fseai");

            HostStatusVo hostStatusVo = (HostStatusVo) applicationContext.getBean("hostStatusVo");

            hostStatusVo.setCpu(hostStatusService.getCpuPercentage());
            hostStatusVo.setMemory(hostStatusService.getMemoryPercentage());
            hostStatusVo.setDisk(hostStatusService.getDiskPercentage(path));

            socketClient.send(hostStatusVo);
            logger.debug("SEND HostStatusAgent : " + hostStatusVo );
        } catch (Exception e) {
            logger.warn(this, e);
        }

    }

    public void setHostStatusService(HostStatusService hostStatusService) {
        this.hostStatusService = hostStatusService;
    }

    public void setRmsProperties(RmsProperties rmsProperties) {
        this.rmsProperties = rmsProperties;
    }

    public void setSocketClient(SocketClient socketClient) {
        this.socketClient = socketClient;
    }
}
