Skip to content

Commit

Permalink
Add linux/rapl metricset (elastic#28238)
Browse files Browse the repository at this point in the history
* first pass at rapl metricset

* finish up rapl code

* create docs, cleanup

* add config to docs

* x-pack update

* fix rollover issues, naming

* make notice

* fix docs

* add build tags, fix a few things

* create some working tests

* add doc.go files

* run format, again

* please play nice CI
  • Loading branch information
fearful-symmetry authored Oct 19, 2021
1 parent 298d786 commit d2569fd
Show file tree
Hide file tree
Showing 23 changed files with 1,038 additions and 2 deletions.
422 changes: 422 additions & 0 deletions NOTICE.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ require (
github.com/elastic/go-windows v1.0.1
github.com/elastic/gosigar v0.14.1
github.com/fatih/color v1.9.0
github.com/fearful-symmetry/gorapl v0.0.4
github.com/fsnotify/fsevents v0.1.1
github.com/fsnotify/fsnotify v1.4.9
github.com/go-ole/go-ole v1.2.5-0.20190920104607-14974a1cf647 // indirect
Expand Down Expand Up @@ -222,6 +223,7 @@ require (
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/evanphx/json-patch v4.9.0+incompatible // indirect
github.com/fearful-symmetry/gomsr v0.0.1 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/gobuffalo/here v0.6.0 // indirect
github.com/godbus/dbus/v5 v5.0.3 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ github.com/evanphx/json-patch v4.9.0+incompatible h1:kLcOMZeuLAJvL2BPWLMIj5oaZQo
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fearful-symmetry/gomsr v0.0.1 h1:m208RzdTApWVbv8a9kf78rdPLQe+BY9AxRb/nSbHxSA=
github.com/fearful-symmetry/gomsr v0.0.1/go.mod h1:Qb/0Y7zwobP7v8Sji+M5mlL4N7Voyz5WaKXXRFPnLio=
github.com/fearful-symmetry/gorapl v0.0.4 h1:TMn4fhhtIAd+C3NrAl638oaYlX1vgcKNVVdad53oyiE=
github.com/fearful-symmetry/gorapl v0.0.4/go.mod h1:XoeZ+5v0tJX9WMvzqdPaaKAdX7y17mDN3pxDGemINR0=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
Expand Down
97 changes: 97 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -44982,6 +44982,103 @@ type: long

--

[float]
=== rapl

Wattage as reported by Intel RAPL



*`linux.rapl.core`*::
+
--
The core where the RAPL request originated from. Only one core is queried per hardware CPU.


type: long

--

*`linux.rapl.dram.watts`*::
+
--
Power usage in watts on the DRAM RAPL domain


type: float

--

*`linux.rapl.dram.joules`*::
+
--
Raw power usage counter for the DRAM domain


type: float

--

*`linux.rapl.pp0.watts`*::
+
--
Power usage in watts on the PP0 RAPL domain


type: float

--

*`linux.rapl.pp0.joules`*::
+
--
Raw power usage counter for the PP0 domain


type: float

--

*`linux.rapl.pp1.watts`*::
+
--
Power usage in watts on the PP1 RAPL domain


type: float

--

*`linux.rapl.pp1.joules`*::
+
--
Raw power usage counter for the PP1 domain


type: float

--

*`linux.rapl.package.watts`*::
+
--
Power usage in watts on the Package RAPL domain


type: float

--

*`linux.rapl.package.joules`*::
+
--
Raw power usage counter for the package domain


type: float

--

[[exported-fields-logstash]]
== Logstash fields

Expand Down
6 changes: 6 additions & 0 deletions metricbeat/docs/modules/linux.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ metricbeat.modules:
# - conntrack
# - iostat
# - pressure
# - rapl
enabled: true
#hostfs: /hostfs
#rapl.use_msr_safe: false
----

Expand All @@ -55,6 +57,8 @@ The following metricsets are available:

* <<metricbeat-metricset-linux-pressure,pressure>>

* <<metricbeat-metricset-linux-rapl,rapl>>

include::linux/conntrack.asciidoc[]

include::linux/iostat.asciidoc[]
Expand All @@ -67,3 +71,5 @@ include::linux/pageinfo.asciidoc[]

include::linux/pressure.asciidoc[]

include::linux/rapl.asciidoc[]

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

[[metricbeat-metricset-linux-rapl]]
=== Linux rapl metricset

beta[]

include::../../../module/linux/rapl/_meta/docs.asciidoc[]


==== Fields

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

Here is an example document generated by this metricset:

[source,json]
----
include::../../../module/linux/rapl/_meta/data.json[]
----
3 changes: 2 additions & 1 deletion metricbeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,13 @@ This file is generated! See scripts/mage/docs_collector.go
.2+| .2+| |<<metricbeat-metricset-kvm-dommemstat,dommemstat>> beta[]
|<<metricbeat-metricset-kvm-status,status>> beta[]
|<<metricbeat-module-linux,Linux>> beta[] |image:./images/icon-no.png[No prebuilt dashboards] |
.6+| .6+| |<<metricbeat-metricset-linux-conntrack,conntrack>> beta[]
.7+| .7+| |<<metricbeat-metricset-linux-conntrack,conntrack>> beta[]
|<<metricbeat-metricset-linux-iostat,iostat>> beta[]
|<<metricbeat-metricset-linux-ksm,ksm>> beta[]
|<<metricbeat-metricset-linux-memory,memory>> beta[]
|<<metricbeat-metricset-linux-pageinfo,pageinfo>> beta[]
|<<metricbeat-metricset-linux-pressure,pressure>> beta[]
|<<metricbeat-metricset-linux-rapl,rapl>> beta[]
|<<metricbeat-module-logstash,Logstash>> |image:./images/icon-no.png[No prebuilt dashboards] |
.2+| .2+| |<<metricbeat-metricset-logstash-node,node>>
|<<metricbeat-metricset-logstash-node_stats,node_stats>>
Expand Down
1 change: 1 addition & 0 deletions metricbeat/include/list_common.go

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

2 changes: 2 additions & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,10 @@ metricbeat.modules:
# - conntrack
# - iostat
# - pressure
# - rapl
enabled: true
#hostfs: /hostfs
#rapl.use_msr_safe: false


#------------------------------- Logstash Module -------------------------------
Expand Down
2 changes: 2 additions & 0 deletions metricbeat/module/linux/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# - conntrack
# - iostat
# - pressure
# - rapl
enabled: true
#hostfs: /hostfs
#rapl.use_msr_safe: false

2 changes: 1 addition & 1 deletion metricbeat/module/linux/fields.go

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

32 changes: 32 additions & 0 deletions metricbeat/module/linux/rapl/_meta/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"event": {
"dataset": "linux.rapl",
"duration": 115000,
"module": "linux"
},
"linux": {
"rapl": {
"core": 0,
"dram": {
"joules": 38106.59,
"watts": 5.912
},
"package": {
"joules": 25764.9984,
"watts": 11.5784
},
"pp0": {
"joules": 27353.5644,
"watts": 2.7159
}
}
},
"metricset": {
"name": "rapl",
"period": 10000
},
"service": {
"type": "linux"
}
}
43 changes: 43 additions & 0 deletions metricbeat/module/linux/rapl/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
The RAPL metricset reports power usage in Watts as reported by Intel's RAPL (Running Average Power Limit) API. In practice, RAPL is used for setting power usage limits on a CPU, but it can also be used for monitoring power usage.

RAPL is available on most Intel CPUs in some form since Sandy Bridge, however, this implementation requires a linux distro that exposes intel MSRs (model-specific registers) via `/dev/cpu/[CPU]/msr`. You can check to see if your linux distro and CPU support RAPL by running

```
sudo rdmsr 0x606
```
If that command returns a hex value such as `a1003`, RAPL is supported.

RAPL divides a CPU into four domains, each one corresponding to a component within the hardware itself: `Package`, `DRAM`, `PP0` (usually the collective power usage of the cores), and `PP1` (usually the integrated GPU). Not all packages are available on all CPUs, and the RAPL metricset will report all RAPL domains that it finds.


[float]
=== msr-safe usage


This metricset also supports https://github.com/LLNL/msr-safe[msr-safe], which allows a user to access an MSR device without root. The `rapl.use_msr_safe` flag in the linux module config will enable usage of the `/dev/cpu/[CPU]/msr_safe` device.


For existing msr-safe installs, the following allowlist will open all RAPL MSRs for reading:

```
0x00000606 0x0000000000000000 # "SMSR_RAPL_POWER_UNIT"

0x00000610 0x0000000000000000 # "SMSR_PACKAGE_POWER_LIMIT"
0x00000611 0x0000000000000000 # "SMSR_PACKAGE_ENERGY_STATUS"
0x00000613 0x0000000000000000 # "SMSR_PACKAGE_PERF_STATUS"
0x00000614 0x0000000000000000 # "SMSR_PACKAGE_POWER_INFO"

0x00000618 0x0000000000000000 # "SMSR_DRAM_POWER_LIMIT"
0x00000619 0x0000000000000000 # "SMSR_DRAM_ENERGY_STATUS"
0x0000061b 0x0000000000000000 # "SMSR_DRAM_PERF_STATUS"
0x0000061c 0x0000000000000000 # "SMSR_DRAM_POWER_INFO"

0x00000638 0x0000000000000000 # "SMSR_PP0_POWER_LIMIT"
0x00000639 0x0000000000000000 # "SMSR_PP0_ENERGY_STATUS"
0x0000063a 0x0000000000000000 # "SMSR_PP0_POLICY"
0x0000063b 0x0000000000000000 # "SMSR_PP0_PERF_STATUS"

0x00000640 0x0000000000000000 # "SMSR_PP1_POWER_LIMIT"
0x00000641 0x0000000000000000 # "SMSR_PP1_ENERGY_STATUS"
0x00000642 0x0000000000000000 # "SMSR_PP1_POLICY"
```
45 changes: 45 additions & 0 deletions metricbeat/module/linux/rapl/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
- name: rapl
type: group
release: beta
description: >
Wattage as reported by Intel RAPL
fields:
- name: core
type: long
description: >
The core where the RAPL request originated from. Only one core is queried per hardware CPU.
- name: dram.watts
type: float
description: >
Power usage in watts on the DRAM RAPL domain
- name: dram.joules
type: float
description: >
Raw power usage counter for the DRAM domain
- name: pp0.watts
type: float
description: >
Power usage in watts on the PP0 RAPL domain
- name: pp0.joules
type: float
description: >
Raw power usage counter for the PP0 domain
- name: pp1.watts
type: float
description: >
Power usage in watts on the PP1 RAPL domain
- name: pp1.joules
type: float
description: >
Raw power usage counter for the PP1 domain
- name: package.watts
type: float
description: >
Power usage in watts on the Package RAPL domain
- name: package.joules
type: float
description: >
Raw power usage counter for the package domain
18 changes: 18 additions & 0 deletions metricbeat/module/linux/rapl/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package rapl
Binary file added metricbeat/module/linux/rapl/msr_test
Binary file not shown.
Loading

0 comments on commit d2569fd

Please sign in to comment.