update procfs to latest (#1335)

Updates for procfs refactoring

Signed-off-by: Paul Gier <pgier@redhat.com>
This commit is contained in:
Paul Gier 2019-05-06 23:38:21 -05:00 committed by Ben Kochie
commit 86f9079429
33 changed files with 1966 additions and 1382 deletions

View file

@ -15,6 +15,13 @@
// Fields are documented in https://www.svennd.be/nfsd-stats-explained-procnetrpcnfsd/
package nfs
import (
"os"
"strings"
"github.com/prometheus/procfs/internal/fs"
)
// ReplyCache models the "rc" line.
type ReplyCache struct {
Hits uint64
@ -261,3 +268,46 @@ type ServerRPCStats struct {
ServerV4Stats ServerV4Stats
V4Ops V4Ops
}
// FS represents the pseudo-filesystem proc, which provides an interface to
// kernel data structures.
type FS struct {
proc *fs.FS
}
// NewFS returns a new FS mounted under the given mountPoint. It will error
// if the mount point can't be read.
func NewFS(mountPoint string) (FS, error) {
if strings.TrimSpace(mountPoint) == "" {
mountPoint = fs.DefaultProcMountPoint
}
fs, err := fs.NewFS(mountPoint)
if err != nil {
return FS{}, err
}
return FS{&fs}, nil
}
// ClientRPCStats retrieves NFS client RPC statistics
// from proc/net/rpc/nfs.
func (fs FS) ClientRPCStats() (*ClientRPCStats, error) {
f, err := os.Open(fs.proc.Path("net/rpc/nfs"))
if err != nil {
return nil, err
}
defer f.Close()
return ParseClientRPCStats(f)
}
// ServerRPCStats retrieves NFS daemon RPC statistics
// from proc/net/rpc/nfsd.
func (fs FS) ServerRPCStats() (*ServerRPCStats, error) {
f, err := os.Open(fs.proc.Path("net/rpc/nfsd"))
if err != nil {
return nil, err
}
defer f.Close()
return ParseServerRPCStats(f)
}