Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containerd metricbeat module #29247

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6208f0a
Create cpu metricset of metricbeat containerd module initial commit
MichaelKatsoulis Nov 24, 2021
6550334
Add cpu fields
MichaelKatsoulis Nov 24, 2021
928d3ea
Generate containerd cpu metrics
MichaelKatsoulis Nov 25, 2021
64da17e
Get cpu usage percentage
MichaelKatsoulis Nov 30, 2021
31672b5
New fields
MichaelKatsoulis Dec 2, 2021
512f5d4
Make fmt
MichaelKatsoulis Dec 2, 2021
287c9c4
Add config option for cpu pct calculation
MichaelKatsoulis Dec 6, 2021
e7f700c
Move containerd to xpack
MichaelKatsoulis Dec 6, 2021
3f48a7c
a
MichaelKatsoulis Dec 6, 2021
4b90344
list common
MichaelKatsoulis Dec 6, 2021
e61077c
Update
MichaelKatsoulis Dec 7, 2021
5e5ee78
Fmt
MichaelKatsoulis Dec 7, 2021
3ac6dca
Add memory metricset
MichaelKatsoulis Dec 8, 2021
5be637e
Add more memory fields
MichaelKatsoulis Dec 8, 2021
10ab5ce
Add blkio metricset
MichaelKatsoulis Dec 9, 2021
cf1243e
format code
MichaelKatsoulis Dec 9, 2021
de9b9a8
Add cache for containerd metrics
MichaelKatsoulis Dec 14, 2021
578736a
Update method of cpu percentage calculation
MichaelKatsoulis Dec 15, 2021
d1b61d9
Calculate workingset.pct
MichaelKatsoulis Dec 15, 2021
b41c19c
Add tests
MichaelKatsoulis Dec 16, 2021
9e409ea
Merge remote-tracking branch 'upstream/master' into containerd_metric…
MichaelKatsoulis Dec 16, 2021
e293e5e
Make update
MichaelKatsoulis Dec 16, 2021
8339a52
Add check for timestampDelta
MichaelKatsoulis Dec 16, 2021
3dea7e5
Add namespace modulefield
MichaelKatsoulis Dec 17, 2021
a8b3fa1
make update
MichaelKatsoulis Dec 17, 2021
de94d3e
fmt helper
MichaelKatsoulis Dec 17, 2021
2358f5e
Add changelog entry
MichaelKatsoulis Dec 17, 2021
d35b4ce
Add check for memoryLimit different than zero
MichaelKatsoulis Dec 20, 2021
0486457
Prevent zero division
MichaelKatsoulis Dec 20, 2021
980b0a7
Merge remote-tracking branch 'upstream/master' into containerd_metric…
MichaelKatsoulis Dec 20, 2021
5be9960
Review updates
MichaelKatsoulis Dec 22, 2021
f75539b
Update data.json files
MichaelKatsoulis Dec 22, 2021
4cdb805
Update yml files
MichaelKatsoulis Dec 22, 2021
9e80313
Merge remote-tracking branch 'upstream/master' into containerd_metric…
MichaelKatsoulis Dec 22, 2021
c641c38
Make update
MichaelKatsoulis Dec 22, 2021
3ca0046
Update containerd documentation
MichaelKatsoulis Dec 22, 2021
5d30573
Update metricbeat/docs/modules/containerd.asciidoc
MichaelKatsoulis Jan 4, 2022
942c0d9
Merge remote-tracking branch 'upstream/master' into containerd_metric…
MichaelKatsoulis Jan 5, 2022
0dcb148
Make update
MichaelKatsoulis Jan 5, 2022
e66977f
Merge remote-tracking branch 'upstream/master' into containerd_metric…
MichaelKatsoulis Jan 10, 2022
69f4b5f
Metricsets enabled by default
MichaelKatsoulis Jan 11, 2022
edd33ab
Merge remote-tracking branch 'upstream/master' into containerd_metric…
MichaelKatsoulis Jan 11, 2022
34badbe
Add debug message in case of inactiveFiles,usage.total or usage.limit…
MichaelKatsoulis Jan 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ grouped in the following categories:
* <<exported-fields-cockroachdb>>
* <<exported-fields-common>>
* <<exported-fields-consul>>
* <<exported-fields-containerd>>
* <<exported-fields-coredns>>
* <<exported-fields-couchbase>>
* <<exported-fields-couchdb>>
Expand Down Expand Up @@ -10253,6 +10254,107 @@ type: long

--

[[exported-fields-containerd]]
== Containerd fields

Containerd stats collected from containerd



[float]
=== containerd

Information and statistics about containerd's running containers.



[float]
=== cpu

Containerd Runtime CPU metrics.





*`containerd.cpu.usage.kernel.ns`*::
+
--
CPU Kernel usage nanoseconds


type: double

--


*`containerd.cpu.usage.user.ns`*::
+
--
CPU User usage nanoseconds


type: double

--


*`containerd.cpu.usage.total.ns`*::
+
--
CPU total usage nanoseconds


type: double

--

*`containerd.cpu.usage.total.pct`*::
+
--
Percentage of total CPU time normalized by the number of CPU cores


type: scaled_float

format: percent

--

*`containerd.cpu.usage.kernel.pct`*::
+
--
Percentage of time in kernel space normalized by the number of CPU cores.


type: scaled_float

format: percent

--

*`containerd.cpu.usage.user.pct`*::
+
--
Percentage of time in user space normalized by the number of CPU cores.


type: scaled_float

format: percent

--

*`containerd.cpu.usage.cpu.*.ns`*::
+
--
CPU usage nanoseconds in this cpu.


type: object

--

[[exported-fields-coredns]]
== Coredns fields

Expand Down
42 changes: 42 additions & 0 deletions metricbeat/docs/modules/containerd.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
////
This file is generated! See scripts/mage/docs_collector.go
////

:modulename: containerd

[[metricbeat-module-containerd]]
[role="xpack"]
== Containerd module

beta[]

This is the containerd module.



[float]
=== Example configuration

The Containerd module supports the standard configuration options that are described
in <<configuration-metricbeat>>. Here is an example configuration:

[source,yaml]
----
metricbeat.modules:
- module: containerd
metricsets: ["cpu"]
enabled: false
period: 10s
hosts: ["localhost:1338"]

----

[float]
=== Metricsets

The following metricsets are available:

* <<metricbeat-metricset-containerd-cpu,cpu>>

include::containerd/cpu.asciidoc[]

24 changes: 24 additions & 0 deletions metricbeat/docs/modules/containerd/cpu.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
////
This file is generated! See scripts/mage/docs_collector.go
////

[[metricbeat-metricset-containerd-cpu]]
[role="xpack"]
=== Containerd cpu metricset

beta[]

include::../../../../x-pack/metricbeat/module/containerd/cpu/_meta/docs.asciidoc[]


==== Fields

For a description of each field in the metricset, see the
<<exported-fields-containerd,exported fields>> section.

Here is an example document generated by this metricset:

[source,json]
----
include::../../../../x-pack/metricbeat/module/containerd/cpu/_meta/data.json[]
----
3 changes: 3 additions & 0 deletions metricbeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ This file is generated! See scripts/mage/docs_collector.go
.1+| .1+| |<<metricbeat-metricset-cockroachdb-status,status>> beta[]
|<<metricbeat-module-consul,Consul>> beta[] |image:./images/icon-yes.png[Prebuilt dashboards are available] |
.1+| .1+| |<<metricbeat-metricset-consul-agent,agent>> beta[]
|<<metricbeat-module-containerd,Containerd>> beta[] |image:./images/icon-no.png[No prebuilt dashboards] |
.1+| .1+| |<<metricbeat-metricset-containerd-cpu,cpu>> beta[]
|<<metricbeat-module-coredns,Coredns>> |image:./images/icon-yes.png[Prebuilt dashboards are available] |
.1+| .1+| |<<metricbeat-metricset-coredns-stats,stats>>
|<<metricbeat-module-couchbase,Couchbase>> |image:./images/icon-yes.png[Prebuilt dashboards are available] |
Expand Down Expand Up @@ -322,6 +324,7 @@ include::modules/ceph.asciidoc[]
include::modules/cloudfoundry.asciidoc[]
include::modules/cockroachdb.asciidoc[]
include::modules/consul.asciidoc[]
include::modules/containerd.asciidoc[]
include::modules/coredns.asciidoc[]
include::modules/couchbase.asciidoc[]
include::modules/couchdb.asciidoc[]
Expand Down
2 changes: 2 additions & 0 deletions x-pack/metricbeat/include/list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions x-pack/metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@ metricbeat.modules:
hosts: ["localhost:8500"]


#------------------------------ Containerd Module ------------------------------
- module: containerd
metricsets: ["cpu"]
enabled: false
period: 10s
hosts: ["localhost:1338"]
ChrsMark marked this conversation as resolved.
Show resolved Hide resolved


#------------------------------- Coredns Module -------------------------------
- module: coredns
metricsets: ["stats"]
Expand Down
7 changes: 7 additions & 0 deletions x-pack/metricbeat/module/containerd/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- module: containerd
metricsets: ["cpu", "memory"]
enabled: false
period: 10s
hosts: ["localhost:1338"]
calcpct: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought around this. Would it make sense to make it available per metricset instead of having it horizontal effect? Sth like:

calcpct.cpu: true
calcpct.memory: false
calcpctblkio: true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For blkio it is not needed(we don't calculate any percentage) but for cpu and memory makes sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


2 changes: 2 additions & 0 deletions x-pack/metricbeat/module/containerd/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is the containerd module.

11 changes: 11 additions & 0 deletions x-pack/metricbeat/module/containerd/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- key: containerd
title: "Containerd"
release: beta
description: >
Containerd stats collected from containerd
fields:
- name: containerd
type: group
description: >
Information and statistics about containerd's running containers.
fields:
17 changes: 17 additions & 0 deletions x-pack/metricbeat/module/containerd/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package containerd

// Config contains the config needed for containerd
type Config struct {
CalculatePct bool `config:"calcpct"`
}

// DefaultConfig returns default module config
func DefaultConfig() Config {
return Config{
CalculatePct: true,
}
}
19 changes: 19 additions & 0 deletions x-pack/metricbeat/module/containerd/cpu/_meta/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"@timestamp":"2016-05-23T08:05:34.853Z",
"beat":{
"hostname":"beathost",
"name":"beathost"
},
"metricset":{
"host":"localhost",
"module":"containerd",
"name":"cpu",
"rtt":44269
},
"containerd":{
"cpu":{
"example": "cpu"
}
},
"type":"metricsets"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the cpu metricset of the module containerd.
50 changes: 50 additions & 0 deletions x-pack/metricbeat/module/containerd/cpu/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
- name: cpu
type: group
description: >
Containerd Runtime CPU metrics.
release: beta
fields:
- name: usage
type: group
fields:
- name: kernel
type: group
fields:
- name: ns
type: double
description: >
CPU Kernel usage nanoseconds
- name: user
type: group
fields:
- name: ns
type: double
description: >
CPU User usage nanoseconds
- name: total
type: group
fields:
- name: ns
type: double
description: >
CPU total usage nanoseconds
- name: total.pct
type: scaled_float
format: percent
description: >
Percentage of total CPU time normalized by the number of CPU cores
- name: kernel.pct
type: scaled_float
format: percent
description: >
Percentage of time in kernel space normalized by the number of CPU cores.
- name: user.pct
type: scaled_float
format: percent
description: >
Percentage of time in user space normalized by the number of CPU cores.
- name: cpu.*.ns
type: object
object_type: double
description: >
CPU usage nanoseconds in this cpu.
48 changes: 48 additions & 0 deletions x-pack/metricbeat/module/containerd/cpu/cpu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package cpu

import (
"github.com/elastic/beats/v7/metricbeat/helper/prometheus"
"github.com/elastic/beats/v7/metricbeat/mb"
"github.com/elastic/beats/v7/metricbeat/mb/parse"
)

const (
defaultScheme = "http"
defaultPath = "/v1/metrics"
)

var (
// HostParser validates Prometheus URLs
hostParser = parse.URLHostParserBuilder{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this declared globally? I only see it being used in the init function?

DefaultScheme: defaultScheme,
DefaultPath: defaultPath,
}.Build()
)

// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
// Mapping of state metrics
mapping := &prometheus.MetricsMapping{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this map is declared here? I don't think that getMetricsetFactory function is getting reused, so we could just put it in one place?

Metrics: map[string]prometheus.MetricMap{
"container_cpu_total_nanoseconds": prometheus.Metric("usage.total.ns"),
"container_cpu_user_nanoseconds": prometheus.Metric("usage.user.ns"),
"container_cpu_kernel_nanoseconds": prometheus.Metric("usage.kernel.ns"),
"container_per_cpu_nanoseconds": prometheus.Metric("usage.percpu.ns"),
"process_cpu_seconds_total": prometheus.Metric("system.total"),
},
Labels: map[string]prometheus.LabelMap{
"container_id": prometheus.KeyLabel("id"),
"cpu": prometheus.KeyLabel("cpu"),
},
}

mb.Registry.MustAddMetricSet("containerd", "cpu",
getMetricsetFactory(mapping),
mb.WithHostParser(hostParser),
)
}
Loading