"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * PromQL工具类
 * @date 2021-09-13 13:37:53
 * @author 吴锋霖
 */
var PromQLUtils = /** @class */ (function () {
    function PromQLUtils() {
    }
    /**
     * 构建当前指标PromQL 查询语句
     * @param namespace 命名空间
     * @param podId K8S POD ID
     * @param metric 查询指标
     */
    PromQLUtils.buildInstantPromQL = function (namespace, podId, metric) {
        switch (metric) {
            case 'MEM_REQUEST':
                return "sum (kube_pod_container_resource_requests_memory_bytes{pod=\"" + podId + "\", namespace=\"" + namespace + "\"})";
            case 'MEM_LIMIT':
                return "sum (kube_pod_container_resource_limits_memory_bytes{pod=\"" + podId + "\", namespace=\"" + namespace + "\"})";
            case 'MEM_USED':
                return "sum (container_memory_working_set_bytes{pod=\"" + podId + "\", namespace=\"" + namespace + "\"})";
            case 'MEM_UTILIZATION':
                return "sum (container_memory_working_set_bytes{image!=\"\",pod=\"" + podId + "\",namespace=\"" + namespace + "\"}) /  (sum (container_spec_memory_limit_bytes{image!=\"\",pod=\"" + podId + "\",namespace=\"" + namespace + "\"})) * 100";
            case 'CPU_REQUEST':
                return "sum (kube_pod_container_resource_requests_cpu_cores{pod=\"" + podId + "\", namespace=\"" + namespace + "\"})";
            case 'CPU_LIMIT':
                return "sum (kube_pod_container_resource_limits_cpu_cores{pod=\"" + podId + "\", namespace=\"" + namespace + "\"})";
            case 'CPU_USED':
                return "sum (rate (container_cpu_usage_seconds_total{image!=\"\",pod=\"" + podId + "\",namespace=\"" + namespace + "\"}[1m]))";
            case 'CPU_UTILIZATION':
                return "sum(rate(container_cpu_usage_seconds_total{image!=\"\",pod_name=\"" + podId + "\",namespace=\"" + namespace + "\"}[1m])) by (pod_name, namespace) / (sum(container_spec_cpu_quota{image!=\"\",pod_name=\"" + podId + "\",namespace=\"" + namespace + "\"}/100000) by (pod_name, namespace)) * 100";
        }
    };
    /**
      * 构建范围值指标PromQL 查询语句
      * @param namespace 命名空间
      * @param podId K8S POD ID
      * @param metric 查询指标
      */
    PromQLUtils.buildRangePromQL = function (namespace, podId, metric) {
        switch (metric) {
            case 'MEM_USAGE':
                return "sum (container_memory_working_set_bytes{image!=\"\",pod_name=\"" + podId + "\",namespace=\"" + namespace + "\"}) by (pod_name)";
            case 'CPU_USAGE':
                return "sum (rate (container_cpu_usage_seconds_total{image!=\"\",pod_name=\"" + podId + "\",namespace=\"" + namespace + "\"}[1m])) by (pod_name)";
        }
    };
    PromQLUtils.epochSecond = function (date) {
        var seconds = (date || new Date()).getTime() / 1000 + '';
        return parseInt(seconds);
    };
    return PromQLUtils;
}());
exports.PromQLUtils = PromQLUtils;
//# sourceMappingURL=PromQLUtils.js.map