Refactor NFS client collector (#816)
* Update vendor github.com/prometheus/procfs/... * Refactor NFS collector Use new procfs library to parse NFS client stats. * Ignore nfs proc file not existing. * Refactor with reflection to walk the structs.
This commit is contained in:
parent
52c031890e
commit
01bd99fb1a
5 changed files with 202 additions and 156 deletions
4
vendor/github.com/prometheus/procfs/fs.go
generated
vendored
4
vendor/github.com/prometheus/procfs/fs.go
generated
vendored
|
|
@ -46,8 +46,8 @@ func (fs FS) XFSStats() (*xfs.Stats, error) {
|
|||
return xfs.ParseStats(f)
|
||||
}
|
||||
|
||||
// NFSdClientRPCStats retrieves NFS daemon RPC statistics.
|
||||
func (fs FS) NFSdClientRPCStats() (*nfs.ClientRPCStats, error) {
|
||||
// NFSClientRPCStats retrieves NFS client RPC statistics.
|
||||
func (fs FS) NFSClientRPCStats() (*nfs.ClientRPCStats, error) {
|
||||
f, err := os.Open(fs.Path("net/rpc/nfs"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
13
vendor/github.com/prometheus/procfs/nfs/parse.go
generated
vendored
13
vendor/github.com/prometheus/procfs/nfs/parse.go
generated
vendored
|
|
@ -178,8 +178,17 @@ func parseV3Stats(v []uint64) (V3Stats, error) {
|
|||
|
||||
func parseClientV4Stats(v []uint64) (ClientV4Stats, error) {
|
||||
values := int(v[0])
|
||||
if len(v[1:]) != values || values < 59 {
|
||||
return ClientV4Stats{}, fmt.Errorf("invalid V4Stats line %q", v)
|
||||
if len(v[1:]) != values {
|
||||
return ClientV4Stats{}, fmt.Errorf("invalid ClientV4Stats line %q", v)
|
||||
}
|
||||
|
||||
// This function currently supports mapping 59 NFS v4 client stats. Older
|
||||
// kernels may emit fewer stats, so we must detect this and pad out the
|
||||
// values to match the expected slice size.
|
||||
if values < 59 {
|
||||
newValues := make([]uint64, 60)
|
||||
copy(newValues, v)
|
||||
v = newValues
|
||||
}
|
||||
|
||||
return ClientV4Stats{
|
||||
|
|
|
|||
10
vendor/github.com/prometheus/procfs/nfs/parse_nfs.go
generated
vendored
10
vendor/github.com/prometheus/procfs/nfs/parse_nfs.go
generated
vendored
|
|
@ -32,12 +32,12 @@ func ParseClientRPCStats(r io.Reader) (*ClientRPCStats, error) {
|
|||
parts := strings.Fields(scanner.Text())
|
||||
// require at least <key> <value>
|
||||
if len(parts) < 2 {
|
||||
return nil, fmt.Errorf("invalid NFSd metric line %q", line)
|
||||
return nil, fmt.Errorf("invalid NFS metric line %q", line)
|
||||
}
|
||||
|
||||
values, err := util.ParseUint64s(parts[1:])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing NFSd metric line: %s", err)
|
||||
return nil, fmt.Errorf("error parsing NFS metric line: %s", err)
|
||||
}
|
||||
|
||||
switch metricLine := parts[0]; metricLine {
|
||||
|
|
@ -52,15 +52,15 @@ func ParseClientRPCStats(r io.Reader) (*ClientRPCStats, error) {
|
|||
case "proc4":
|
||||
stats.ClientV4Stats, err = parseClientV4Stats(values)
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown NFSd metric line %q", metricLine)
|
||||
return nil, fmt.Errorf("unknown NFS metric line %q", metricLine)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("errors parsing NFSd metric line: %s", err)
|
||||
return nil, fmt.Errorf("errors parsing NFS metric line: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, fmt.Errorf("error scanning NFSd file: %s", err)
|
||||
return nil, fmt.Errorf("error scanning NFS file: %s", err)
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
|
|
|
|||
28
vendor/vendor.json
vendored
28
vendor/vendor.json
vendored
|
|
@ -161,40 +161,40 @@
|
|||
"revisionTime": "2018-01-10T21:49:58Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "lolK0h7LSVERIX8zLyVQ/+7wEyA=",
|
||||
"checksumSHA1": "Qvc01kv3ttHV2P2+J68g9ioU4Qs=",
|
||||
"path": "github.com/prometheus/procfs",
|
||||
"revision": "cb4147076ac75738c9a7d279075a253c0cc5acbd",
|
||||
"revisionTime": "2018-01-25T13:30:57Z"
|
||||
"revision": "282c8707aa210456a825798969cc27edda34992a",
|
||||
"revisionTime": "2018-02-12T14:59:26Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "O64FotgWPYIpl3m2gvTEPIem+xg=",
|
||||
"path": "github.com/prometheus/procfs/bcache",
|
||||
"revision": "cb4147076ac75738c9a7d279075a253c0cc5acbd",
|
||||
"revisionTime": "2018-01-25T13:30:57Z"
|
||||
"revision": "282c8707aa210456a825798969cc27edda34992a",
|
||||
"revisionTime": "2018-02-12T14:59:26Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "lv9rIcjbVEGo8AT1UCUZXhXrfQc=",
|
||||
"path": "github.com/prometheus/procfs/internal/util",
|
||||
"revision": "cb4147076ac75738c9a7d279075a253c0cc5acbd",
|
||||
"revisionTime": "2018-01-25T13:30:57Z"
|
||||
"revision": "282c8707aa210456a825798969cc27edda34992a",
|
||||
"revisionTime": "2018-02-12T14:59:26Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "BXJH5h2ri8SU5qC6kkDvTIGCky4=",
|
||||
"checksumSHA1": "EekY1iRG9JY74mDD0jsbFCWbAFs=",
|
||||
"path": "github.com/prometheus/procfs/nfs",
|
||||
"revision": "cb4147076ac75738c9a7d279075a253c0cc5acbd",
|
||||
"revisionTime": "2018-01-25T13:30:57Z"
|
||||
"revision": "282c8707aa210456a825798969cc27edda34992a",
|
||||
"revisionTime": "2018-02-12T14:59:26Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "wMhQkA/xQw3Q8eI+PIAjFmS94Qo=",
|
||||
"path": "github.com/prometheus/procfs/sysfs",
|
||||
"revision": "cb4147076ac75738c9a7d279075a253c0cc5acbd",
|
||||
"revisionTime": "2018-01-25T13:30:57Z"
|
||||
"revision": "282c8707aa210456a825798969cc27edda34992a",
|
||||
"revisionTime": "2018-02-12T14:59:26Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "yItvTQLUVqm/ArLEbvEhqG0T5a0=",
|
||||
"path": "github.com/prometheus/procfs/xfs",
|
||||
"revision": "cb4147076ac75738c9a7d279075a253c0cc5acbd",
|
||||
"revisionTime": "2018-01-25T13:30:57Z"
|
||||
"revision": "282c8707aa210456a825798969cc27edda34992a",
|
||||
"revisionTime": "2018-02-12T14:59:26Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "ySaT8G3I3y4MmnoXOYAAX0rC+p8=",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue