aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/prometheus/procfs/sysfs/class_fibrechannel.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/prometheus/procfs/sysfs/class_fibrechannel.go')
-rw-r--r--vendor/github.com/prometheus/procfs/sysfs/class_fibrechannel.go249
1 files changed, 249 insertions, 0 deletions
diff --git a/vendor/github.com/prometheus/procfs/sysfs/class_fibrechannel.go b/vendor/github.com/prometheus/procfs/sysfs/class_fibrechannel.go
new file mode 100644
index 0000000..d57ff9c
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/sysfs/class_fibrechannel.go
@@ -0,0 +1,249 @@
1// Copyright 2020 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// +build !windows
15
16package sysfs
17
18import (
19 "fmt"
20 "io/ioutil"
21 "os"
22 "path/filepath"
23
24 "github.com/prometheus/procfs/internal/util"
25)
26
27const fibrechannelClassPath = "class/fc_host"
28
29type FibreChannelCounters struct {
30 DumpedFrames uint64 // /sys/class/fc_host/<Name>/statistics/dumped_frames
31 ErrorFrames uint64 // /sys/class/fc_host/<Name>/statistics/error_frames
32 InvalidCRCCount uint64 // /sys/class/fc_host/<Name>/statistics/invalid_crc_count
33 RXFrames uint64 // /sys/class/fc_host/<Name>/statistics/rx_frames
34 RXWords uint64 // /sys/class/fc_host/<Name>/statistics/rx_words
35 TXFrames uint64 // /sys/class/fc_host/<Name>/statistics/tx_frames
36 TXWords uint64 // /sys/class/fc_host/<Name>/statistics/tx_words
37 SecondsSinceLastReset uint64 // /sys/class/fc_host/<Name>/statistics/seconds_since_last_reset
38 InvalidTXWordCount uint64 // /sys/class/fc_host/<Name>/statistics/invalid_tx_word_count
39 LinkFailureCount uint64 // /sys/class/fc_host/<Name>/statistics/link_failure_count
40 LossOfSyncCount uint64 // /sys/class/fc_host/<Name>/statistics/loss_of_sync_count
41 LossOfSignalCount uint64 // /sys/class/fc_host/<Name>/statistics/loss_of_signal_count
42 NosCount uint64 // /sys/class/fc_host/<Name>/statistics/nos_count
43 FCPPacketAborts uint64 // / sys/class/fc_host/<Name>/statistics/fcp_packet_aborts
44}
45
46type FibreChannelHost struct {
47 Name string // /sys/class/fc_host/<Name>
48 Speed string // /sys/class/fc_host/<Name>/speed
49 PortState string // /sys/class/fc_host/<Name>/port_state
50 PortType string // /sys/class/fc_host/<Name>/port_type
51 SymbolicName string // /sys/class/fc_host/<Name>/symbolic_name
52 NodeName string // /sys/class/fc_host/<Name>/node_name
53 PortID string // /sys/class/fc_host/<Name>/port_id
54 PortName string // /sys/class/fc_host/<Name>/port_name
55 FabricName string // /sys/class/fc_host/<Name>/fabric_name
56 DevLossTMO string // /sys/class/fc_host/<Name>/dev_loss_tmo
57 SupportedClasses string // /sys/class/fc_host/<Name>/supported_classes
58 SupportedSpeeds string // /sys/class/fc_host/<Name>/supported_speeds
59 Counters FibreChannelCounters // /sys/class/fc_host/<Name>/statistics/*
60}
61
62type FibreChannelClass map[string]FibreChannelHost
63
64// FibreChannelClass parses everything in /sys/class/fc_host.
65func (fs FS) FibreChannelClass() (FibreChannelClass, error) {
66 path := fs.sys.Path(fibrechannelClassPath)
67
68 dirs, err := ioutil.ReadDir(path)
69 if err != nil {
70 return nil, err
71 }
72
73 fcc := make(FibreChannelClass, len(dirs))
74 for _, d := range dirs {
75 host, err := fs.parseFibreChannelHost(d.Name())
76 if err != nil {
77 return nil, err
78 }
79
80 fcc[host.Name] = *host
81 }
82
83 return fcc, nil
84}
85
86// Parse a single FC host
87func (fs FS) parseFibreChannelHost(name string) (*FibreChannelHost, error) {
88 path := fs.sys.Path(fibrechannelClassPath, name)
89 host := FibreChannelHost{Name: name}
90
91 for _, f := range [...]string{"speed", "port_state", "port_type", "node_name", "port_id", "port_name", "fabric_name", "dev_loss_tmo", "symbolic_name", "supported_classes", "supported_speeds"} {
92 name := filepath.Join(path, f)
93 value, err := util.SysReadFile(name)
94 if err != nil {
95 return nil, fmt.Errorf("failed to read file %q: %v", name, err)
96 }
97
98 switch f {
99 case "speed":
100 host.Speed = value
101 case "port_state":
102 host.PortState = value
103 case "port_type":
104 host.PortType = value
105 case "node_name":
106 if len(value) > 2 {
107 value = value[2:]
108 }
109 host.NodeName = value
110 case "port_id":
111 if len(value) > 2 {
112 value = value[2:]
113 }
114 host.PortID = value
115 case "port_name":
116 if len(value) > 2 {
117 value = value[2:]
118 }
119 host.PortName = value
120 case "fabric_name":
121 if len(value) > 2 {
122 value = value[2:]
123 }
124 host.FabricName = value
125 case "dev_loss_tmo":
126 host.DevLossTMO = value
127 case "supported_classes":
128 host.SupportedClasses = value
129 case "supported_speeds":
130 host.SupportedSpeeds = value
131 case "symbolic_name":
132 host.SymbolicName = value
133 }
134 }
135
136 counters, err := parseFibreChannelStatistics(path)
137 if err != nil {
138 return nil, err
139 }
140 host.Counters = *counters
141
142 return &host, nil
143}
144
145// parseFibreChannelStatistics parses metrics from a single FC host.
146func parseFibreChannelStatistics(hostPath string) (*FibreChannelCounters, error) {
147 var counters FibreChannelCounters
148
149 path := filepath.Join(hostPath, "statistics")
150 files, err := ioutil.ReadDir(path)
151 if err != nil {
152 return nil, err
153 }
154
155 for _, f := range files {
156 if !f.Mode().IsRegular() || f.Name() == "reset_statistics" {
157 continue
158 }
159
160 name := filepath.Join(path, f.Name())
161 value, err := util.SysReadFile(name)
162 if err != nil {
163 // there are some write-only files in this directory; we can safely skip over them
164 if os.IsNotExist(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
165 continue
166 }
167 return nil, fmt.Errorf("failed to read file %q: %v", name, err)
168 }
169
170 vp := util.NewValueParser(value)
171
172 // Below switch was automatically generated. Don't need everything in there yet, so the unwanted bits are commented out.
173 switch f.Name() {
174 case "dumped_frames":
175 counters.DumpedFrames = *vp.PUInt64()
176 case "error_frames":
177 counters.ErrorFrames = *vp.PUInt64()
178 /*
179 case "fc_no_free_exch":
180 counters.FcNoFreeExch = *vp.PUInt64()
181 case "fc_no_free_exch_xid":
182 counters.FcNoFreeExchXid = *vp.PUInt64()
183 case "fc_non_bls_resp":
184 counters.FcNonBlsResp = *vp.PUInt64()
185 case "fc_seq_not_found":
186 counters.FcSeqNotFound = *vp.PUInt64()
187 case "fc_xid_busy":
188 counters.FcXidBusy = *vp.PUInt64()
189 case "fc_xid_not_found":
190 counters.FcXidNotFound = *vp.PUInt64()
191 case "fcp_control_requests":
192 counters.FcpControlRequests = *vp.PUInt64()
193 case "fcp_frame_alloc_failures":
194 counters.FcpFrameAllocFailures = *vp.PUInt64()
195 case "fcp_input_megabytes":
196 counters.FcpInputMegabytes = *vp.PUInt64()
197 case "fcp_input_requests":
198 counters.FcpInputRequests = *vp.PUInt64()
199 case "fcp_output_megabytes":
200 counters.FcpOutputMegabytes = *vp.PUInt64()
201 case "fcp_output_requests":
202 counters.FcpOutputRequests = *vp.PUInt64()
203 */
204 case "fcp_packet_aborts":
205 counters.FCPPacketAborts = *vp.PUInt64()
206 /*
207 case "fcp_packet_alloc_failures":
208 counters.FcpPacketAllocFailures = *vp.PUInt64()
209 */
210 case "invalid_tx_word_count":
211 counters.InvalidTXWordCount = *vp.PUInt64()
212 case "invalid_crc_count":
213 counters.InvalidCRCCount = *vp.PUInt64()
214 case "link_failure_count":
215 counters.LinkFailureCount = *vp.PUInt64()
216 /*
217 case "lip_count":
218 counters.LipCount = *vp.PUInt64()
219 */
220 case "loss_of_signal_count":
221 counters.LossOfSignalCount = *vp.PUInt64()
222 case "loss_of_sync_count":
223 counters.LossOfSyncCount = *vp.PUInt64()
224 case "nos_count":
225 counters.NosCount = *vp.PUInt64()
226 /*
227 case "prim_seq_protocol_err_count":
228 counters.PrimSeqProtocolErrCount = *vp.PUInt64()
229 */
230 case "rx_frames":
231 counters.RXFrames = *vp.PUInt64()
232 case "rx_words":
233 counters.RXWords = *vp.PUInt64()
234 case "seconds_since_last_reset":
235 counters.SecondsSinceLastReset = *vp.PUInt64()
236 case "tx_frames":
237 counters.TXFrames = *vp.PUInt64()
238 case "tx_words":
239 counters.TXWords = *vp.PUInt64()
240 }
241
242 if err := vp.Err(); err != nil {
243 return nil, err
244 }
245
246 }
247
248 return &counters, nil
249}