Use NewMetric to create a new metric

This commit is contained in:
Holger Obermaier
2026-05-06 13:22:02 +02:00
parent 0f6fee9db4
commit 8e58072ff6
16 changed files with 52 additions and 141 deletions

View File

@@ -128,30 +128,14 @@ mountLoop:
tags := map[string]string{"type": "node", "device": linefields[0]}
total := (stat.Blocks * uint64(stat.Bsize)) / uint64(1000_000_000)
if m.allowedMetrics["disk_total"] {
y, err := lp.NewMessage(
"disk_total",
tags,
m.meta,
map[string]any{
"value": total,
},
time.Now())
if err == nil {
if y, err := lp.NewMetric("disk_total", tags, m.meta, total, time.Now()); err == nil {
y.AddMeta("unit", "GBytes")
output <- y
}
}
free := (stat.Bfree * uint64(stat.Bsize)) / uint64(1000_000_000)
if m.allowedMetrics["disk_free"] {
y, err := lp.NewMessage(
"disk_free",
tags,
m.meta,
map[string]any{
"value": free,
},
time.Now())
if err == nil {
if y, err := lp.NewMetric("disk_free", tags, m.meta, free, time.Now()); err == nil {
y.AddMeta("unit", "GBytes")
output <- y
}
@@ -164,16 +148,7 @@ mountLoop:
}
}
if m.allowedMetrics["part_max_used"] {
y, err := lp.NewMessage(
"part_max_used",
map[string]string{
"type": "node",
},
m.meta,
map[string]any{
"value": int(part_max_used),
},
time.Now())
y, err := lp.NewMetric("part_max_used", map[string]string{"type": "node"}, m.meta, int(part_max_used), time.Now())
if err == nil {
y.AddMeta("unit", "percent")
output <- y