Skip to content

Commit f9bf87e

Browse files
bdrungoblitorum
authored andcommitted
Add DMI collector (prometheus#2131)
Add a DMI collector to expose the Desktop Management Interface (DMI) info from `/sys/class/dmi/id/`. This will expose information about the BIOS, mainboard, chassis, and product. Closes: prometheus#303 Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
1 parent 531d6a5 commit f9bf87e

File tree

8 files changed

+234
-3
lines changed

8 files changed

+234
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [BUGFIX]
77

88
* [ENHANCEMENT] Add flag to disable guest CPU metrics #2123
9+
* [ENHANCEMENT] Add DMI collector #303
910
* [BUGFIX] Fix possible panic on macOS #2133
1011

1112
## 1.2.2 / 2021-08-06

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ conntrack | Shows conntrack statistics (does nothing if no `/proc/sys/net/netfil
9898
cpu | Exposes CPU statistics | Darwin, Dragonfly, FreeBSD, Linux, Solaris, OpenBSD
9999
cpufreq | Exposes CPU frequency statistics | Linux, Solaris
100100
diskstats | Exposes disk I/O statistics. | Darwin, Linux, OpenBSD
101+
dmi | Expose Desktop Management Interface (DMI) info from `/sys/class/dmi/id/` | Linux
101102
edac | Exposes error detection and correction statistics. | Linux
102103
entropy | Exposes available entropy. | Linux
103104
exec | Exposes execution statistics. | Dragonfly, FreeBSD

collector/dmi.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2021 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
//go:build linux && !nodmi
15+
// +build linux,!nodmi
16+
17+
package collector
18+
19+
import (
20+
"errors"
21+
"fmt"
22+
"os"
23+
24+
"github.com/go-kit/log"
25+
"github.com/go-kit/log/level"
26+
"github.com/prometheus/client_golang/prometheus"
27+
"github.com/prometheus/procfs/sysfs"
28+
)
29+
30+
type dmiCollector struct {
31+
infoDesc *prometheus.Desc
32+
values []string
33+
}
34+
35+
func init() {
36+
registerCollector("dmi", defaultEnabled, NewDMICollector)
37+
}
38+
39+
// NewDMICollector returns a new Collector exposing DMI information.
40+
func NewDMICollector(logger log.Logger) (Collector, error) {
41+
fs, err := sysfs.NewFS(*sysPath)
42+
if err != nil {
43+
return nil, fmt.Errorf("failed to open sysfs: %w", err)
44+
}
45+
46+
dmi, err := fs.DMIClass()
47+
if err != nil {
48+
if errors.Is(err, os.ErrNotExist) {
49+
level.Debug(logger).Log("msg", "Platform does not support Desktop Management Interface (DMI) information", "err", err)
50+
dmi = &sysfs.DMIClass{}
51+
} else {
52+
return nil, fmt.Errorf("failed to read Desktop Management Interface (DMI) information: %w", err)
53+
}
54+
}
55+
56+
var labels, values []string
57+
for label, value := range map[string]*string{
58+
"bios_date": dmi.BiosDate,
59+
"bios_release": dmi.BiosRelease,
60+
"bios_vendor": dmi.BiosVendor,
61+
"bios_version": dmi.BiosVersion,
62+
"board_asset_tag": dmi.BoardAssetTag,
63+
"board_name": dmi.BoardName,
64+
"board_serial": dmi.BoardSerial,
65+
"board_vendor": dmi.BoardVendor,
66+
"board_version": dmi.BoardVersion,
67+
"chassis_asset_tag": dmi.ChassisAssetTag,
68+
"chassis_serial": dmi.ChassisSerial,
69+
"chassis_vendor": dmi.ChassisVendor,
70+
"chassis_version": dmi.ChassisVersion,
71+
"product_family": dmi.ProductFamily,
72+
"product_name": dmi.ProductName,
73+
"product_serial": dmi.ProductSerial,
74+
"product_sku": dmi.ProductSKU,
75+
"product_uuid": dmi.ProductUUID,
76+
"product_version": dmi.ProductVersion,
77+
"system_vendor": dmi.SystemVendor,
78+
} {
79+
if value != nil {
80+
labels = append(labels, label)
81+
values = append(values, *value)
82+
}
83+
}
84+
85+
// Construct DMI metric only once since it will not change until the next reboot.
86+
return &dmiCollector{
87+
infoDesc: prometheus.NewDesc(
88+
prometheus.BuildFQName(namespace, "dmi", "info"),
89+
"A metric with a constant '1' value labeled by bios_date, bios_release, bios_vendor, bios_version, "+
90+
"board_asset_tag, board_name, board_serial, board_vendor, board_version, chassis_asset_tag, "+
91+
"chassis_serial, chassis_vendor, chassis_version, product_family, product_name, product_serial, "+
92+
"product_sku, product_uuid, product_version, system_vendor if provided by DMI.",
93+
labels, nil,
94+
),
95+
values: values,
96+
}, nil
97+
}
98+
99+
func (c *dmiCollector) Update(ch chan<- prometheus.Metric) error {
100+
if len(c.values) == 0 {
101+
return ErrNoData
102+
}
103+
ch <- prometheus.MustNewConstMetric(c.infoDesc, prometheus.GaugeValue, 1.0, c.values...)
104+
return nil
105+
}

collector/fixtures/e2e-64k-page-output.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ node_disk_written_bytes_total{device="sda"} 2.58916880384e+11
506506
node_disk_written_bytes_total{device="sdb"} 1.01012736e+09
507507
node_disk_written_bytes_total{device="sr0"} 0
508508
node_disk_written_bytes_total{device="vda"} 1.0938236928e+11
509+
# HELP node_dmi_info A metric with a constant '1' value labeled by bios_date, bios_release, bios_vendor, bios_version, board_asset_tag, board_name, board_serial, board_vendor, board_version, chassis_asset_tag, chassis_serial, chassis_vendor, chassis_version, product_family, product_name, product_serial, product_sku, product_uuid, product_version, system_vendor if provided by DMI.
510+
# TYPE node_dmi_info gauge
511+
node_dmi_info{bios_date="04/12/2021",bios_release="2.2",bios_vendor="Dell Inc.",bios_version="2.2.4",board_name="07PXPY",board_serial=".7N62AI2.GRTCL6944100GP.",board_vendor="Dell Inc.",board_version="A01",chassis_asset_tag="",chassis_serial="7N62AI2",chassis_vendor="Dell Inc.",chassis_version="",product_family="PowerEdge",product_name="PowerEdge R6515",product_serial="7N62AI2",product_sku="SKU=NotProvided;ModelName=PowerEdge R6515",product_uuid="83340ca8-cb49-4474-8c29-d2088ca84dd9",product_version="",system_vendor="Dell Inc."} 1
509512
# HELP node_drbd_activitylog_writes_total Number of updates of the activity log area of the meta data.
510513
# TYPE node_drbd_activitylog_writes_total counter
511514
node_drbd_activitylog_writes_total{device="drbd1"} 1100
@@ -2576,6 +2579,7 @@ node_scrape_collector_success{collector="conntrack"} 1
25762579
node_scrape_collector_success{collector="cpu"} 1
25772580
node_scrape_collector_success{collector="cpufreq"} 1
25782581
node_scrape_collector_success{collector="diskstats"} 1
2582+
node_scrape_collector_success{collector="dmi"} 1
25792583
node_scrape_collector_success{collector="drbd"} 1
25802584
node_scrape_collector_success{collector="edac"} 1
25812585
node_scrape_collector_success{collector="entropy"} 1

collector/fixtures/e2e-output.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,9 @@ node_disk_written_bytes_total{device="sdb"} 1.01012736e+09
876876
node_disk_written_bytes_total{device="sdc"} 8.852736e+07
877877
node_disk_written_bytes_total{device="sr0"} 0
878878
node_disk_written_bytes_total{device="vda"} 1.0938236928e+11
879+
# HELP node_dmi_info A metric with a constant '1' value labeled by bios_date, bios_release, bios_vendor, bios_version, board_asset_tag, board_name, board_serial, board_vendor, board_version, chassis_asset_tag, chassis_serial, chassis_vendor, chassis_version, product_family, product_name, product_serial, product_sku, product_uuid, product_version, system_vendor if provided by DMI.
880+
# TYPE node_dmi_info gauge
881+
node_dmi_info{bios_date="04/12/2021",bios_release="2.2",bios_vendor="Dell Inc.",bios_version="2.2.4",board_name="07PXPY",board_serial=".7N62AI2.GRTCL6944100GP.",board_vendor="Dell Inc.",board_version="A01",chassis_asset_tag="",chassis_serial="7N62AI2",chassis_vendor="Dell Inc.",chassis_version="",product_family="PowerEdge",product_name="PowerEdge R6515",product_serial="7N62AI2",product_sku="SKU=NotProvided;ModelName=PowerEdge R6515",product_uuid="83340ca8-cb49-4474-8c29-d2088ca84dd9",product_version="",system_vendor="Dell Inc."} 1
879882
# HELP node_drbd_activitylog_writes_total Number of updates of the activity log area of the meta data.
880883
# TYPE node_drbd_activitylog_writes_total counter
881884
node_drbd_activitylog_writes_total{device="drbd1"} 1100
@@ -3240,6 +3243,7 @@ node_scrape_collector_success{collector="conntrack"} 1
32403243
node_scrape_collector_success{collector="cpu"} 1
32413244
node_scrape_collector_success{collector="cpufreq"} 1
32423245
node_scrape_collector_success{collector="diskstats"} 1
3246+
node_scrape_collector_success{collector="dmi"} 1
32433247
node_scrape_collector_success{collector="drbd"} 1
32443248
node_scrape_collector_success{collector="edac"} 1
32453249
node_scrape_collector_success{collector="entropy"} 1

collector/fixtures/sys.ttar

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,122 @@ SymlinkTo: ../../../devices/system/node/node1
3838
Directory: sys/class
3939
Mode: 755
4040
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41+
Directory: sys/class/dmi
42+
Mode: 775
43+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44+
Directory: sys/class/dmi/id
45+
Mode: 775
46+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47+
Path: sys/class/dmi/id/bios_date
48+
Lines: 1
49+
04/12/2021
50+
Mode: 444
51+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52+
Path: sys/class/dmi/id/bios_release
53+
Lines: 1
54+
2.2
55+
Mode: 444
56+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57+
Path: sys/class/dmi/id/bios_vendor
58+
Lines: 1
59+
Dell Inc.
60+
Mode: 444
61+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62+
Path: sys/class/dmi/id/bios_version
63+
Lines: 1
64+
2.2.4
65+
Mode: 444
66+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
67+
Path: sys/class/dmi/id/board_name
68+
Lines: 1
69+
07PXPY
70+
Mode: 444
71+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72+
Path: sys/class/dmi/id/board_serial
73+
Lines: 1
74+
.7N62AI2.GRTCL6944100GP.
75+
Mode: 400
76+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77+
Path: sys/class/dmi/id/board_vendor
78+
Lines: 1
79+
Dell Inc.
80+
Mode: 444
81+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82+
Path: sys/class/dmi/id/board_version
83+
Lines: 1
84+
A01
85+
Mode: 444
86+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87+
Path: sys/class/dmi/id/chassis_asset_tag
88+
Lines: 1
89+
90+
Mode: 444
91+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92+
Path: sys/class/dmi/id/chassis_serial
93+
Lines: 1
94+
7N62AI2
95+
Mode: 400
96+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
97+
Path: sys/class/dmi/id/chassis_type
98+
Lines: 1
99+
23
100+
Mode: 444
101+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
102+
Path: sys/class/dmi/id/chassis_vendor
103+
Lines: 1
104+
Dell Inc.
105+
Mode: 444
106+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
107+
Path: sys/class/dmi/id/chassis_version
108+
Lines: 1
109+
110+
Mode: 444
111+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
112+
Path: sys/class/dmi/id/modalias
113+
Lines: 1
114+
dmi:bvnDellInc.:bvr2.2.4:bd04/12/2021:br2.2:svnDellInc.:pnPowerEdgeR6515:pvr:rvnDellInc.:rn07PXPY:rvrA01:cvnDellInc.:ct23:cvr:
115+
Mode: 444
116+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
117+
Path: sys/class/dmi/id/product_family
118+
Lines: 1
119+
PowerEdge
120+
Mode: 444
121+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
122+
Path: sys/class/dmi/id/product_name
123+
Lines: 1
124+
PowerEdge R6515
125+
Mode: 444
126+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127+
Path: sys/class/dmi/id/product_serial
128+
Lines: 1
129+
7N62AI2
130+
Mode: 400
131+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
132+
Path: sys/class/dmi/id/product_sku
133+
Lines: 1
134+
SKU=NotProvided;ModelName=PowerEdge R6515
135+
Mode: 444
136+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137+
Path: sys/class/dmi/id/product_uuid
138+
Lines: 1
139+
83340ca8-cb49-4474-8c29-d2088ca84dd9
140+
Mode: 400
141+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
142+
Path: sys/class/dmi/id/product_version
143+
Lines: 1
144+
145+
Mode: 444
146+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147+
Path: sys/class/dmi/id/sys_vendor
148+
Lines: 1
149+
Dell Inc.
150+
Mode: 444
151+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
152+
Path: sys/class/dmi/id/uevent
153+
Lines: 1
154+
MODALIAS=dmi:bvnDellInc.:bvr2.2.4:bd04/12/2021:br2.2:svnDellInc.:pnPowerEdgeR6515:pvr:rvnDellInc.:rn07PXPY:rvrA01:cvnDellInc.:ct23:cvr:
155+
Mode: 644
156+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41157
Directory: sys/class/fc_host
42158
Mode: 755
43159
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/prometheus/client_model v0.2.0
2020
github.com/prometheus/common v0.31.1
2121
github.com/prometheus/exporter-toolkit v0.6.1
22-
github.com/prometheus/procfs v0.7.3
22+
github.com/prometheus/procfs v0.7.4-0.20211011103944-1a7a2bd3279f
2323
github.com/safchain/ethtool v0.0.0-20210803160452-9aa261dae9b1
2424
github.com/siebenmann/go-kstat v0.0.0-20210513183136-173c9b0a9973 // indirect
2525
github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
241241
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
242242
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
243243
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
244-
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
245-
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
244+
github.com/prometheus/procfs v0.7.4-0.20211011103944-1a7a2bd3279f h1:ncXqc93eJV1Ncr3f6GA3MrIDNkNHvcPonRC2QgZaVkQ=
245+
github.com/prometheus/procfs v0.7.4-0.20211011103944-1a7a2bd3279f/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
246246
github.com/prometheus/promu v0.2.0 h1:QKoCatPW0XeOG/9ghBv4qESc4G74NHCzuIzsm6SLVt4=
247247
github.com/prometheus/promu v0.2.0/go.mod h1:7vT+16au8n5E4UrtokdU7btmuJ1bF9df9F9s79Cgs3E=
248248
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

0 commit comments

Comments
 (0)