Commit eb6942ff authored by 智勇's avatar 智勇

循环获取container_cpu_usage_seconds_total

parent a2d7eee6
...@@ -11,12 +11,13 @@ const startTime = endTime - (60 * 60 * 12) ...@@ -11,12 +11,13 @@ const startTime = endTime - (60 * 60 * 12)
async function job() { async function job() {
logger.info('cpu rate job start') logger.info('cpu rate job start')
const finalCpuLimit = {} const finalCpuLimit = {}
let url = `${config.prometheus}/api/v1/query?query=sum%20(container_spec_cpu_quota%20
{namespace!~%22kube-system|monitor|rc-test%22}/(100*1000))%20by%20(pod_name)`
const cpuLimitRes = await awaitRequest({ const cpuLimitRes = await awaitRequest({
url: `${config.prometheus}/api/v1/query?query=sum%20(container_spec_cpu_quota%20 url,
{namespace!~%22kube-system|monitor|rc-test%22}/(100*1000))%20by%20(pod_name)`,
method: 'GET', method: 'GET',
}) })
logger.info('container_spec_cpu_quota', cpuLimitRes.status, cpuLimitRes.data.result.length) logger.info('container_spec_cpu_quota', cpuLimitRes.status, cpuLimitRes.data.result.length, url)
cpuLimitRes.data.result.forEach((item) => { cpuLimitRes.data.result.forEach((item) => {
if (item.metric.pod_name) { if (item.metric.pod_name) {
...@@ -25,13 +26,17 @@ async function job() { ...@@ -25,13 +26,17 @@ async function job() {
}) })
const finalCpuUsage = {} const finalCpuUsage = {}
const cpuUsageRes = await awaitRequest({ url = `${config.prometheus}/api/v1/query_range?query=sum (rate (container_cpu_usage_seconds_total
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 {image!="",name=~"^k8s_.*",io_kubernetes_container_name!="POD",pod_name=~"^()()().*$"}[1m])) by
(pod_name)&start=${startTime}&end=${endTime}&step=60`, (pod_name)&start=${startTime}&end=${endTime}&step=60`
method: 'GET', let cpuUsageRes = { data: { result: [] } }
}) while (cpuUsageRes.data.result.length === 0) {
logger.info('container_cpu_usage_seconds_total', cpuUsageRes.status, cpuUsageRes.data.result.length) cpuUsageRes = await awaitRequest({
url,
method: 'GET',
})
logger.info('container_cpu_usage_seconds_total', cpuUsageRes.status, cpuUsageRes.data.result.length, url)
}
cpuUsageRes.data.result.forEach((item) => { cpuUsageRes.data.result.forEach((item) => {
if (item.metric.pod_name) { if (item.metric.pod_name) {
......
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