Files
VictoriaMetrics/lib/osinfo/info_linux.go
JAYICE 211fb08028 introduce os kernel version information metric (#10746)
The commit introduces the `vm_os_info` metric, which is exposed by all VM binaries by default. It provides visibility into the operating system version on which VictoriaMetrics is running, helping with troubleshooting environment-specific issues, like known kernel or fs bugs. 

FIxes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/10481
PR https://github.com/VictoriaMetrics/VictoriaMetrics/pull/10746

Co-authored-by: Max Kotliar <mkotlyar@victoriametrics.com>
2026-04-09 14:43:25 +03:00

31 lines
689 B
Go

package osinfo
import (
"fmt"
"syscall"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/metrics"
)
var linuxRelease string
func ExposeAsMetric() {
var uname syscall.Utsname
if err := syscall.Uname(&uname); err != nil {
logger.Warnf("os info wont be exposed as vm_os_info metric; failed to call syscall.Uname: %s", err)
return
}
release := make([]byte, 0, len(uname.Release))
for _, v := range uname.Release {
if v == 0 {
break
}
release = append(release, byte(v))
}
linuxRelease = string(release)
_ = metrics.GetOrCreateGauge(fmt.Sprintf(`vm_os_info{os="linux", release=%q}`, linuxRelease), func() float64 { return 1 })
}