Skip to content

Commit dfee3b7

Browse files
committed
chore: added the cpu utilization metrics
1 parent 2726ad6 commit dfee3b7

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

internal/collector/otelcol.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ receivers:
77
{{- if .Receivers.HostMetrics.Scrapers }}
88
{{- if .Receivers.HostMetrics.Scrapers.CPU }}
99
cpu:
10+
{{- if .Receivers.HostMetrics.Scrapers.CPU.Utilization }}
11+
metrics:
12+
utilization:
13+
enabled: true
14+
{{- end }}
1015
{{- end }}
1116
{{- if .Receivers.HostMetrics.Scrapers.Disk }}
1217
disk:

internal/collector/settings_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ func TestTemplateWrite(t *testing.T) {
7979
CollectionInterval: time.Minute,
8080
InitialDelay: time.Second,
8181
Scrapers: &config.HostMetricsScrapers{
82-
CPU: &config.CPUScraper{},
82+
CPU: &config.CPUScraper{
83+
Utilization: true,
84+
},
8385
Disk: &config.DiskScraper{},
8486
Filesystem: &config.FilesystemScraper{},
8587
Memory: &config.MemoryScraper{},

internal/config/types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ type (
242242
Memory *MemoryScraper `yaml:"-" mapstructure:"memory"`
243243
Network *NetworkScraper `yaml:"-" mapstructure:"network"`
244244
}
245-
CPUScraper struct{}
245+
CPUScraper struct {
246+
Utilization bool `yaml:"-" mapstructure:"utilization"`
247+
}
246248
DiskScraper struct{}
247249
FilesystemScraper struct{}
248250
MemoryScraper struct{}

test/config/collector/test-opentelemetry-collector-agent.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ receivers:
44
initial_delay: 1s
55
scrapers:
66
cpu:
7+
metrics:
8+
utilization:
9+
enabled: true
710
disk:
811
filesystem:
912
memory:

test/mock/collector/nginx-agent.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ collector:
3838
collection_interval: 1m0s
3939
initial_delay: 1s
4040
scrapers:
41-
cpu: {}
41+
cpu:
42+
metrics:
43+
utilization:
4244
memory: {}
4345
disk: {}
4446
network: {}

test/types/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ func AgentConfig() *config.Config {
9595
CollectionInterval: time.Minute,
9696
InitialDelay: time.Second,
9797
Scrapers: &config.HostMetricsScrapers{
98-
CPU: &config.CPUScraper{},
98+
CPU: &config.CPUScraper{
99+
Utilization: true,
100+
},
99101
Disk: &config.DiskScraper{},
100102
Filesystem: &config.FilesystemScraper{},
101103
Memory: &config.MemoryScraper{},

0 commit comments

Comments
 (0)