...

Source file src/github.com/prometheus/procfs/nfs/parse.go

Documentation: github.com/prometheus/procfs/nfs

     1  // Copyright 2018 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  package nfs
    15  
    16  import (
    17  	"fmt"
    18  )
    19  
    20  func parseReplyCache(v []uint64) (ReplyCache, error) {
    21  	if len(v) != 3 {
    22  		return ReplyCache{}, fmt.Errorf("invalid ReplyCache line %q", v)
    23  	}
    24  
    25  	return ReplyCache{
    26  		Hits:    v[0],
    27  		Misses:  v[1],
    28  		NoCache: v[2],
    29  	}, nil
    30  }
    31  
    32  func parseFileHandles(v []uint64) (FileHandles, error) {
    33  	if len(v) != 5 {
    34  		return FileHandles{}, fmt.Errorf("invalid FileHandles, line %q", v)
    35  	}
    36  
    37  	return FileHandles{
    38  		Stale:        v[0],
    39  		TotalLookups: v[1],
    40  		AnonLookups:  v[2],
    41  		DirNoCache:   v[3],
    42  		NoDirNoCache: v[4],
    43  	}, nil
    44  }
    45  
    46  func parseInputOutput(v []uint64) (InputOutput, error) {
    47  	if len(v) != 2 {
    48  		return InputOutput{}, fmt.Errorf("invalid InputOutput line %q", v)
    49  	}
    50  
    51  	return InputOutput{
    52  		Read:  v[0],
    53  		Write: v[1],
    54  	}, nil
    55  }
    56  
    57  func parseThreads(v []uint64) (Threads, error) {
    58  	if len(v) != 2 {
    59  		return Threads{}, fmt.Errorf("invalid Threads line %q", v)
    60  	}
    61  
    62  	return Threads{
    63  		Threads: v[0],
    64  		FullCnt: v[1],
    65  	}, nil
    66  }
    67  
    68  func parseReadAheadCache(v []uint64) (ReadAheadCache, error) {
    69  	if len(v) != 12 {
    70  		return ReadAheadCache{}, fmt.Errorf("invalid ReadAheadCache line %q", v)
    71  	}
    72  
    73  	return ReadAheadCache{
    74  		CacheSize:      v[0],
    75  		CacheHistogram: v[1:11],
    76  		NotFound:       v[11],
    77  	}, nil
    78  }
    79  
    80  func parseNetwork(v []uint64) (Network, error) {
    81  	if len(v) != 4 {
    82  		return Network{}, fmt.Errorf("invalid Network line %q", v)
    83  	}
    84  
    85  	return Network{
    86  		NetCount:   v[0],
    87  		UDPCount:   v[1],
    88  		TCPCount:   v[2],
    89  		TCPConnect: v[3],
    90  	}, nil
    91  }
    92  
    93  func parseServerRPC(v []uint64) (ServerRPC, error) {
    94  	if len(v) != 5 {
    95  		return ServerRPC{}, fmt.Errorf("invalid RPC line %q", v)
    96  	}
    97  
    98  	return ServerRPC{
    99  		RPCCount: v[0],
   100  		BadCnt:   v[1],
   101  		BadFmt:   v[2],
   102  		BadAuth:  v[3],
   103  		BadcInt:  v[4],
   104  	}, nil
   105  }
   106  
   107  func parseClientRPC(v []uint64) (ClientRPC, error) {
   108  	if len(v) != 3 {
   109  		return ClientRPC{}, fmt.Errorf("invalid RPC line %q", v)
   110  	}
   111  
   112  	return ClientRPC{
   113  		RPCCount:        v[0],
   114  		Retransmissions: v[1],
   115  		AuthRefreshes:   v[2],
   116  	}, nil
   117  }
   118  
   119  func parseV2Stats(v []uint64) (V2Stats, error) {
   120  	values := int(v[0])
   121  	if len(v[1:]) != values || values < 18 {
   122  		return V2Stats{}, fmt.Errorf("invalid V2Stats line %q", v)
   123  	}
   124  
   125  	return V2Stats{
   126  		Null:     v[1],
   127  		GetAttr:  v[2],
   128  		SetAttr:  v[3],
   129  		Root:     v[4],
   130  		Lookup:   v[5],
   131  		ReadLink: v[6],
   132  		Read:     v[7],
   133  		WrCache:  v[8],
   134  		Write:    v[9],
   135  		Create:   v[10],
   136  		Remove:   v[11],
   137  		Rename:   v[12],
   138  		Link:     v[13],
   139  		SymLink:  v[14],
   140  		MkDir:    v[15],
   141  		RmDir:    v[16],
   142  		ReadDir:  v[17],
   143  		FsStat:   v[18],
   144  	}, nil
   145  }
   146  
   147  func parseV3Stats(v []uint64) (V3Stats, error) {
   148  	values := int(v[0])
   149  	if len(v[1:]) != values || values < 22 {
   150  		return V3Stats{}, fmt.Errorf("invalid V3Stats line %q", v)
   151  	}
   152  
   153  	return V3Stats{
   154  		Null:        v[1],
   155  		GetAttr:     v[2],
   156  		SetAttr:     v[3],
   157  		Lookup:      v[4],
   158  		Access:      v[5],
   159  		ReadLink:    v[6],
   160  		Read:        v[7],
   161  		Write:       v[8],
   162  		Create:      v[9],
   163  		MkDir:       v[10],
   164  		SymLink:     v[11],
   165  		MkNod:       v[12],
   166  		Remove:      v[13],
   167  		RmDir:       v[14],
   168  		Rename:      v[15],
   169  		Link:        v[16],
   170  		ReadDir:     v[17],
   171  		ReadDirPlus: v[18],
   172  		FsStat:      v[19],
   173  		FsInfo:      v[20],
   174  		PathConf:    v[21],
   175  		Commit:      v[22],
   176  	}, nil
   177  }
   178  
   179  func parseClientV4Stats(v []uint64) (ClientV4Stats, error) {
   180  	values := int(v[0])
   181  	if len(v[1:]) != values {
   182  		return ClientV4Stats{}, fmt.Errorf("invalid ClientV4Stats line %q", v)
   183  	}
   184  
   185  	// This function currently supports mapping 59 NFS v4 client stats.  Older
   186  	// kernels may emit fewer stats, so we must detect this and pad out the
   187  	// values to match the expected slice size.
   188  	if values < 59 {
   189  		newValues := make([]uint64, 60)
   190  		copy(newValues, v)
   191  		v = newValues
   192  	}
   193  
   194  	return ClientV4Stats{
   195  		Null:               v[1],
   196  		Read:               v[2],
   197  		Write:              v[3],
   198  		Commit:             v[4],
   199  		Open:               v[5],
   200  		OpenConfirm:        v[6],
   201  		OpenNoattr:         v[7],
   202  		OpenDowngrade:      v[8],
   203  		Close:              v[9],
   204  		Setattr:            v[10],
   205  		FsInfo:             v[11],
   206  		Renew:              v[12],
   207  		SetClientID:        v[13],
   208  		SetClientIDConfirm: v[14],
   209  		Lock:               v[15],
   210  		Lockt:              v[16],
   211  		Locku:              v[17],
   212  		Access:             v[18],
   213  		Getattr:            v[19],
   214  		Lookup:             v[20],
   215  		LookupRoot:         v[21],
   216  		Remove:             v[22],
   217  		Rename:             v[23],
   218  		Link:               v[24],
   219  		Symlink:            v[25],
   220  		Create:             v[26],
   221  		Pathconf:           v[27],
   222  		StatFs:             v[28],
   223  		ReadLink:           v[29],
   224  		ReadDir:            v[30],
   225  		ServerCaps:         v[31],
   226  		DelegReturn:        v[32],
   227  		GetACL:             v[33],
   228  		SetACL:             v[34],
   229  		FsLocations:        v[35],
   230  		ReleaseLockowner:   v[36],
   231  		Secinfo:            v[37],
   232  		FsidPresent:        v[38],
   233  		ExchangeID:         v[39],
   234  		CreateSession:      v[40],
   235  		DestroySession:     v[41],
   236  		Sequence:           v[42],
   237  		GetLeaseTime:       v[43],
   238  		ReclaimComplete:    v[44],
   239  		LayoutGet:          v[45],
   240  		GetDeviceInfo:      v[46],
   241  		LayoutCommit:       v[47],
   242  		LayoutReturn:       v[48],
   243  		SecinfoNoName:      v[49],
   244  		TestStateID:        v[50],
   245  		FreeStateID:        v[51],
   246  		GetDeviceList:      v[52],
   247  		BindConnToSession:  v[53],
   248  		DestroyClientID:    v[54],
   249  		Seek:               v[55],
   250  		Allocate:           v[56],
   251  		DeAllocate:         v[57],
   252  		LayoutStats:        v[58],
   253  		Clone:              v[59],
   254  	}, nil
   255  }
   256  
   257  func parseServerV4Stats(v []uint64) (ServerV4Stats, error) {
   258  	values := int(v[0])
   259  	if len(v[1:]) != values || values != 2 {
   260  		return ServerV4Stats{}, fmt.Errorf("invalid V4Stats line %q", v)
   261  	}
   262  
   263  	return ServerV4Stats{
   264  		Null:     v[1],
   265  		Compound: v[2],
   266  	}, nil
   267  }
   268  
   269  func parseV4Ops(v []uint64) (V4Ops, error) {
   270  	values := int(v[0])
   271  	if len(v[1:]) != values || values < 39 {
   272  		return V4Ops{}, fmt.Errorf("invalid V4Ops line %q", v)
   273  	}
   274  
   275  	// nfs v2.5.x 39field and >=v2.6.x 40 field;
   276  	v40 := uint64(0)
   277  	if values > 39 {
   278  		v40 = v[40]
   279  	}
   280  
   281  	stats := V4Ops{
   282  		Op0Unused:          v[1],
   283  		Op1Unused:          v[2],
   284  		Op2Future:          v[3],
   285  		Access:             v[4],
   286  		Close:              v[5],
   287  		Commit:             v[6],
   288  		Create:             v[7],
   289  		DelegPurge:         v[8],
   290  		DelegReturn:        v[9],
   291  		GetAttr:            v[10],
   292  		GetFH:              v[11],
   293  		Link:               v[12],
   294  		Lock:               v[13],
   295  		Lockt:              v[14],
   296  		Locku:              v[15],
   297  		Lookup:             v[16],
   298  		LookupRoot:         v[17],
   299  		Nverify:            v[18],
   300  		Open:               v[19],
   301  		OpenAttr:           v[20],
   302  		OpenConfirm:        v[21],
   303  		OpenDgrd:           v[22],
   304  		PutFH:              v[23],
   305  		PutPubFH:           v[24],
   306  		PutRootFH:          v[25],
   307  		Read:               v[26],
   308  		ReadDir:            v[27],
   309  		ReadLink:           v[28],
   310  		Remove:             v[29],
   311  		Rename:             v[30],
   312  		Renew:              v[31],
   313  		RestoreFH:          v[32],
   314  		SaveFH:             v[33],
   315  		SecInfo:            v[34],
   316  		SetAttr:            v[35],
   317  		SetClientID:        v[36],
   318  		SetClientIDConfirm: v[37],
   319  		Verify:             v[38],
   320  		Write:              v[39],
   321  		RelLockOwner:       v40,
   322  	}
   323  
   324  	return stats, nil
   325  }
   326  

View as plain text