Sanitize UTF-8 in dmi collector (#2229)

Replace invalid UTF-8 chars with "�" string.

Fixes: https://github.com/prometheus/node_exporter/issues/2228

Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
Ben Kochie 2021-12-01 11:13:43 +01:00 committed by GitHub
parent 5c8d162ca6
commit 1d5afd05b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 3 deletions

View File

@ -5,7 +5,9 @@
* [ENHANCEMENT]
* [BUGFIX]
* [ENHANCEMENT] Add node_softirqs_total metric #2221
* [BUGFIX] Handle nil CPU thermal power status on M1 #2218
* [BUGFIX] Sanitize UTF-8 in dmi collector #2229
## 1.3.0 / 2021-10-20

View File

@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"os"
"strings"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
@ -78,7 +79,7 @@ func NewDMICollector(logger log.Logger) (Collector, error) {
} {
if value != nil {
labels = append(labels, label)
values = append(values, *value)
values = append(values, strings.ToValidUTF8(*value, "<22>"))
}
}

View File

@ -609,7 +609,7 @@ node_disk_written_bytes_total{device="sr0"} 0
node_disk_written_bytes_total{device="vda"} 1.0938236928e+11
# 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.
# TYPE node_dmi_info gauge
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
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="<EFBFBD>[<5B>",system_vendor="Dell Inc."} 1
# HELP node_drbd_activitylog_writes_total Number of updates of the activity log area of the meta data.
# TYPE node_drbd_activitylog_writes_total counter
node_drbd_activitylog_writes_total{device="drbd1"} 1100

View File

@ -141,7 +141,7 @@ Mode: 400
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/class/dmi/id/product_version
Lines: 1
<EFBFBD>[<5B>
Mode: 444
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/class/dmi/id/sys_vendor

View File

@ -11,6 +11,7 @@ enabled_collectors=$(cat << COLLECTORS
cpu
cpufreq
diskstats
dmi
drbd
edac
entropy