Commit 825252f3 authored by 智勇's avatar 智勇

修复时间参数问题

parent eb6942ff
......@@ -6,7 +6,7 @@ const awaitRequest = require('../utils/awaitRequest')
const config = require(global.configPath)
const endTime = Math.round(moment().valueOf() / 1000)
const endTime = Math.round(moment(new Date()).valueOf() / 1000)
const startTime = endTime - (60 * 60 * 12)
async function job() {
logger.info('cpu rate job start')
......@@ -17,7 +17,7 @@ async function job() {
url,
method: 'GET',
})
logger.info('container_spec_cpu_quota', cpuLimitRes.status, cpuLimitRes.data.result.length, url)
logger.info('container_spec_cpu_quota_log', cpuLimitRes.status, cpuLimitRes.data.result.length, url)
cpuLimitRes.data.result.forEach((item) => {
if (item.metric.pod_name) {
......@@ -26,16 +26,18 @@ async function job() {
})
const finalCpuUsage = {}
let flag = 0
url = `${config.prometheus}/api/v1/query_range?query=sum (rate (container_cpu_usage_seconds_total
{image!="",name=~"^k8s_.*",io_kubernetes_container_name!="POD",pod_name=~"^()()().*$"}[1m])) by
(pod_name)&start=${startTime}&end=${endTime}&step=60`
let cpuUsageRes = { data: { result: [] } }
while (cpuUsageRes.data.result.length === 0) {
while (cpuUsageRes.data.result.length === 0 && flag < 10) {
cpuUsageRes = await awaitRequest({
url,
method: 'GET',
})
logger.info('container_cpu_usage_seconds_total', cpuUsageRes.status, cpuUsageRes.data.result.length, url)
logger.info('container_cpu_usage_seconds_total_log', cpuUsageRes.status, cpuUsageRes.data.result.length, url)
flag += 1
}
cpuUsageRes.data.result.forEach((item) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment