Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
telegraf-nftables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Due to inactivity, this project is scheduled to be deleted on 2035-04-24.
Why is this scheduled?
Show more breadcrumbs
vqgroup
telegraf-nftables
Commits
f5a9d1bc
Commit
f5a9d1bc
authored
7 years ago
by
Pierre Fersing
Committed by
Daniel Nelson
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix CPU system plugin gets stuck after system suspend (#3342)
parent
4b05edea
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
plugins/inputs/system/cpu.go
+3
-2
3 additions, 2 deletions
plugins/inputs/system/cpu.go
plugins/inputs/system/cpu_test.go
+69
-0
69 additions, 0 deletions
plugins/inputs/system/cpu_test.go
with
73 additions
and
2 deletions
CHANGELOG.md
+
1
−
0
View file @
f5a9d1bc
...
...
@@ -50,6 +50,7 @@
-
[
#3136
](
https://github.com/influxdata/telegraf/issues/3136
)
: Fix webhooks input address in use during reload.
-
[
#3258
](
https://github.com/influxdata/telegraf/issues/3258
)
: Unlock Statsd when stopping to prevent deadlock.
-
[
#3319
](
https://github.com/influxdata/telegraf/issues/3319
)
: Fix cloudwatch output requires unneeded permissions.
-
[
#3342
](
https://github.com/influxdata/telegraf/pull/3342
)
: Fix CPU input plugin stuck after suspend on Linux.
## v1.4.3 [unreleased]
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/system/cpu.go
+
3
−
2
View file @
f5a9d1bc
...
...
@@ -96,7 +96,8 @@ func (s *CPUStats) Gather(acc telegraf.Accumulator) error {
totalDelta
:=
total
-
lastTotal
if
totalDelta
<
0
{
return
fmt
.
Errorf
(
"Error: current total CPU time is less than previous total CPU time"
)
err
=
fmt
.
Errorf
(
"Error: current total CPU time is less than previous total CPU time"
)
break
}
if
totalDelta
==
0
{
...
...
@@ -126,7 +127,7 @@ func (s *CPUStats) Gather(acc telegraf.Accumulator) error {
s
.
lastStats
[
cts
.
CPU
]
=
cts
}
return
nil
return
err
}
func
totalCpuTime
(
t
cpu
.
TimesStat
)
float64
{
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/system/cpu_test.go
+
69
−
0
View file @
f5a9d1bc
...
...
@@ -184,3 +184,72 @@ func TestCPUCountIncrease(t *testing.T) {
err
=
cs
.
Gather
(
&
acc
)
require
.
NoError
(
t
,
err
)
}
// TestCPUTimesDecrease tests that telegraf continue to works after
// CPU times decrease, which seems to occur when Linux system is suspended.
func
TestCPUTimesDecrease
(
t
*
testing
.
T
)
{
var
mps
MockPS
defer
mps
.
AssertExpectations
(
t
)
var
acc
testutil
.
Accumulator
cts
:=
cpu
.
TimesStat
{
CPU
:
"cpu0"
,
User
:
18
,
Idle
:
80
,
Iowait
:
2
,
}
cts2
:=
cpu
.
TimesStat
{
CPU
:
"cpu0"
,
User
:
38
,
// increased by 20
Idle
:
40
,
// decreased by 40
Iowait
:
1
,
// decreased by 1
}
cts3
:=
cpu
.
TimesStat
{
CPU
:
"cpu0"
,
User
:
56
,
// increased by 18
Idle
:
120
,
// increased by 80
Iowait
:
3
,
// increased by 2
}
mps
.
On
(
"CPUTimes"
)
.
Return
([]
cpu
.
TimesStat
{
cts
},
nil
)
cs
:=
NewCPUStats
(
&
mps
)
cputags
:=
map
[
string
]
string
{
"cpu"
:
"cpu0"
,
}
err
:=
cs
.
Gather
(
&
acc
)
require
.
NoError
(
t
,
err
)
// Computed values are checked with delta > 0 becasue of floating point arithmatic
// imprecision
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_user"
,
18
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_idle"
,
80
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_iowait"
,
2
,
0
,
cputags
)
mps2
:=
MockPS
{}
mps2
.
On
(
"CPUTimes"
)
.
Return
([]
cpu
.
TimesStat
{
cts2
},
nil
)
cs
.
ps
=
&
mps2
// CPU times decreased. An error should be raised
err
=
cs
.
Gather
(
&
acc
)
require
.
Error
(
t
,
err
)
mps3
:=
MockPS
{}
mps3
.
On
(
"CPUTimes"
)
.
Return
([]
cpu
.
TimesStat
{
cts3
},
nil
)
cs
.
ps
=
&
mps3
err
=
cs
.
Gather
(
&
acc
)
require
.
NoError
(
t
,
err
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_user"
,
56
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_idle"
,
120
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_iowait"
,
3
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"usage_user"
,
18
,
0.0005
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"usage_idle"
,
80
,
0.0005
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"usage_iowait"
,
2
,
0.0005
,
cputags
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment