mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 00:26:36 +03:00
This commit introduces a new metric to expose fs type for the provided path.
For example:
```
vm_fs_info{path="/vmstorage-data", fs_type="xfs"}
```
Path must be registered with new method `fs.RegisterPathFsMetrics`.
fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/10482
33 lines
647 B
Go
33 lines
647 B
Go
//go:build darwin || freebsd
|
|
|
|
package fs
|
|
|
|
import (
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
type statfs_t = unix.Statfs_t
|
|
|
|
func freeSpace(stat statfs_t) uint64 {
|
|
return uint64(stat.Bavail) * uint64(stat.Bsize)
|
|
}
|
|
|
|
// totalSpace returns the total capacity of the filesystem described by stat in bytes.
|
|
func totalSpace(stat statfs_t) uint64 {
|
|
return uint64(stat.Blocks) * uint64(stat.Bsize)
|
|
}
|
|
|
|
func statfs(path string, stat *statfs_t) (err error) {
|
|
return unix.Statfs(path, stat)
|
|
}
|
|
|
|
func getFsType(path string) string {
|
|
var stat statfs_t
|
|
err := statfs(path, &stat)
|
|
if err != nil {
|
|
return "unknown"
|
|
}
|
|
|
|
return unix.ByteSliceToString(stat.Fstypename[:])
|
|
}
|