Index | Thread | Search

From:
Atanas Vladimirov <vlado@bsdbg.net>
Subject:
Telegraf mem plugin and OpenBSD Cache memory
To:
ports@openbsd.org
Date:
Wed, 18 Feb 2026 15:58:24 +0200

Download raw body.

Thread
Hello,

I need your advice on something I just found.
The short version is I started migrating from node_exporter to Telegraf 
and found discrepancy between how Telegraf reports memory usage compared 
to node_exporter.

I have come with this Telegraf patch:

```
Index: plugins/inputs/mem/mem.go
--- plugins/inputs/mem/mem.go.orig
+++ plugins/inputs/mem/mem.go
@@ -50,7 +50,7 @@ func (ms *Mem) Gather(acc telegraf.Accumulator) error
                 fields["wired"] = vm.Wired
         case "openbsd":
                 fields["active"] = vm.Active
-               fields["cached"] = vm.Cached
+               fields["cached"] = vm.Buffers
                 fields["free"] = vm.Free
                 fields["inactive"] = vm.Inactive
                 fields["wired"] = vm.Wired
```

It works.

The problem is that Telegraf reports cached = 0 because gopsutil sets 
Cached = 0.

Here is the gopsutil part
https://github.com/shirou/gopsutil/blob/67304c33f246d9598551d61af85690d50b3e8606/mem/mem_openbsd.go#L41
```
ret := &VirtualMemoryStat{
     Total:    uint64(uvmexp.Npages) * p,
     Free:     uint64(uvmexp.Free) * p,
     Active:   uint64(uvmexp.Active) * p,
     Inactive: uint64(uvmexp.Inactive) * p,
     Cached:   0, // not available   <-- explicitly hardcoded
     Wired:    uint64(uvmexp.Wired) * p,
}
```

The above patch uses `vm.Buffers` from gopsutil and this is what 
node_exporter does.

I'm almost sure that you'll say that this should go upstream, right?

My question is where should I try to send the patch - to Telegraf or to 
gopsutil? What would you suggest?

(a patch for the gopsutil would be something like adding:

```
ret.Cached = ret.Buffers    <-- adds the Cached to be equal to Buffers
```

of course, if this is the path I'll see to check and test it more)

Thanks for you time and please add me in CC to the replies because I'm 
not subscribed to the list.

Best wishes,
Atanas