-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #360 from EdSchouten/nfs
Add a collector for NFS client statistics.
- Loading branch information
Showing
5 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
net 70 70 69 45 | ||
rpc 1218785755 374636 1218815394 | ||
proc2 18 16 57 74 52 71 73 45 86 0 52 83 61 17 53 50 23 70 82 | ||
proc3 22 0 1061909262 48906 4077635 117661341 5 29391916 2570425 2993289 590 0 0 7815 15 1130 0 3983 92385 13332 2 1 23729 | ||
proc4 48 98 51 54 83 85 23 24 1 28 73 68 83 12 84 39 68 59 58 88 29 74 69 96 21 84 15 53 86 54 66 56 97 36 49 32 85 81 11 58 32 67 13 28 35 90 1 26 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
// Copyright 2016 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. | ||
|
||
package collector | ||
|
||
import ( | ||
"errors" | ||
"io/ioutil" | ||
"os" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/common/log" | ||
) | ||
|
||
var ( | ||
netLineRE = regexp.MustCompile(`^net \d+ (\d+) (\d+) (\d+)$`) | ||
rpcLineRE = regexp.MustCompile(`^rpc (\d+) (\d+) (\d+)$`) | ||
procLineRE = regexp.MustCompile(`^proc(\d+) \d+ (\d+( \d+)*)$`) | ||
|
||
nfsProcedures = map[string][]string{ | ||
"2": []string{ | ||
"null", "getattr", "setattr", "root", "lookup", | ||
"readlink", "read", "writecache", "write", "create", | ||
"remove", "rename", "link", "symlink", "mkdir", | ||
"rmdir", "readdir", "statfs", | ||
}, | ||
"3": []string{ | ||
"null", "getattr", "setattr", "lookup", "access", | ||
"readlink", "read", "write", "create", "mkdir", | ||
"symlink", "mknod", "remove", "rmdir", "rename", | ||
"link", "readdir", "readdirplus", "fsstat", "fsinfo", | ||
"pathconf", "commit", | ||
}, | ||
"4": []string{ | ||
"null", "read", "write", "commit", "open", | ||
"open_confirm", "open_noattr", "open_downgrade", | ||
"close", "setattr", "fsinfo", "renew", "setclientid", | ||
"setclientid_confirm", "lock", "lockt", "locku", | ||
"access", "getattr", "lookup", "lookup_root", "remove", | ||
"rename", "link", "symlink", "create", "pathconf", | ||
"statfs", "readlink", "readdir", "server_caps", | ||
"delegreturn", "getacl", "setacl", "fs_locations", | ||
"release_lockowner", "secinfo", "fsid_present", | ||
"exchange_id", "create_session", "destroy_session", | ||
"sequence", "get_lease_time", "reclaim_complete", | ||
"layoutget", "getdeviceinfo", "layoutcommit", | ||
"layoutreturn", "secinfo_no_name", "test_stateid", | ||
"free_stateid", "getdevicelist", | ||
"bind_conn_to_session", "destroy_clientid", "seek", | ||
"allocate", "deallocate", "layoutstats", "clone", | ||
"copy", | ||
}, | ||
} | ||
|
||
nfsNetReadsDesc = prometheus.NewDesc( | ||
prometheus.BuildFQName(Namespace, "nfs", "net_reads"), | ||
"Number of reads at the network layer.", | ||
[]string{"protocol"}, | ||
nil, | ||
) | ||
nfsNetConnectionsDesc = prometheus.NewDesc( | ||
prometheus.BuildFQName(Namespace, "nfs", "net_connections"), | ||
"Number of connections at the network layer.", | ||
[]string{"protocol"}, | ||
nil, | ||
) | ||
|
||
nfsRpcOperationsDesc = prometheus.NewDesc( | ||
prometheus.BuildFQName(Namespace, "nfs", "rpc_operations"), | ||
"Number of RPCs performed.", | ||
nil, | ||
nil, | ||
) | ||
nfsRpcRetransmissionsDesc = prometheus.NewDesc( | ||
prometheus.BuildFQName(Namespace, "nfs", "rpc_retransmissions"), | ||
"Number of RPC transmissions performed.", | ||
nil, | ||
nil, | ||
) | ||
nfsRpcAuthenticationRefreshesDesc = prometheus.NewDesc( | ||
prometheus.BuildFQName(Namespace, "nfs", "rpc_authentication_refreshes"), | ||
"Number of RPC authentication refreshes performed.", | ||
nil, | ||
nil, | ||
) | ||
|
||
nfsProceduresDesc = prometheus.NewDesc( | ||
prometheus.BuildFQName(Namespace, "nfs", "procedures"), | ||
"Number of NFS procedures invoked.", | ||
[]string{"version", "procedure"}, | ||
nil, | ||
) | ||
) | ||
|
||
type nfsCollector struct{} | ||
|
||
func init() { | ||
Factories["nfs"] = NewNfsCollector | ||
} | ||
|
||
func NewNfsCollector() (Collector, error) { | ||
return &nfsCollector{}, nil | ||
} | ||
|
||
func (c *nfsCollector) Update(ch chan<- prometheus.Metric) (err error) { | ||
statsFile := procFilePath("net/rpc/nfs") | ||
content, err := ioutil.ReadFile(statsFile) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
log.Debugf("Not collecting NFS statistics, as %s does not exist: %s", statsFile) | ||
return nil | ||
} | ||
return err | ||
} | ||
|
||
for _, line := range strings.Split(string(content), "\n") { | ||
if fields := netLineRE.FindStringSubmatch(line); fields != nil { | ||
value, _ := strconv.ParseFloat(fields[1], 64) | ||
ch <- prometheus.MustNewConstMetric( | ||
nfsNetReadsDesc, prometheus.CounterValue, | ||
value, "udp") | ||
|
||
value, _ = strconv.ParseFloat(fields[2], 64) | ||
ch <- prometheus.MustNewConstMetric( | ||
nfsNetReadsDesc, prometheus.CounterValue, | ||
value, "tcp") | ||
|
||
value, _ = strconv.ParseFloat(fields[3], 64) | ||
ch <- prometheus.MustNewConstMetric( | ||
nfsNetConnectionsDesc, prometheus.CounterValue, | ||
value, "tcp") | ||
} else if fields := rpcLineRE.FindStringSubmatch(line); fields != nil { | ||
value, _ := strconv.ParseFloat(fields[1], 64) | ||
ch <- prometheus.MustNewConstMetric( | ||
nfsRpcOperationsDesc, | ||
prometheus.CounterValue, value) | ||
|
||
value, _ = strconv.ParseFloat(fields[2], 64) | ||
ch <- prometheus.MustNewConstMetric( | ||
nfsRpcRetransmissionsDesc, | ||
prometheus.CounterValue, value) | ||
|
||
value, _ = strconv.ParseFloat(fields[3], 64) | ||
ch <- prometheus.MustNewConstMetric( | ||
nfsRpcAuthenticationRefreshesDesc, | ||
prometheus.CounterValue, value) | ||
} else if fields := procLineRE.FindStringSubmatch(line); fields != nil { | ||
version := fields[1] | ||
for procedure, count := range strings.Split(fields[2], " ") { | ||
value, _ := strconv.ParseFloat(count, 64) | ||
ch <- prometheus.MustNewConstMetric( | ||
nfsProceduresDesc, | ||
prometheus.CounterValue, | ||
value, | ||
version, | ||
nfsProcedures[version][procedure]) | ||
} | ||
} else if line != "" { | ||
return errors.New("Failed to parse line: " + line) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ collectors=$(cat << COLLECTORS | |
meminfo_numa | ||
netdev | ||
netstat | ||
nfs | ||
sockstat | ||
stat | ||
textfile | ||
|