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
d217cdc1
Commit
d217cdc1
authored
7 years ago
by
Bob Shannon
Committed by
Daniel Nelson
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add optional usage_active and time_active CPU metrics (#2943)
parent
d5b6f92f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
plugins/inputs/system/CPU_README.md
+4
-0
4 additions, 0 deletions
plugins/inputs/system/CPU_README.md
plugins/inputs/system/cpu.go
+18
-0
18 additions, 0 deletions
plugins/inputs/system/cpu.go
plugins/inputs/system/cpu_test.go
+3
-0
3 additions, 0 deletions
plugins/inputs/system/cpu_test.go
with
25 additions
and
0 deletions
plugins/inputs/system/CPU_README.md
+
4
−
0
View file @
d217cdc1
...
...
@@ -14,6 +14,8 @@
totalcpu = true
## If true, collect raw CPU time metrics.
collect_cpu_time = false
## If true, compute and report the sum of all non-idle CPU states.
report_active = false
```
#### Description
...
...
@@ -68,6 +70,7 @@ Measurement names:
-
cpu_time_user
-
cpu_time_system
-
cpu_time_idle
-
cpu_time_active (must be explicitly enabled by setting
`report_active = true`
)
-
cpu_time_nice
-
cpu_time_iowait
-
cpu_time_irq
...
...
@@ -86,6 +89,7 @@ Measurement names:
-
cpu_usage_user
-
cpu_usage_system
-
cpu_usage_idle
-
cpu_usage_active (must be explicitly enabled by setting
`report_active = true`
)
-
cpu_usage_nice
-
cpu_usage_iowait
-
cpu_usage_irq
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/system/cpu.go
+
18
−
0
View file @
d217cdc1
...
...
@@ -16,12 +16,14 @@ type CPUStats struct {
PerCPU
bool
`toml:"percpu"`
TotalCPU
bool
`toml:"totalcpu"`
CollectCPUTime
bool
`toml:"collect_cpu_time"`
ReportActive
bool
`toml:"report_active"`
}
func
NewCPUStats
(
ps
PS
)
*
CPUStats
{
return
&
CPUStats
{
ps
:
ps
,
CollectCPUTime
:
true
,
ReportActive
:
true
,
}
}
...
...
@@ -36,6 +38,8 @@ var sampleConfig = `
totalcpu = true
## If true, collect raw CPU time metrics.
collect_cpu_time = false
## If true, compute and report the sum of all non-idle CPU states.
report_active = false
`
func
(
_
*
CPUStats
)
SampleConfig
()
string
{
...
...
@@ -55,6 +59,7 @@ func (s *CPUStats) Gather(acc telegraf.Accumulator) error {
}
total
:=
totalCpuTime
(
cts
)
active
:=
activeCpuTime
(
cts
)
if
s
.
CollectCPUTime
{
// Add cpu time metrics
...
...
@@ -70,6 +75,9 @@ func (s *CPUStats) Gather(acc telegraf.Accumulator) error {
"time_guest"
:
cts
.
Guest
,
"time_guest_nice"
:
cts
.
GuestNice
,
}
if
s
.
ReportActive
{
fieldsC
[
"time_active"
]
=
activeCpuTime
(
cts
)
}
acc
.
AddCounter
(
"cpu"
,
fieldsC
,
tags
,
now
)
}
...
...
@@ -80,6 +88,7 @@ func (s *CPUStats) Gather(acc telegraf.Accumulator) error {
}
lastCts
:=
s
.
lastStats
[
i
]
lastTotal
:=
totalCpuTime
(
lastCts
)
lastActive
:=
activeCpuTime
(
lastCts
)
totalDelta
:=
total
-
lastTotal
if
totalDelta
<
0
{
...
...
@@ -90,6 +99,7 @@ func (s *CPUStats) Gather(acc telegraf.Accumulator) error {
if
totalDelta
==
0
{
continue
}
fieldsG
:=
map
[
string
]
interface
{}{
"usage_user"
:
100
*
(
cts
.
User
-
lastCts
.
User
-
(
cts
.
Guest
-
lastCts
.
Guest
))
/
totalDelta
,
"usage_system"
:
100
*
(
cts
.
System
-
lastCts
.
System
)
/
totalDelta
,
...
...
@@ -102,6 +112,9 @@ func (s *CPUStats) Gather(acc telegraf.Accumulator) error {
"usage_guest"
:
100
*
(
cts
.
Guest
-
lastCts
.
Guest
)
/
totalDelta
,
"usage_guest_nice"
:
100
*
(
cts
.
GuestNice
-
lastCts
.
GuestNice
)
/
totalDelta
,
}
if
s
.
ReportActive
{
fieldsG
[
"usage_active"
]
=
100
*
(
active
-
lastActive
)
/
totalDelta
}
acc
.
AddGauge
(
"cpu"
,
fieldsG
,
tags
,
now
)
}
...
...
@@ -116,6 +129,11 @@ func totalCpuTime(t cpu.TimesStat) float64 {
return
total
}
func
activeCpuTime
(
t
cpu
.
TimesStat
)
float64
{
active
:=
totalCpuTime
(
t
)
-
t
.
Idle
return
active
}
func
init
()
{
inputs
.
Add
(
"cpu"
,
func
()
telegraf
.
Input
{
return
&
CPUStats
{
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/system/cpu_test.go
+
3
−
0
View file @
d217cdc1
...
...
@@ -59,6 +59,7 @@ func TestCPUStats(t *testing.T) {
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_user"
,
8.8
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_system"
,
8.2
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_idle"
,
80.1
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_active"
,
19.9
,
0.0005
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_nice"
,
1.3
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_iowait"
,
0.8389
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_irq"
,
0.6
,
0
,
cputags
)
...
...
@@ -78,6 +79,7 @@ func TestCPUStats(t *testing.T) {
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_user"
,
24.9
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_system"
,
10.9
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_idle"
,
157.9798
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_active"
,
42.0202
,
0.0005
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_nice"
,
3.5
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_iowait"
,
0.929
,
0
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"time_irq"
,
1.2
,
0
,
cputags
)
...
...
@@ -89,6 +91,7 @@ func TestCPUStats(t *testing.T) {
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"usage_user"
,
7.8
,
0.0005
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"usage_system"
,
2.7
,
0.0005
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"usage_idle"
,
77.8798
,
0.0005
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"usage_active"
,
22.1202
,
0.0005
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"usage_nice"
,
0
,
0.0005
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"usage_iowait"
,
0.0901
,
0.0005
,
cputags
)
assertContainsTaggedFloat
(
t
,
&
acc
,
"cpu"
,
"usage_irq"
,
0.6
,
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