Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 12 additions & 5 deletions collector/lsblk_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"log/slog"
"os"
"strconv"

"github.com/alecthomas/kingpin/v2"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -53,10 +54,10 @@ type lsblkJSONRoot struct {

type lsblkJSONDevice struct {
Name string `json:"name"`
Size *string `json:"size"`
Size *int64 `json:"size"`
Fstype *string `json:"fstype"`
Mountpoint *string `json:"mountpoint"`
Fsused *string `json:"fsused"`
Fsused *int64 `json:"fsused"`
FsusePct *string `json:"fsuse%"`
Children []lsblkJSONDevice `json:"children"`
}
Expand All @@ -67,6 +68,12 @@ func lsblkStringPtr(s *string) string {
}
return *s
}
func int64PtrToString(i *int64) string {
if i == nil {
return ""
}
return strconv.FormatInt(*i, 10)
}

// lsblkMountpointForLabels maps mount paths under --path.rootfs to the host view (same as filesystem collector).
func lsblkMountpointForLabels(mp *string) string {
Expand All @@ -83,8 +90,8 @@ func (c *lsblkCollector) emitRecursive(ch chan<- prometheus.Metric, devices []ls
parent,
lsblkStringPtr(d.Fstype),
lsblkMountpointForLabels(d.Mountpoint),
lsblkStringPtr(d.Size),
lsblkStringPtr(d.Fsused),
int64PtrToString(d.Size),
int64PtrToString(d.Fsused),
lsblkStringPtr(d.FsusePct),
)
if len(d.Children) > 0 {
Expand All @@ -103,7 +110,7 @@ func (c *lsblkCollector) Update(ch chan<- prometheus.Metric) error {
return ErrNoData
}

args := []string{"--json", "-o", "NAME,SIZE,FSTYPE,MOUNTPOINT,FSUSED,FSUSE%"}
args := []string{"--json", "-b", "-o", "NAME,SIZE,FSTYPE,MOUNTPOINT,FSUSED,FSUSE%"}
cmd := execCommand(path, args...)
out, err := CombinedOutputTimeout(cmd, *lsblkTimeout)
if err != nil {
Expand Down
55 changes: 51 additions & 4 deletions collector/rapl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import (
"errors"
"fmt"
"log/slog"
"os"
"strconv"

"github.com/alecthomas/kingpin/v2"

Check failure on line 22 in collector/rapl_linux.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (goimports)

Check failure on line 22 in collector/rapl_linux.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (goimports)
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
"log/slog"
"os"
"path/filepath"
"strconv"
)

const raplCollectorSubsystem = "rapl"
Expand All @@ -35,6 +35,10 @@
logger *slog.Logger

joulesMetricDesc *prometheus.Desc

constraint0MaxPowerUWDesc *prometheus.Desc
constraint0PowerLimitUWDesc *prometheus.Desc
constraint1PowerLimitUWDesc *prometheus.Desc
}

func init() {
Expand All @@ -59,10 +63,30 @@
[]string{"index", "path", "rapl_zone"}, nil,
)

constraintLabels := []string{"index", "path"}
if *raplZoneLabel {
constraintLabels = []string{"index", "path", "rapl_zone"}
}

collector := raplCollector{
fs: fs,
logger: logger,
joulesMetricDesc: joulesMetricDesc,
constraint0MaxPowerUWDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, raplCollectorSubsystem, "constraint_0_max_power_uw"),
"RAPL constraint_0 maximum power in microwatts (powercap constraint_0_max_power_uw).",
constraintLabels, nil,
),
constraint0PowerLimitUWDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, raplCollectorSubsystem, "constraint_0_power_limit_uw"),
"RAPL constraint_0 power limit in microwatts (powercap constraint_0_power_limit_uw).",
constraintLabels, nil,
),
constraint1PowerLimitUWDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, raplCollectorSubsystem, "constraint_1_power_limit_uw"),
"RAPL constraint_1 power limit in microwatts (powercap constraint_1_power_limit_uw).",
constraintLabels, nil,
),
}
return &collector, nil
}
Expand Down Expand Up @@ -100,10 +124,33 @@
} else {
ch <- c.joulesMetric(rz, joules)
}

c.emitRAPLConstraintUW(ch, c.constraint0MaxPowerUWDesc, rz, "constraint_0_max_power_uw")
c.emitRAPLConstraintUW(ch, c.constraint0PowerLimitUWDesc, rz, "constraint_0_power_limit_uw")
c.emitRAPLConstraintUW(ch, c.constraint1PowerLimitUWDesc, rz, "constraint_1_power_limit_uw")
}
return nil
}

func (c *raplCollector) emitRAPLConstraintUW(ch chan<- prometheus.Metric, desc *prometheus.Desc, rz sysfs.RaplZone, fileName string) {
p := filepath.Join(rz.Path, fileName)
v, err := readUintFromFile(p)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return
}
c.logger.Debug("skipping RAPL constraint file", "path", p, "err", err)
return
}

index := strconv.Itoa(rz.Index)
if *raplZoneLabel {
ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, float64(v), index, rz.Path, rz.Name)
return
}
ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, float64(v), index, rz.Path)
}

func (c *raplCollector) joulesMetric(z sysfs.RaplZone, v float64) prometheus.Metric {
index := strconv.Itoa(z.Index)
descriptor := prometheus.NewDesc(
Expand Down
Loading