package com.ruoyi.web.controller.monitor;

import com.ruoyi.cc.service.ICcParamsService;
import com.ruoyi.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.framework.web.domain.Server;

/**
 * 服务器监控
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/monitor/server")
public class ServerController extends BaseController
{

    @Autowired
    private ICcParamsService ccParamsService;

    private String prefix = "monitor/server";

    @RequiresPermissions("monitor:server:view")
    @GetMapping()
    public String server(ModelMap mmap) throws Exception
    {
        // http://192.168.67.238:19999/api/v1/data
        String netdataApiBase = ccParamsService.getParamValueByCode("netdata_api_base", "");
        if  (StringUtils.isNotEmpty(netdataApiBase)) {
            mmap.put("netdataApiBase", netdataApiBase);
            return prefix + "/system_io";
        } else {
            Server server = new Server();
            server.copyTo();
            mmap.put("server", server);
            return prefix + "/server";
        }
    }
}
