|
| 1 | +package collector |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/manahl/prometheus-flashblade-exporter/fb" |
| 5 | + "github.com/prometheus/client_golang/prometheus" |
| 6 | + "github.com/prometheus/common/log" |
| 7 | +) |
| 8 | + |
| 9 | +type ArrayPerformanceCollector struct { |
| 10 | + fbClient *fb.FlashbladeClient |
| 11 | + BytesPerOp *prometheus.Desc |
| 12 | + BytesPerRead *prometheus.Desc |
| 13 | + BytesPerWrite *prometheus.Desc |
| 14 | + OthersPerSec *prometheus.Desc |
| 15 | + OutputPerSec *prometheus.Desc |
| 16 | + ReadsPerSec *prometheus.Desc |
| 17 | + UsecPerOtherOp *prometheus.Desc |
| 18 | + UsecPerReadOp *prometheus.Desc |
| 19 | + UsecPerWriteOp *prometheus.Desc |
| 20 | + InputPerSec *prometheus.Desc |
| 21 | + WritesPerSec *prometheus.Desc |
| 22 | +} |
| 23 | + |
| 24 | +func NewArrayPerformanceCollector(fbClient *fb.FlashbladeClient) *ArrayPerformanceCollector { |
| 25 | + const subsystem = "perf" |
| 26 | + |
| 27 | + return &ArrayPerformanceCollector{ |
| 28 | + fbClient: fbClient, |
| 29 | + BytesPerOp: prometheus.NewDesc( |
| 30 | + prometheus.BuildFQName(namespace, subsystem, "bytes_per_op"), |
| 31 | + "Average operation size (read bytes+write bytes/(read ops+write ops))", |
| 32 | + nil, |
| 33 | + prometheus.Labels{"host": fbClient.Host}, |
| 34 | + ), |
| 35 | + BytesPerRead: prometheus.NewDesc( |
| 36 | + prometheus.BuildFQName(namespace, subsystem, "bytes_per_read"), |
| 37 | + "Average read size in bytes per read operation", |
| 38 | + nil, |
| 39 | + prometheus.Labels{"host": fbClient.Host}, |
| 40 | + ), |
| 41 | + BytesPerWrite: prometheus.NewDesc( |
| 42 | + prometheus.BuildFQName(namespace, subsystem, "bytes_per_write"), |
| 43 | + "Average write size in bytes per write operation", |
| 44 | + nil, |
| 45 | + prometheus.Labels{"host": fbClient.Host}, |
| 46 | + ), |
| 47 | + OthersPerSec: prometheus.NewDesc( |
| 48 | + prometheus.BuildFQName(namespace, subsystem, "others_per_sec"), |
| 49 | + "Other operations processed per second", |
| 50 | + nil, |
| 51 | + prometheus.Labels{"host": fbClient.Host}, |
| 52 | + ), |
| 53 | + OutputPerSec: prometheus.NewDesc( |
| 54 | + prometheus.BuildFQName(namespace, subsystem, "output_per_sec"), |
| 55 | + "Bytes read per second", |
| 56 | + nil, |
| 57 | + prometheus.Labels{"host": fbClient.Host}, |
| 58 | + ), |
| 59 | + ReadsPerSec: prometheus.NewDesc( |
| 60 | + prometheus.BuildFQName(namespace, subsystem, "reads_per_sec"), |
| 61 | + "Read requests processed per second", |
| 62 | + nil, |
| 63 | + prometheus.Labels{"host": fbClient.Host}, |
| 64 | + ), |
| 65 | + UsecPerOtherOp: prometheus.NewDesc( |
| 66 | + prometheus.BuildFQName(namespace, subsystem, "usec_per_other_op"), |
| 67 | + "Average time, measured in microseconds, that the array takes to process other operations", |
| 68 | + nil, |
| 69 | + prometheus.Labels{"host": fbClient.Host}, |
| 70 | + ), |
| 71 | + UsecPerReadOp: prometheus.NewDesc( |
| 72 | + prometheus.BuildFQName(namespace, subsystem, "usec_per_read_op"), |
| 73 | + "Average time, measured in microseconds, that the array takes to process a read request", |
| 74 | + nil, |
| 75 | + prometheus.Labels{"host": fbClient.Host}, |
| 76 | + ), |
| 77 | + UsecPerWriteOp: prometheus.NewDesc( |
| 78 | + prometheus.BuildFQName(namespace, subsystem, "usec_per_write_op"), |
| 79 | + "Average time, measured in microseconds, that the array takes to process a write request", |
| 80 | + nil, |
| 81 | + prometheus.Labels{"host": fbClient.Host}, |
| 82 | + ), |
| 83 | + InputPerSec: prometheus.NewDesc( |
| 84 | + prometheus.BuildFQName(namespace, subsystem, "input_per_sec"), |
| 85 | + "Bytes written per second", |
| 86 | + nil, |
| 87 | + prometheus.Labels{"host": fbClient.Host}, |
| 88 | + ), |
| 89 | + WritesPerSec: prometheus.NewDesc( |
| 90 | + prometheus.BuildFQName(namespace, subsystem, "writes_per_sec"), |
| 91 | + "Write requests processed per second", |
| 92 | + nil, |
| 93 | + prometheus.Labels{"host": fbClient.Host}, |
| 94 | + ), |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +func (c ArrayPerformanceCollector) Collect(ch chan<- prometheus.Metric) { |
| 99 | + if err := c.collect(ch); err != nil { |
| 100 | + log.Error("Failed collecting array performance metrics", err) |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +func (c ArrayPerformanceCollector) collect(ch chan<- prometheus.Metric) error { |
| 105 | + stats, err := c.fbClient.ArrayPerformance() |
| 106 | + if err != nil { |
| 107 | + return err |
| 108 | + } |
| 109 | + |
| 110 | + ch <- prometheus.MustNewConstMetric( |
| 111 | + c.BytesPerOp, |
| 112 | + prometheus.GaugeValue, |
| 113 | + float64(stats.Items[0].BytesPerOp)) |
| 114 | + |
| 115 | + ch <- prometheus.MustNewConstMetric( |
| 116 | + c.BytesPerRead, |
| 117 | + prometheus.GaugeValue, |
| 118 | + float64(stats.Items[0].BytesPerRead)) |
| 119 | + |
| 120 | + ch <- prometheus.MustNewConstMetric( |
| 121 | + c.BytesPerWrite, |
| 122 | + prometheus.GaugeValue, |
| 123 | + float64(stats.Items[0].BytesPerWrite)) |
| 124 | + |
| 125 | + ch <- prometheus.MustNewConstMetric( |
| 126 | + c.OthersPerSec, |
| 127 | + prometheus.GaugeValue, |
| 128 | + float64(stats.Items[0].OthersPerSec)) |
| 129 | + |
| 130 | + ch <- prometheus.MustNewConstMetric( |
| 131 | + c.OutputPerSec, |
| 132 | + prometheus.GaugeValue, |
| 133 | + float64(stats.Items[0].OutputPerSec)) |
| 134 | + |
| 135 | + ch <- prometheus.MustNewConstMetric( |
| 136 | + c.ReadsPerSec, |
| 137 | + prometheus.GaugeValue, |
| 138 | + float64(stats.Items[0].ReadsPerSec)) |
| 139 | + |
| 140 | + ch <- prometheus.MustNewConstMetric( |
| 141 | + c.UsecPerOtherOp, |
| 142 | + prometheus.GaugeValue, |
| 143 | + float64(stats.Items[0].UsecPerOtherOp)) |
| 144 | + |
| 145 | + ch <- prometheus.MustNewConstMetric( |
| 146 | + c.UsecPerReadOp, |
| 147 | + prometheus.GaugeValue, |
| 148 | + float64(stats.Items[0].UsecPerReadOp)) |
| 149 | + |
| 150 | + ch <- prometheus.MustNewConstMetric( |
| 151 | + c.UsecPerWriteOp, |
| 152 | + prometheus.GaugeValue, |
| 153 | + float64(stats.Items[0].UsecPerWriteOp)) |
| 154 | + |
| 155 | + ch <- prometheus.MustNewConstMetric( |
| 156 | + c.InputPerSec, |
| 157 | + prometheus.GaugeValue, |
| 158 | + float64(stats.Items[0].InputPerSec)) |
| 159 | + |
| 160 | + ch <- prometheus.MustNewConstMetric( |
| 161 | + c.WritesPerSec, |
| 162 | + prometheus.GaugeValue, |
| 163 | + float64(stats.Items[0].WritesPerSec)) |
| 164 | + |
| 165 | + return nil |
| 166 | +} |
0 commit comments