package net.northking.cctp.device.util.prometheus;

public class PromQlConfig {

    private final static String protocol = "http://";
    public final static String windowsSystem = "windows";
    public final static String linuxSystem = "linux";
    public final static String checkDatabase = "/api/v1/query?query=0&time=1";
    public final static String queryRange = "/api/v1/query_range";
    public final static String query = "/api/v1/query";
    public final static String targets = "/api/v1/targets";

    public static String getCheckDatabaseUrl(String ipPort) {
        return protocol + ipPort + checkDatabase;
    }

    public static String getQueryRangeUrl(String ipPort) {
        return protocol + ipPort + queryRange;
    }

    public static String getQueryUrl(String ipPort) {
        return protocol + ipPort + query;
    }

    public static String getTargetsUrl(String ipPort) {
        return protocol + ipPort + targets;
    }

    /****************************  windows_export   *******************************************/
    //主机基础信息
    public final static String windowsOsInfo = "windows_os_info{job=~\"$job\",instance=~\"$instance\"}*on(instance)group_right(product)windows_cs_hostname";
    //运行总时间
    public final static String windowsRunTimeCal = "time()-windows_system_system_up_time{job=~\"$job\",instance=~\"$instance\"}";
    //cpu核数
    public final static String windowsCpuCore = "windows_cs_logical_processors{job=~\"$job\",instance=~\"$instance\"}-0";
    //总内存
    public final static String windowsRamTotal = "windows_cs_physical_memory_bytes{job=~\"$job\",instance=~\"$instance\"}-0";
    //内存使用率
    public final static String windowsRamRate = "100-100*windows_os_physical_memory_free_bytes{job=~\"$job\",instance=~\"$instance\"}/windows_cs_physical_memory_bytes{job=~\"$job\",instance=~\"$instance\"}";
    //内存使用率
    public final static String windowsRamRateInstance = "100.0-100*avg_over_time(windows_os_physical_memory_free_bytes{job=~\"$job\",instance=~\"$instance\"}[$interval])/windows_cs_physical_memory_bytes{job=~\"$job\",instance=~\"$instance\"}";
    //cpus使用率
    public final static String windowsCpuRate = "100-(avg%20by(instance)(irate(windows_cpu_time_total{job=~\"$job\",instance=~\"$instance\",mode=\"idle\"}[2m]))*100)";
    //cpus使用率
    public final static String windowsCpuRateInstance = "100-(avg(rate(windows_cpu_time_total{job=~\"$job\",instance=~\"$instance\",mode=\"idle\"}[$interval]))by(instance)*100)";
    //读取
    public final static String windowsReadInstance = "irate(windows_logical_disk_read_bytes_total{job=~\"$job\",instance=~\"$instance\"}[5m])/1024";
    //写入
    public final static String windowsWriteInstance = "irate(windows_logical_disk_write_bytes_total{job=~\"$job\",instance=~\"$instance\"}[5m])/1024";
    //上传
    public final static String networkReceive = "irate(windows_net_bytes_received_total{job=~\"$job\",instance=~\"$instance\",nic!~\'isatap.*|VPN.*\'}[5m])*8/1024";
    //下载
    public final static String networkTransmit = "(irate(windows_net_bytes_sent_total{job=~\"$job\",instance=~\"$instance\",nic!~\'isatap.*|VPN.*\'}[5m])*8>0)/1024";


    /****************************  node_export   *******************************************/
    //主机基础信息
    public final static String nodeOsInfo = "node_uname_info{job=~\"$job\",instance=~\"$instance\"}-0";
    //运行总时间
    public final static String nodeRunTimeCal = "sum(time()-node_boot_time_seconds{job=~\"$job\",instance=~\"$instance\"})by(instance)";
    //cpu核数
    public final static String nodeCpuCore = "count(node_cpu_seconds_total{job=~\"$job\",instance=~\"$instance\",mode='system'})by(instance)";
    //总内存
    public final static String nodeRamTotal = "node_memory_MemTotal_bytes{job=~\"$job\",instance=~\"$instance\"}-0";
    //内存使用率
    public final static String nodeRamRate = "(1-(node_memory_MemAvailable_bytes{job=~\"$job\",instance=~\"$instance\"}/(node_memory_MemTotal_bytes{job=~\"$job\",instance=~\"$instance\"})))*100";
    //内存使用率
    public final static String nodeRamRateInstance = "(1-((avg_over_time(node_memory_MemAvailable_bytes{job=~\"$job\",instance=~\"$instance\"}[$interval]))/(node_memory_MemTotal_bytes{job=~\"$job\",instance=~\"$instance\"})))*100";
    //cpu使用率
    public final static String nodeCpuRate = "(1-avg(rate(node_cpu_seconds_total{job=~\"$job\",instance=~\"$instance\",mode=\"idle\"}[2m]))by(instance))*100";
    //cpu使用率
    public final static String nodeCpuRateInstance = "(1-avg(rate(node_cpu_seconds_total{job=~\"$job\",instance=~\"$instance\",mode=\"idle\"}[$interval]))by(instance))*100";
    //IO耗时占比
    public final static String nodeIoRateInstance = "avg(rate(node_disk_io_time_seconds_total{job=~\"$job\",instance=~\"$instance\"}[$interval]))";
    //读取
    public final static String nodeReadInstance = "-avg(rate(node_disk_read_bytes_total{job=~\"$job\",instance=~\"$instance\"}[$interval]))";
    //写入
    public final static String nodeWriteInstance = "avg(rate(node_disk_written_bytes_total{job=~\"$job\",instance=~\"$instance\"}[$interval]))";

    //运行总时间
    public final static String nodeRunTimeCal_1 = "sum(time()-node_boot_time_seconds{instance=~\"$instance\"})by(instance)";
    //cpu核数
    public final static String nodeCpuCore_1 = "count(node_cpu_seconds_total{instance=~\"$instance\",mode='system'})by(instance)";
    //总内存
    public final static String nodeRamTotal_1 = "node_memory_MemTotal_bytes{instance=~\"$instance\"}-0";
    //内存使用率
    public final static String nodeRamRate_1 = "(1-(node_memory_MemAvailable_bytes{instance=~\"$instance\"}/(node_memory_MemTotal_bytes{instance=~\"$instance\"})))*100";
    //cpu使用率
    public final static String nodeCpuRate_1 = "(1-avg(rate(node_cpu_seconds_total{instance=~\"$instance\",mode=\"idle\"}[2m]))by(instance))*100";

    //运行总时间
    public final static String windowsRunTimeCal_1 = "time()-windows_system_system_up_time{instance=~\"$instance\"}";
    //cpu核数
    public final static String windowsCpuCore_1 = "windows_cs_logical_processors{instance=~\"$instance\"}-0";
    //总内存
    public final static String windowsRamTotal_1 = "windows_cs_physical_memory_bytes{instance=~\"$instance\"}-0";
    //内存使用率
    public final static String windowsRamRate_1 = "100-100*windows_os_physical_memory_free_bytes{instance=~\"$instance\"}/windows_cs_physical_memory_bytes{instance=~\"$instance\"}";
    //cpu使用率
    public final static String windowsCpuRate_1 = "100-(avg%20by(instance)(irate(windows_cpu_time_total{instance=~\"$instance\",mode=\"idle\"}[2m]))*100)";

}
