mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 00:26:36 +03:00
lib/fs: introduce new metric for Filesystem type name
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
This commit is contained in:
@@ -285,6 +285,7 @@ func initRemoteWriteCtxs(urls []string) {
|
||||
rwctxs[i] = newRemoteWriteCtx(i, remoteWriteURL, sanitizedURL)
|
||||
rwctxIdx[i] = i
|
||||
}
|
||||
fs.RegisterPathFsMetrics(*tmpDataPath)
|
||||
|
||||
if *shardByURL {
|
||||
consistentHashNodes := make([]string, 0, len(urls))
|
||||
|
||||
@@ -180,6 +180,7 @@ func Init(resetCacheIfNeeded func(mrs []storage.MetricRow)) {
|
||||
writeStorageMetrics(w, strg)
|
||||
})
|
||||
metrics.RegisterSet(storageMetrics)
|
||||
fs.RegisterPathFsMetrics(*DataPath)
|
||||
}
|
||||
|
||||
var storageMetrics *metrics.Set
|
||||
|
||||
@@ -31,6 +31,7 @@ See also [LTS releases](https://docs.victoriametrics.com/victoriametrics/lts-rel
|
||||
* FEATURE: [vmalert](https://docs.victoriametrics.com/victoriametrics/vmalert/): add `-rule.stripFilePath` to support stripping rule file paths in logs and all API responses, including /metrics. See [#5625](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5625).
|
||||
* FEATURE: [vmalert](https://docs.victoriametrics.com/victoriametrics/vmalert/): add `formatTime` template function for formatting a Unix timestamp using the provided layout. For example, `{{ now | formatTime "2006-01-02T15:04:05Z07:00" }}` returns the current time in RFC3339 format. See issue [#10624](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/10624). Thanks to @andriibeee for the contribution.
|
||||
* FEATURE: [vmagent](https://docs.victoriametrics.com/victoriametrics/vmagent/), [vmsingle](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/), `vminsert` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/victoriametrics/cluster-victoriametrics/): add support for [Prometheus native histogram](https://prometheus.io/docs/specs/native_histograms/) during ingestion. See [#10743](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/10743).
|
||||
* FEATURE: [vmagent](https://docs.victoriametrics.com/victoriametrics/vmagent/), [vmsingle](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/), `vmselect` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/victoriametrics/cluster-victoriametrics/) and `vmstorage` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/victoriametrics/cluster-victoriametrics/): introduce the `vm_fs_info` metric. It exposes the filesystem type (e.g., ext4, xfs, nfs) used for `-*Path` related flags. See [#10482](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/10482).
|
||||
* FEATURE: [dashboards/vmagent](https://grafana.com/grafana/dashboards/12683): add `Kafka (Enterprise)` row with panels for monitoring traffic (bytes), messages in/out, producer and consumer errors. See [#10728](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/10728).
|
||||
|
||||
* BUGFIX: [vmagent](https://docs.victoriametrics.com/victoriametrics/vmagent/) and [vmsingle](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/): properly obtain `__meta_hetzner_hcloud_location` and `__meta_hetzner_hcloud_location_network_zone` labels for [hetzner_sd_configs](https://docs.victoriametrics.com/victoriametrics/sd_configs/#hetzner_sd_configs). Hetzner changed discovery [API response](https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters) and returns `location` information from different field. See [#10909](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/10909). Thanks to @juliusrickert for contribution.
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/filestream"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs/fsutil"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||
"github.com/VictoriaMetrics/metrics"
|
||||
)
|
||||
|
||||
var tmpFileNum atomicutil.Uint64
|
||||
@@ -352,3 +353,8 @@ type diskSpaceEntry struct {
|
||||
func IsDirOrSymlink(de os.DirEntry) bool {
|
||||
return de.IsDir() || (de.Type()&os.ModeSymlink == os.ModeSymlink)
|
||||
}
|
||||
|
||||
// RegisterPathFsMetrics exposes filesystem information for the given path as metrics.
|
||||
func RegisterPathFsMetrics(path string) {
|
||||
_ = metrics.GetOrCreateGauge(fmt.Sprintf(`vm_fs_info{path=%q, fs_type=%q}`, path, getFsType(path)), func() float64 { return 1 })
|
||||
}
|
||||
|
||||
65
lib/fs/fs_linux.go
Normal file
65
lib/fs/fs_linux.go
Normal file
@@ -0,0 +1,65 @@
|
||||
//go:build linux
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/magic.h
|
||||
var fsMagicNumberToName = map[int64]string{
|
||||
0xEF53: "ext2/ext3/ext4",
|
||||
0xabba1974: "xenfs",
|
||||
0x9123683E: "btrfs",
|
||||
0x3434: "nilfs",
|
||||
0xF2F52010: "f2fs",
|
||||
0xf995e849: "hpfs",
|
||||
0x9660: "isofs",
|
||||
0x72b6: "jffs2",
|
||||
0x58465342: "xfs",
|
||||
0x6165676C: "pstorefs",
|
||||
0xde5e81e4: "efivarfs",
|
||||
0x00c0ffee: "hostfs",
|
||||
0x794c7630: "overlayfs",
|
||||
0x65735546: "fuse",
|
||||
0xca451a4e: "bcachefs",
|
||||
0xadf5: "adfs",
|
||||
0xadff: "affs",
|
||||
0x5346414F: "afs",
|
||||
0x0187: "autofs",
|
||||
0xf15f: "ecryptfs",
|
||||
0x414A53: "efs",
|
||||
0xE0F5E1E2: "erofs",
|
||||
0x6969: "nfs",
|
||||
0xFF534D42: "cifs",
|
||||
0x6c6f6f70: "binderfs",
|
||||
0xBAD1DEA: "futexfs",
|
||||
}
|
||||
|
||||
func getFsType(path string) string {
|
||||
var stat statfs_t
|
||||
fsName := "unknown"
|
||||
err := statfs(path, &stat)
|
||||
if err != nil {
|
||||
return fsName
|
||||
}
|
||||
if fsn, ok := fsMagicNumberToName[int64(stat.Type)]; ok {
|
||||
fsName = fsn
|
||||
}
|
||||
return fsName
|
||||
}
|
||||
@@ -18,3 +18,13 @@ func totalSpace(stat statfs_t) uint64 {
|
||||
func statfs(path string, buf *statfs_t) (err error) {
|
||||
return unix.Statvfs(path, buf)
|
||||
}
|
||||
|
||||
func getFsType(path string) string {
|
||||
var stat statfs_t
|
||||
err := statfs(path, &stat)
|
||||
if err != nil {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
return unix.ByteSliceToString(stat.Fstypename[:])
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build linux || darwin || freebsd
|
||||
//go:build darwin || freebsd
|
||||
|
||||
package fs
|
||||
|
||||
@@ -20,3 +20,13 @@ func totalSpace(stat statfs_t) uint64 {
|
||||
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[:])
|
||||
}
|
||||
|
||||
@@ -18,3 +18,7 @@ func totalSpace(stat statfs_t) uint64 {
|
||||
func statfs(path string, stat *statfs_t) (err error) {
|
||||
return unix.Statfs(path, stat)
|
||||
}
|
||||
|
||||
func getFsType(path string) string {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
@@ -124,3 +124,7 @@ func newOverlapped() (*windows.Overlapped, error) {
|
||||
}
|
||||
return &windows.Overlapped{HEvent: event}, nil
|
||||
}
|
||||
|
||||
func getFsType(_ string) string {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user