fs

package
v0.55.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 14 Imported by: 1,593

Documentation

Overview

Provides Filesystem Stats

Index

Constants

View Source
const (
	LabelSystemRoot          = "root"
	LabelDockerImages        = "docker-images"
	LabelCrioImages          = "crio-images"
	LabelCrioContainers      = "crio-containers"
	DriverStatusPoolName     = "Pool Name"
	DriverStatusDataLoopFile = "Data loop file"
)

Variables

View Source
var (
	// ErrNoSuchDevice is the error indicating the requested device does not exist.
	ErrNoSuchDevice = errors.New("cadvisor: no such device")

	// ErrDeviceNotInPartitionsMap is the error resulting if a device could not be found in the partitions map.
	ErrDeviceNotInPartitionsMap = errors.New("could not find device in cached partitions map")
)
View Source
var ErrFallbackToVFS = errors.New("fallback to VFS")

ErrFallbackToVFS signals that a specialized plugin cannot handle this filesystem and VFS should be used instead.

Functions

func InitializeWatchers added in v0.55.0

func InitializeWatchers() map[string]FsWatcher

InitializeWatchers starts all plugin watchers and returns them.

func RegisterPlugin added in v0.55.0

func RegisterPlugin(name string, plugin FsPlugin) error

RegisterPlugin registers a filesystem plugin. This should be called from init() functions.

func StopWatchers added in v0.55.0

func StopWatchers(watchers map[string]FsWatcher)

StopWatchers stops all provided watchers.

Types

type Context

type Context struct {
	// docker root directory.
	Docker DockerContext
	Crio   CrioContext
	Podman PodmanContext
}

type CrioContext added in v0.27.1

type CrioContext struct {
	Root       string
	ImageStore string
	Driver     string
}

type DeviceInfo

type DeviceInfo struct {
	Device string
	Major  uint
	Minor  uint
}

type DiskStats

type DiskStats struct {
	MajorNum        uint64
	MinorNum        uint64
	ReadsCompleted  uint64
	ReadsMerged     uint64
	SectorsRead     uint64
	ReadTime        uint64
	WritesCompleted uint64
	WritesMerged    uint64
	SectorsWritten  uint64
	WriteTime       uint64
	IoInProgress    uint64
	IoTime          uint64
	WeightedIoTime  uint64
	Major           uint64
	Minor           uint64
}

type DockerContext added in v0.23.0

type DockerContext struct {
	Root         string
	Driver       string
	DriverStatus map[string]string
}

type Fs

type Fs struct {
	DeviceInfo
	Type       FsType
	Capacity   uint64
	Free       uint64
	Available  uint64
	Inodes     *uint64
	InodesFree *uint64
	DiskStats  DiskStats
}

type FsCachingPlugin added in v0.55.0

type FsCachingPlugin interface {
	FsPlugin

	// CacheKey returns a cache key for the given partition.
	// Stats will be cached by this key and reused for partitions with the same key.
	// Return empty string to disable caching for a specific partition.
	CacheKey(partition PartitionInfo) string
}

FsCachingPlugin is an optional interface for plugins that want to cache stats by a key (e.g., device ID) to avoid redundant stat calls. This is useful for network filesystems like NFS where multiple mounts may point to the same underlying device.

type FsInfo

type FsInfo interface {
	// Returns capacity and free space, in bytes, of all the ext2, ext3, ext4 filesystems on the host.
	GetGlobalFsInfo() ([]Fs, error)

	// Returns capacity and free space, in bytes, of the set of mounts passed.
	GetFsInfoForPath(mountSet map[string]struct{}) ([]Fs, error)

	// GetDirUsage returns a usage information for 'dir'.
	GetDirUsage(dir string) (UsageInfo, error)

	// GetDeviceInfoByFsUUID returns the information of the device with the
	// specified filesystem uuid. If no such device exists, this function will
	// return the ErrNoSuchDevice error.
	GetDeviceInfoByFsUUID(uuid string) (*DeviceInfo, error)

	// Returns the block device info of the filesystem on which 'dir' resides.
	GetDirFsDevice(dir string) (*DeviceInfo, error)

	// Returns the device name associated with a particular label.
	GetDeviceForLabel(label string) (string, error)

	// Returns all labels associated with a particular device name.
	GetLabelsForDevice(device string) ([]string, error)

	// Returns the mountpoint associated with a particular device.
	GetMountpointForDevice(device string) (string, error)
}

func NewFsInfo

func NewFsInfo(context Context) (FsInfo, error)

type FsPlugin added in v0.55.0

type FsPlugin interface {
	// Name returns the plugin identifier (e.g., "zfs", "devicemapper", "vfs").
	Name() string

	// CanHandle returns true if this plugin handles the given filesystem type.
	CanHandle(fsType string) bool

	// Priority returns the plugin priority (higher = checked first).
	// Allows specific plugins (zfs, btrfs) to override generic (vfs).
	Priority() int

	// GetStats returns filesystem statistics for a partition.
	GetStats(device string, partition PartitionInfo) (*FsStats, error)

	// ProcessMount optionally modifies mount info during processing.
	// Returns (shouldInclude bool, modifiedMount *mount.Info, error).
	ProcessMount(mnt *mount.Info) (bool, *mount.Info, error)
}

FsPlugin provides filesystem-specific statistics collection.

func GetAllPlugins added in v0.55.0

func GetAllPlugins() []FsPlugin

GetAllPlugins returns all registered plugins.

func GetPluginForFsType added in v0.55.0

func GetPluginForFsType(fsType string) FsPlugin

GetPluginForFsType returns the appropriate plugin for the filesystem type. Returns nil if no plugin can handle the filesystem type.

type FsStats added in v0.55.0

type FsStats struct {
	Capacity   uint64
	Free       uint64
	Available  uint64
	Inodes     *uint64
	InodesFree *uint64
	Type       FsType
}

FsStats contains filesystem statistics returned by plugins.

type FsType added in v0.22.0

type FsType string
const (
	ZFS          FsType = "zfs"
	DeviceMapper FsType = "devicemapper"
	VFS          FsType = "vfs"
	NFS          FsType = "nfs"
)

func (FsType) String added in v0.22.0

func (ft FsType) String() string

type FsWatcher added in v0.55.0

type FsWatcher interface {
	// GetUsage returns filesystem usage for a specific container/path.
	GetUsage(containerID string, deviceID string) (uint64, error)

	// Stop stops the background monitoring.
	Stop()
}

FsWatcher provides container-level filesystem usage from background monitoring.

type FsWatcherPlugin added in v0.55.0

type FsWatcherPlugin interface {
	FsPlugin

	// StartWatcher starts background monitoring.
	// Returns a Watcher that can be used to get container-level usage.
	StartWatcher() (FsWatcher, error)
}

FsWatcherPlugin is an optional interface for plugins that provide background monitoring (e.g., ZFS watcher, ThinPool watcher).

type PartitionInfo added in v0.55.0

type PartitionInfo struct {
	Mountpoint string
	Major      uint
	Minor      uint
	FsType     string
	BlockSize  uint
}

PartitionInfo contains information needed for stats collection.

type PodmanContext added in v0.48.0

type PodmanContext struct {
	Root         string
	Driver       string
	DriverStatus map[string]string
}

type RealFsInfo

type RealFsInfo struct {
	// contains filtered or unexported fields
}

func (*RealFsInfo) GetDeviceForLabel

func (i *RealFsInfo) GetDeviceForLabel(label string) (string, error)

func (*RealFsInfo) GetDeviceInfoByFsUUID added in v0.27.0

func (i *RealFsInfo) GetDeviceInfoByFsUUID(uuid string) (*DeviceInfo, error)

func (*RealFsInfo) GetDirFsDevice

func (i *RealFsInfo) GetDirFsDevice(dir string) (*DeviceInfo, error)

func (*RealFsInfo) GetDirUsage

func (i *RealFsInfo) GetDirUsage(dir string) (UsageInfo, error)

func (*RealFsInfo) GetFsInfoForPath

func (i *RealFsInfo) GetFsInfoForPath(mountSet map[string]struct{}) ([]Fs, error)

func (*RealFsInfo) GetGlobalFsInfo

func (i *RealFsInfo) GetGlobalFsInfo() ([]Fs, error)

func (*RealFsInfo) GetLabelsForDevice

func (i *RealFsInfo) GetLabelsForDevice(device string) ([]string, error)

func (*RealFsInfo) GetMountpointForDevice

func (i *RealFsInfo) GetMountpointForDevice(dev string) (string, error)

type UsageInfo added in v0.33.0

type UsageInfo struct {
	Bytes  uint64
	Inodes uint64
}

func GetDirUsage added in v0.33.0

func GetDirUsage(dir string) (UsageInfo, error)

Directories

Path Synopsis
nfs
vfs
zfs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL