|
| 1 | +// Copyright 2024 The Prometheus Authors |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +//go:build !nofilesystem |
| 15 | +// +build !nofilesystem |
| 16 | + |
| 17 | +package collector |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/power-devops/perfstat" |
| 21 | +) |
| 22 | + |
| 23 | +const ( |
| 24 | + defMountPointsExcluded = "^/(dev|aha)($|/)" |
| 25 | + defFSTypesExcluded = "^procfs$" |
| 26 | +) |
| 27 | + |
| 28 | +// Expose filesystem fullness. |
| 29 | +func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { |
| 30 | + fsStat, err := perfstat.FileSystemStat() |
| 31 | + if err != nil { |
| 32 | + return nil, err |
| 33 | + } |
| 34 | + for _, stat := range fsStat { |
| 35 | + if c.excludedMountPointsPattern.MatchString(stat.MountPoint) { |
| 36 | + c.logger.Debug("Ignoring mount point", "mountpoint", stat.MountPoint) |
| 37 | + continue |
| 38 | + } |
| 39 | + fstype := stat.TypeString() |
| 40 | + if c.excludedFSTypesPattern.MatchString(fstype) { |
| 41 | + c.logger.Debug("Ignoring fs type", "type", fstype) |
| 42 | + continue |
| 43 | + } |
| 44 | + |
| 45 | + ro := 0.0 |
| 46 | + if stat.Flags&perfstat.VFS_READONLY != 0 { |
| 47 | + ro = 1.0 |
| 48 | + } |
| 49 | + |
| 50 | + stats = append(stats, filesystemStats{ |
| 51 | + labels: filesystemLabels{ |
| 52 | + device: stat.Device, |
| 53 | + mountPoint: stat.MountPoint, |
| 54 | + fsType: fstype, |
| 55 | + }, |
| 56 | + size: float64(stat.TotalBlocks / 512.0), |
| 57 | + free: float64(stat.FreeBlocks / 512.0), |
| 58 | + avail: float64(stat.FreeBlocks / 512.0), // AIX doesn't distinguish between free and available blocks. |
| 59 | + files: float64(stat.TotalInodes), |
| 60 | + filesFree: float64(stat.FreeInodes), |
| 61 | + ro: ro, |
| 62 | + }) |
| 63 | + } |
| 64 | + return stats, nil |
| 65 | +} |
0 commit comments