From 0a2a54ff2d37c08901689bb60cdcb7e5ee6e4d25 Mon Sep 17 00:00:00 2001 From: Johannes Ziemke Date: Tue, 30 Jul 2024 09:34:59 -0500 Subject: [PATCH] Add AIX filesystem collector Signed-off-by: Johannes Ziemke --- collector/filesystem_aix.go | 65 ++++++++++++++++++++++++++++++++++ collector/filesystem_common.go | 4 +-- go.sum | 3 ++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 collector/filesystem_aix.go diff --git a/collector/filesystem_aix.go b/collector/filesystem_aix.go new file mode 100644 index 00000000..863a26a0 --- /dev/null +++ b/collector/filesystem_aix.go @@ -0,0 +1,65 @@ +// Copyright 2024 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build !nofilesystem +// +build !nofilesystem + +package collector + +import ( + "github.com/power-devops/perfstat" +) + +const ( + defMountPointsExcluded = "^/(dev|aha)($|/)" + defFSTypesExcluded = "^procfs$" +) + +// Expose filesystem fullness. +func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { + fsStat, err := perfstat.FileSystemStat() + if err != nil { + return nil, err + } + for _, stat := range fsStat { + if c.excludedMountPointsPattern.MatchString(stat.MountPoint) { + c.logger.Debug("Ignoring mount point", "mountpoint", stat.MountPoint) + continue + } + fstype := stat.TypeString() + if c.excludedFSTypesPattern.MatchString(fstype) { + c.logger.Debug("Ignoring fs type", "type", fstype) + continue + } + + ro := 0.0 + if stat.Flags&perfstat.VFS_READONLY != 0 { + ro = 1.0 + } + + stats = append(stats, filesystemStats{ + labels: filesystemLabels{ + device: stat.Device, + mountPoint: stat.MountPoint, + fsType: fstype, + }, + size: float64(stat.TotalBlocks / 512.0), + free: float64(stat.FreeBlocks / 512.0), + avail: float64(stat.FreeBlocks / 512.0), // AIX doesn't distinguish between free and available blocks. + files: float64(stat.TotalInodes), + filesFree: float64(stat.FreeInodes), + ro: ro, + }) + } + return stats, nil +} diff --git a/collector/filesystem_common.go b/collector/filesystem_common.go index b3b991d3..0ec55e8a 100644 --- a/collector/filesystem_common.go +++ b/collector/filesystem_common.go @@ -11,9 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !nofilesystem && (linux || freebsd || netbsd || openbsd || darwin || dragonfly) +//go:build !nofilesystem && (linux || freebsd || netbsd || openbsd || darwin || dragonfly || aix) // +build !nofilesystem -// +build linux freebsd netbsd openbsd darwin dragonfly +// +build linux freebsd netbsd openbsd darwin dragonfly aix package collector diff --git a/go.sum b/go.sum index 29f642cc..4890766e 100644 --- a/go.sum +++ b/go.sum @@ -71,6 +71,8 @@ github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaL github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU= +github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/prometheus-community/go-runit v0.1.0 h1:uTWEj/Fn2RoLdfg/etSqwzgYNOYPrARx1BHUN052tGA= github.com/prometheus-community/go-runit v0.1.0/go.mod h1:AvJ9Jo3gAFu2lbM4+qfjdpq30FfiLDJZKbQ015u08IQ= github.com/prometheus/client_golang v1.20.3 h1:oPksm4K8B+Vt35tUhw6GbSNSgVlVSBH0qELP/7u83l4= @@ -110,6 +112,7 @@ golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20211031064116-611d5d643895/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=