Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qa-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
qa-api
Commits
eb6942ff
Commit
eb6942ff
authored
Mar 09, 2020
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
循环获取container_cpu_usage_seconds_total
parent
a2d7eee6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
9 deletions
+14
-9
cpuRate.js
app/jobs/cpuRate.js
+14
-9
No files found.
app/jobs/cpuRate.js
View file @
eb6942ff
...
@@ -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`
let
cpuUsageRes
=
{
data
:
{
result
:
[]
}
}
while
(
cpuUsageRes
.
data
.
result
.
length
===
0
)
{
cpuUsageRes
=
await
awaitRequest
({
url
,
method
:
'
GET
'
,
method
:
'
GET
'
,
})
})
logger
.
info
(
'
container_cpu_usage_seconds_total
'
,
cpuUsageRes
.
status
,
cpuUsageRes
.
data
.
result
.
length
)
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment