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
825252f3
Commit
825252f3
authored
Mar 12, 2020
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复时间参数问题
parent
eb6942ff
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
cpuRate.js
app/jobs/cpuRate.js
+6
-4
No files found.
app/jobs/cpuRate.js
View file @
825252f3
...
@@ -6,7 +6,7 @@ const awaitRequest = require('../utils/awaitRequest')
...
@@ -6,7 +6,7 @@ const awaitRequest = require('../utils/awaitRequest')
const
config
=
require
(
global
.
configPath
)
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
)
const
startTime
=
endTime
-
(
60
*
60
*
12
)
async
function
job
()
{
async
function
job
()
{
logger
.
info
(
'
cpu rate job start
'
)
logger
.
info
(
'
cpu rate job start
'
)
...
@@ -17,7 +17,7 @@ async function job() {
...
@@ -17,7 +17,7 @@ async function job() {
url
,
url
,
method
:
'
GET
'
,
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
)
=>
{
cpuLimitRes
.
data
.
result
.
forEach
((
item
)
=>
{
if
(
item
.
metric
.
pod_name
)
{
if
(
item
.
metric
.
pod_name
)
{
...
@@ -26,16 +26,18 @@ async function job() {
...
@@ -26,16 +26,18 @@ async function job() {
})
})
const
finalCpuUsage
=
{}
const
finalCpuUsage
=
{}
let
flag
=
0
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
:
[]
}
}
let
cpuUsageRes
=
{
data
:
{
result
:
[]
}
}
while
(
cpuUsageRes
.
data
.
result
.
length
===
0
)
{
while
(
cpuUsageRes
.
data
.
result
.
length
===
0
&&
flag
<
10
)
{
cpuUsageRes
=
await
awaitRequest
({
cpuUsageRes
=
await
awaitRequest
({
url
,
url
,
method
:
'
GET
'
,
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
)
=>
{
cpuUsageRes
.
data
.
result
.
forEach
((
item
)
=>
{
...
...
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