Skip to content

Commit 78682c8

Browse files
authored
Merge pull request #1786 from deusnefum/master
Add fibre channel collector
2 parents 22c5aeb + 5a28930 commit 78682c8

File tree

5 files changed

+328
-0
lines changed

5 files changed

+328
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ diskstats | Exposes disk I/O statistics. | Darwin, Linux, OpenBSD
9898
edac | Exposes error detection and correction statistics. | Linux
9999
entropy | Exposes available entropy. | Linux
100100
exec | Exposes execution statistics. | Dragonfly, FreeBSD
101+
fibrechannel | Exposes fibre channel information and statistics from `/sys/class/fc_host/`. | Linux
101102
filefd | Exposes file descriptor statistics from `/proc/sys/fs/file-nr`. | Linux
102103
filesystem | Exposes filesystem statistics, such as disk space used. | Darwin, Dragonfly, FreeBSD, Linux, OpenBSD
103104
hwmon | Expose hardware monitoring and sensor data from `/sys/class/hwmon/`. | Linux

collector/fibrechannel_linux.go

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Copyright 2021 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 linux
15+
// +build !nofibrechannel
16+
17+
package collector
18+
19+
import (
20+
"fmt"
21+
"os"
22+
23+
"github.com/go-kit/kit/log"
24+
"github.com/go-kit/kit/log/level"
25+
"github.com/prometheus/client_golang/prometheus"
26+
"github.com/prometheus/procfs/sysfs"
27+
)
28+
29+
const maxUint64 = ^uint64(0)
30+
31+
type fibrechannelCollector struct {
32+
fs sysfs.FS
33+
metricDescs map[string]*prometheus.Desc
34+
logger log.Logger
35+
subsystem string
36+
}
37+
38+
func init() {
39+
registerCollector("fibrechannel", defaultEnabled, NewFibreChannelCollector)
40+
}
41+
42+
// NewFibreChannelCollector returns a new Collector exposing FibreChannel stats.
43+
func NewFibreChannelCollector(logger log.Logger) (Collector, error) {
44+
var i fibrechannelCollector
45+
var err error
46+
47+
i.fs, err = sysfs.NewFS(*sysPath)
48+
if err != nil {
49+
return nil, fmt.Errorf("failed to open sysfs: %w", err)
50+
}
51+
i.logger = logger
52+
53+
// Detailed description for all metrics.
54+
descriptions := map[string]string{
55+
"dumped_frames_total": "Number of dumped frames",
56+
"loss_of_signal_total": "Number of times signal has been lost",
57+
"loss_of_sync_total": "Number of failures on either bit or transmission word boundaries",
58+
"rx_frames_total": "Number of frames received",
59+
"error_frames_total": "Number of errors in frames",
60+
"invalid_tx_words_total": "Number of invalid words transmitted by host port",
61+
"seconds_since_last_reset_total": "Number of seconds since last host port reset",
62+
"tx_words_total": "Number of words transmitted by host port",
63+
"invalid_crc_total": "Invalid Cyclic Redundancy Check count",
64+
"nos_total": "Number Not_Operational Primitive Sequence received by host port",
65+
"fcp_packet_aborts_total": "Number of aborted packets",
66+
"rx_words_total": "Number of words received by host port",
67+
"tx_frames_total": "Number of frames transmitted by host port",
68+
"link_failure_total": "Number of times the host port link has failed",
69+
"name": "Name of Fibre Channel HBA",
70+
"speed": "Current operating speed",
71+
"port_state": "Current port state",
72+
"port_type": "Port type, what the port is connected to",
73+
"symbolic_name": "Symoblic Name",
74+
"node_name": "Node Name as hexadecimal string",
75+
"port_id": "Port ID as string",
76+
"port_name": "Port Name as hexadecimal string",
77+
"fabric_name": "Fabric Name; 0 if PTP",
78+
"dev_loss_tmo": "Device Loss Timeout in seconds",
79+
"supported_classes": "The FC classes supported",
80+
"supported_speeds": "The FC speeds supported",
81+
}
82+
83+
i.metricDescs = make(map[string]*prometheus.Desc)
84+
i.subsystem = "fibrechannel"
85+
86+
for metricName, description := range descriptions {
87+
i.metricDescs[metricName] = prometheus.NewDesc(
88+
prometheus.BuildFQName(namespace, i.subsystem, metricName),
89+
description,
90+
[]string{"fc_host"},
91+
nil,
92+
)
93+
}
94+
95+
return &i, nil
96+
}
97+
98+
func (c *fibrechannelCollector) pushMetric(ch chan<- prometheus.Metric, name string, value uint64, host string, valueType prometheus.ValueType) {
99+
ch <- prometheus.MustNewConstMetric(c.metricDescs[name], valueType, float64(value), host)
100+
}
101+
102+
func (c *fibrechannelCollector) pushCounter(ch chan<- prometheus.Metric, name string, value uint64, host string) {
103+
// Don't push counters that aren't implemented (a counter equal to maxUint64 is unimplemented by the HBA firmware)
104+
if value != maxUint64 {
105+
c.pushMetric(ch, name, value, host, prometheus.CounterValue)
106+
}
107+
}
108+
109+
func (c *fibrechannelCollector) Update(ch chan<- prometheus.Metric) error {
110+
hosts, err := c.fs.FibreChannelClass()
111+
if err != nil {
112+
if os.IsNotExist(err) {
113+
level.Debug(c.logger).Log("msg", "fibrechannel statistics not found, skipping")
114+
return ErrNoData
115+
}
116+
return fmt.Errorf("error obtaining FibreChannel class info: %s", err)
117+
}
118+
119+
for _, host := range hosts {
120+
infoDesc := prometheus.NewDesc(
121+
prometheus.BuildFQName(namespace, c.subsystem, "info"),
122+
"Non-numeric data from /sys/class/fc_host/<host>, value is always 1.",
123+
[]string{"fc_host", "speed", "port_state", "port_type", "port_id", "port_name", "fabric_name", "symbolic_name", "supported_classes", "supported_speeds", "dev_loss_tmo"},
124+
nil,
125+
)
126+
infoValue := 1.0
127+
128+
// First push the Host values
129+
ch <- prometheus.MustNewConstMetric(infoDesc, prometheus.GaugeValue, infoValue, host.Name, host.Speed, host.PortState, host.PortType, host.PortID, host.PortName, host.FabricName, host.SymbolicName, host.SupportedClasses, host.SupportedSpeeds, host.DevLossTMO)
130+
131+
// Then the counters
132+
c.pushCounter(ch, "dumped_frames_total", host.Counters.DumpedFrames, host.Name)
133+
c.pushCounter(ch, "error_frames_total", host.Counters.ErrorFrames, host.Name)
134+
c.pushCounter(ch, "invalid_crc_total", host.Counters.InvalidCRCCount, host.Name)
135+
c.pushCounter(ch, "rx_frames_total", host.Counters.RXFrames, host.Name)
136+
c.pushCounter(ch, "rx_words_total", host.Counters.RXWords, host.Name)
137+
c.pushCounter(ch, "tx_frames_total", host.Counters.TXFrames, host.Name)
138+
c.pushCounter(ch, "tx_words_total", host.Counters.TXWords, host.Name)
139+
c.pushCounter(ch, "seconds_since_last_reset_total", host.Counters.SecondsSinceLastReset, host.Name)
140+
c.pushCounter(ch, "invalid_tx_words_total", host.Counters.InvalidTXWordCount, host.Name)
141+
c.pushCounter(ch, "link_failure_total", host.Counters.LinkFailureCount, host.Name)
142+
c.pushCounter(ch, "loss_of_sync_total", host.Counters.LossOfSyncCount, host.Name)
143+
c.pushCounter(ch, "loss_of_signal_total", host.Counters.LossOfSignalCount, host.Name)
144+
c.pushCounter(ch, "nos_total", host.Counters.NosCount, host.Name)
145+
c.pushCounter(ch, "fcp_packet_aborts_total", host.Counters.FCPPacketAborts, host.Name)
146+
}
147+
148+
return nil
149+
}

collector/fixtures/e2e-output.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,48 @@ node_entropy_available_bits 1337
659659
node_entropy_pool_size_bits 4096
660660
# HELP node_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which node_exporter was built.
661661
# TYPE node_exporter_build_info gauge
662+
# HELP node_fibrechannel_error_frames_total Number of errors in frames
663+
# TYPE node_fibrechannel_error_frames_total counter
664+
node_fibrechannel_error_frames_total{fc_host="host0"} 0
665+
# HELP node_fibrechannel_fcp_packet_aborts_total Number of aborted packets
666+
# TYPE node_fibrechannel_fcp_packet_aborts_total counter
667+
node_fibrechannel_fcp_packet_aborts_total{fc_host="host0"} 19
668+
# HELP node_fibrechannel_info Non-numeric data from /sys/class/fc_host/<host>, value is always 1.
669+
# TYPE node_fibrechannel_info gauge
670+
node_fibrechannel_info{dev_loss_tmo="30",fabric_name="0",fc_host="host0",port_id="000002",port_name="1000e0071bce95f2",port_state="Online",port_type="Point-To-Point (direct nport connection)",speed="16 Gbit",supported_classes="Class 3",supported_speeds="4 Gbit, 8 Gbit, 16 Gbit",symbolic_name="Emulex SN1100E2P FV12.4.270.3 DV12.4.0.0. HN:gotest. OS:Linux"} 1
671+
# HELP node_fibrechannel_invalid_crc_total Invalid Cyclic Redundancy Check count
672+
# TYPE node_fibrechannel_invalid_crc_total counter
673+
node_fibrechannel_invalid_crc_total{fc_host="host0"} 2
674+
# HELP node_fibrechannel_invalid_tx_words_total Number of invalid words transmitted by host port
675+
# TYPE node_fibrechannel_invalid_tx_words_total counter
676+
node_fibrechannel_invalid_tx_words_total{fc_host="host0"} 8
677+
# HELP node_fibrechannel_link_failure_total Number of times the host port link has failed
678+
# TYPE node_fibrechannel_link_failure_total counter
679+
node_fibrechannel_link_failure_total{fc_host="host0"} 9
680+
# HELP node_fibrechannel_loss_of_signal_total Number of times signal has been lost
681+
# TYPE node_fibrechannel_loss_of_signal_total counter
682+
node_fibrechannel_loss_of_signal_total{fc_host="host0"} 17
683+
# HELP node_fibrechannel_loss_of_sync_total Number of failures on either bit or transmission word boundaries
684+
# TYPE node_fibrechannel_loss_of_sync_total counter
685+
node_fibrechannel_loss_of_sync_total{fc_host="host0"} 16
686+
# HELP node_fibrechannel_nos_total Number Not_Operational Primitive Sequence received by host port
687+
# TYPE node_fibrechannel_nos_total counter
688+
node_fibrechannel_nos_total{fc_host="host0"} 18
689+
# HELP node_fibrechannel_rx_frames_total Number of frames received
690+
# TYPE node_fibrechannel_rx_frames_total counter
691+
node_fibrechannel_rx_frames_total{fc_host="host0"} 3
692+
# HELP node_fibrechannel_rx_words_total Number of words received by host port
693+
# TYPE node_fibrechannel_rx_words_total counter
694+
node_fibrechannel_rx_words_total{fc_host="host0"} 4
695+
# HELP node_fibrechannel_seconds_since_last_reset_total Number of seconds since last host port reset
696+
# TYPE node_fibrechannel_seconds_since_last_reset_total counter
697+
node_fibrechannel_seconds_since_last_reset_total{fc_host="host0"} 7
698+
# HELP node_fibrechannel_tx_frames_total Number of frames transmitted by host port
699+
# TYPE node_fibrechannel_tx_frames_total counter
700+
node_fibrechannel_tx_frames_total{fc_host="host0"} 5
701+
# HELP node_fibrechannel_tx_words_total Number of words transmitted by host port
702+
# TYPE node_fibrechannel_tx_words_total counter
703+
node_fibrechannel_tx_words_total{fc_host="host0"} 6
662704
# HELP node_filefd_allocated File descriptor statistics: allocated.
663705
# TYPE node_filefd_allocated gauge
664706
node_filefd_allocated 1024
@@ -2685,6 +2727,7 @@ node_scrape_collector_success{collector="diskstats"} 1
26852727
node_scrape_collector_success{collector="drbd"} 1
26862728
node_scrape_collector_success{collector="edac"} 1
26872729
node_scrape_collector_success{collector="entropy"} 1
2730+
node_scrape_collector_success{collector="fibrechannel"} 1
26882731
node_scrape_collector_success{collector="filefd"} 1
26892732
node_scrape_collector_success{collector="hwmon"} 1
26902733
node_scrape_collector_success{collector="infiniband"} 1

collector/fixtures/sys.ttar

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,140 @@ SymlinkTo: ../../../devices/system/node/node1
3838
Directory: sys/class
3939
Mode: 755
4040
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41+
Directory: sys/class/fc_host
42+
Mode: 755
43+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44+
Directory: sys/class/fc_host/host0
45+
Mode: 755
46+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47+
Path: sys/class/fc_host/host0/dev_loss_tmo
48+
Lines: 1
49+
30
50+
Mode: 644
51+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52+
Path: sys/class/fc_host/host0/fabric_name
53+
Lines: 1
54+
0x0
55+
Mode: 644
56+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57+
Path: sys/class/fc_host/host0/node_name
58+
Lines: 1
59+
0x2000e0071bce95f2
60+
Mode: 644
61+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62+
Path: sys/class/fc_host/host0/port_id
63+
Lines: 1
64+
0x000002
65+
Mode: 644
66+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
67+
Path: sys/class/fc_host/host0/port_name
68+
Lines: 1
69+
0x1000e0071bce95f2
70+
Mode: 644
71+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72+
Path: sys/class/fc_host/host0/port_state
73+
Lines: 1
74+
Online
75+
Mode: 644
76+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77+
Path: sys/class/fc_host/host0/port_type
78+
Lines: 1
79+
Point-To-Point (direct nport connection)
80+
Mode: 644
81+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82+
Path: sys/class/fc_host/host0/speed
83+
Lines: 1
84+
16 Gbit
85+
Mode: 644
86+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87+
Directory: sys/class/fc_host/host0/statistics
88+
Mode: 755
89+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
90+
Path: sys/class/fc_host/host0/statistics/dumped_frames
91+
Lines: 1
92+
0xffffffffffffffff
93+
Mode: 644
94+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95+
Path: sys/class/fc_host/host0/statistics/error_frames
96+
Lines: 1
97+
0x0
98+
Mode: 644
99+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100+
Path: sys/class/fc_host/host0/statistics/fcp_packet_aborts
101+
Lines: 1
102+
0x13
103+
Mode: 644
104+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
105+
Path: sys/class/fc_host/host0/statistics/invalid_crc_count
106+
Lines: 1
107+
0x2
108+
Mode: 644
109+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
110+
Path: sys/class/fc_host/host0/statistics/invalid_tx_word_count
111+
Lines: 1
112+
0x8
113+
Mode: 644
114+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
115+
Path: sys/class/fc_host/host0/statistics/link_failure_count
116+
Lines: 1
117+
0x9
118+
Mode: 644
119+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120+
Path: sys/class/fc_host/host0/statistics/loss_of_signal_count
121+
Lines: 1
122+
0x11
123+
Mode: 644
124+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
125+
Path: sys/class/fc_host/host0/statistics/loss_of_sync_count
126+
Lines: 1
127+
0x10
128+
Mode: 644
129+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130+
Path: sys/class/fc_host/host0/statistics/nos_count
131+
Lines: 1
132+
0x12
133+
Mode: 644
134+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
135+
Path: sys/class/fc_host/host0/statistics/rx_frames
136+
Lines: 1
137+
0x3
138+
Mode: 644
139+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
140+
Path: sys/class/fc_host/host0/statistics/rx_words
141+
Lines: 1
142+
0x4
143+
Mode: 644
144+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
145+
Path: sys/class/fc_host/host0/statistics/seconds_since_last_reset
146+
Lines: 1
147+
0x7
148+
Mode: 644
149+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150+
Path: sys/class/fc_host/host0/statistics/tx_frames
151+
Lines: 1
152+
0x5
153+
Mode: 644
154+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
155+
Path: sys/class/fc_host/host0/statistics/tx_words
156+
Lines: 1
157+
0x6
158+
Mode: 644
159+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
160+
Path: sys/class/fc_host/host0/supported_classes
161+
Lines: 1
162+
Class 3
163+
Mode: 644
164+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
165+
Path: sys/class/fc_host/host0/supported_speeds
166+
Lines: 1
167+
4 Gbit, 8 Gbit, 16 Gbit
168+
Mode: 644
169+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
170+
Path: sys/class/fc_host/host0/symbolic_name
171+
Lines: 1
172+
Emulex SN1100E2P FV12.4.270.3 DV12.4.0.0. HN:gotest. OS:Linux
173+
Mode: 644
174+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41175
Directory: sys/class/hwmon
42176
Mode: 755
43177
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

end-to-end-test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enabled_collectors=$(cat << COLLECTORS
1414
drbd
1515
edac
1616
entropy
17+
fibrechannel
1718
filefd
1819
hwmon
1920
infiniband

0 commit comments

Comments
 (0)