|
| 1 | +package collectors |
| 2 | + |
| 3 | + |
| 4 | +import ( |
| 5 | + "github.com/prometheus/client_golang/prometheus" |
| 6 | + "purestorage/fa-openmetrics-exporter/internal/rest-client" |
| 7 | +) |
| 8 | + |
| 9 | +type NetworkInterfacesPerformanceCollector struct { |
| 10 | + BandwidthDesc *prometheus.Desc |
| 11 | + ThroughputDesc *prometheus.Desc |
| 12 | + ErrorsDesc *prometheus.Desc |
| 13 | + Client *client.FAClient |
| 14 | +} |
| 15 | + |
| 16 | +func (c *NetworkInterfacesPerformanceCollector) Describe(ch chan<- *prometheus.Desc) { |
| 17 | + prometheus.DescribeByCollect(c, ch) |
| 18 | +} |
| 19 | + |
| 20 | +func (c *NetworkInterfacesPerformanceCollector) Collect(ch chan<- prometheus.Metric) { |
| 21 | + nwl := c.Client.GetNetworkInterfacesPerformance() |
| 22 | + if len(nwl.Items) == 0 { |
| 23 | + return |
| 24 | + } |
| 25 | + for _, n := range nwl.Items { |
| 26 | + if n.InterfaceType == "eth" { |
| 27 | + ch <- prometheus.MustNewConstMetric( |
| 28 | + c.BandwidthDesc, |
| 29 | + prometheus.GaugeValue, |
| 30 | + n.Eth.ReceivedBytesPerSec, |
| 31 | + n.Name, "received_bytes_per_sec", n.InterfaceType, |
| 32 | + ) |
| 33 | + ch <- prometheus.MustNewConstMetric( |
| 34 | + c.BandwidthDesc, |
| 35 | + prometheus.GaugeValue, |
| 36 | + n.Eth.TransmittedBytesPerSec, |
| 37 | + n.Name, "transmitted_bytes_per_sec", n.InterfaceType, |
| 38 | + ) |
| 39 | + ch <- prometheus.MustNewConstMetric( |
| 40 | + c.ThroughputDesc, |
| 41 | + prometheus.GaugeValue, |
| 42 | + n.Eth.ReceivedPacketsPerSec, |
| 43 | + n.Name, "received_packets_per_sec", n.InterfaceType, |
| 44 | + ) |
| 45 | + ch <- prometheus.MustNewConstMetric( |
| 46 | + c.ThroughputDesc, |
| 47 | + prometheus.GaugeValue, |
| 48 | + n.Eth.TransmittedPacketsPerSec, |
| 49 | + n.Name, "transmitted_packets_per_sec", n.InterfaceType, |
| 50 | + ) |
| 51 | + ch <- prometheus.MustNewConstMetric( |
| 52 | + c.ErrorsDesc, |
| 53 | + prometheus.GaugeValue, |
| 54 | + n.Eth.OtherErrorsPerSec, |
| 55 | + n.Name, "other_errors_per_sec", n.InterfaceType, |
| 56 | + ) |
| 57 | + ch <- prometheus.MustNewConstMetric( |
| 58 | + c.ErrorsDesc, |
| 59 | + prometheus.GaugeValue, |
| 60 | + n.Eth.ReceivedCrcErrorsPerSec, |
| 61 | + n.Name, "received_crc_errors_per_sec", n.InterfaceType, |
| 62 | + ) |
| 63 | + ch <- prometheus.MustNewConstMetric( |
| 64 | + c.ErrorsDesc, |
| 65 | + prometheus.GaugeValue, |
| 66 | + n.Eth.ReceivedFrameErrorsPerSec, |
| 67 | + n.Name, "received_frame_errors_per_sec", n.InterfaceType, |
| 68 | + ) |
| 69 | + ch <- prometheus.MustNewConstMetric( |
| 70 | + c.ErrorsDesc, |
| 71 | + prometheus.GaugeValue, |
| 72 | + n.Eth.TotalErrorsPerSec, |
| 73 | + n.Name, "total_errors_per_sec", n.InterfaceType, |
| 74 | + ) |
| 75 | + ch <- prometheus.MustNewConstMetric( |
| 76 | + c.ErrorsDesc, |
| 77 | + prometheus.GaugeValue, |
| 78 | + n.Eth.TransmittedCarrierErrorsPerSec, |
| 79 | + n.Name, "transmitted_carrier_errors_per_sec", n.InterfaceType, |
| 80 | + ) |
| 81 | + ch <- prometheus.MustNewConstMetric( |
| 82 | + c.ErrorsDesc, |
| 83 | + prometheus.GaugeValue, |
| 84 | + n.Eth.TransmittedDroppedErrorsPerSec, |
| 85 | + n.Name, "transmitted_dropped_errors_per_sec", n.InterfaceType, |
| 86 | + ) |
| 87 | + } |
| 88 | + if n.InterfaceType == "fc" { |
| 89 | + ch <- prometheus.MustNewConstMetric( |
| 90 | + c.BandwidthDesc, |
| 91 | + prometheus.GaugeValue, |
| 92 | + n.Fc.ReceivedBytesPerSec, |
| 93 | + n.Name, "received_bytes_per_sec", n.InterfaceType, |
| 94 | + ) |
| 95 | + ch <- prometheus.MustNewConstMetric( |
| 96 | + c.BandwidthDesc, |
| 97 | + prometheus.GaugeValue, |
| 98 | + n.Fc.TransmittedBytesPerSec, |
| 99 | + n.Name, "transmitted_bytes_per_sec", n.InterfaceType, |
| 100 | + ) |
| 101 | + ch <- prometheus.MustNewConstMetric( |
| 102 | + c.ThroughputDesc, |
| 103 | + prometheus.GaugeValue, |
| 104 | + n.Fc.ReceivedFramesPerSec, |
| 105 | + n.Name, "received_frames_per_sec", n.InterfaceType, |
| 106 | + ) |
| 107 | + ch <- prometheus.MustNewConstMetric( |
| 108 | + c.ThroughputDesc, |
| 109 | + prometheus.GaugeValue, |
| 110 | + n.Fc.TransmittedFramesPerSec, |
| 111 | + n.Name, "transmitted_frames_per_sec", n.InterfaceType, |
| 112 | + ) |
| 113 | + ch <- prometheus.MustNewConstMetric( |
| 114 | + c.ErrorsDesc, |
| 115 | + prometheus.GaugeValue, |
| 116 | + n.Fc.ReceivedCrcErrorsPerSec, |
| 117 | + n.Name, "received_crc_errors_per_sec", n.InterfaceType, |
| 118 | + ) |
| 119 | + ch <- prometheus.MustNewConstMetric( |
| 120 | + c.ErrorsDesc, |
| 121 | + prometheus.GaugeValue, |
| 122 | + n.Fc.ReceivedLinkFailuresPerSec, |
| 123 | + n.Name, "received_link_failures_per_sec", n.InterfaceType, |
| 124 | + ) |
| 125 | + ch <- prometheus.MustNewConstMetric( |
| 126 | + c.ErrorsDesc, |
| 127 | + prometheus.GaugeValue, |
| 128 | + n.Fc.ReceivedLossOfSignalPerSec, |
| 129 | + n.Name, "received_loss_of_signal_per_sec", n.InterfaceType, |
| 130 | + ) |
| 131 | + ch <- prometheus.MustNewConstMetric( |
| 132 | + c.ErrorsDesc, |
| 133 | + prometheus.GaugeValue, |
| 134 | + n.Fc.ReceivedLossOfSyncPerSec, |
| 135 | + n.Name, "received_loss_of_sync_per_sec", n.InterfaceType, |
| 136 | + ) |
| 137 | + ch <- prometheus.MustNewConstMetric( |
| 138 | + c.ErrorsDesc, |
| 139 | + prometheus.GaugeValue, |
| 140 | + n.Fc.TotalErrorsPerSec, |
| 141 | + n.Name, "total_errors_per_sec", n.InterfaceType, |
| 142 | + ) |
| 143 | + ch <- prometheus.MustNewConstMetric( |
| 144 | + c.ErrorsDesc, |
| 145 | + prometheus.GaugeValue, |
| 146 | + n.Fc.TransmittedInvalidWordsPerSec, |
| 147 | + n.Name, "transmitted_invalid_words_per_sec", n.InterfaceType, |
| 148 | + ) |
| 149 | + } |
| 150 | + |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +func NewNetworkInterfacesPerformanceCollector(fa *client.FAClient) *NetworkInterfacesPerformanceCollector { |
| 155 | + return &NetworkInterfacesPerformanceCollector{ |
| 156 | + BandwidthDesc: prometheus.NewDesc( |
| 157 | + "purefa_network_interface_performance_bandwidth_bytes", |
| 158 | + "FlashArray network interface bandwidth", |
| 159 | + []string{"name", "dimension", "type"}, |
| 160 | + prometheus.Labels{}, |
| 161 | + ), |
| 162 | + ThroughputDesc: prometheus.NewDesc( |
| 163 | + "purefa_network_interface_performance_throughput_pkts", |
| 164 | + "FlashArray network interface throughput", |
| 165 | + []string{"name", "dimension", "type"}, |
| 166 | + prometheus.Labels{}, |
| 167 | + ), |
| 168 | + ErrorsDesc: prometheus.NewDesc( |
| 169 | + "purefa_network_interface_performance_errors", |
| 170 | + "FlashArray network interface errors", |
| 171 | + []string{"name", "dimension", "type"}, |
| 172 | + prometheus.Labels{}, |
| 173 | + ), |
| 174 | + Client: fa, |
| 175 | + } |
| 176 | +} |
0 commit comments