@@ -37,16 +37,24 @@ func (c *CustomCollector) Collect(ch chan<- prometheus.Metric) {
3737 data := readAllStocks ()
3838
3939 for _ , row := range data [1 :] {
40+ var industry string
41+ var superSector string
42+
4043 price , _ := strconv .ParseFloat (row [11 ], 64 )
4144 trades , _ := strconv .ParseFloat (row [15 ], 64 )
4245 volume , _ := strconv .ParseFloat (row [16 ], 64 )
4346 turnover , _ := strconv .ParseFloat (row [17 ], 64 )
4447
48+ if len (row ) == 20 { // Some companies might be missing Industry and Supersector
49+ industry = row [18 ]
50+ superSector = row [19 ]
51+ }
52+
4553 t := time .Now ().In (loc ).Add (- 15 * time .Minute )
46- stockPrice := prometheus .NewMetricWithTimestamp (t , prometheus .MustNewConstMetric (c .stockPriceMetric , prometheus .GaugeValue , price , row [0 ], row [1 ], row [4 ], row [ 18 ], row [ 19 ] , row [5 ]))
47- stockTrades := prometheus .NewMetricWithTimestamp (t , prometheus .MustNewConstMetric (c .stockTradeMetric , prometheus .CounterValue , trades , row [0 ], row [1 ], row [4 ], row [ 18 ], row [ 19 ] , row [5 ]))
48- stockVolume := prometheus .NewMetricWithTimestamp (t , prometheus .MustNewConstMetric (c .stockVolumeMetric , prometheus .CounterValue , volume , row [0 ], row [1 ], row [4 ], row [ 18 ], row [ 19 ] , row [5 ]))
49- stockTurnover := prometheus .NewMetricWithTimestamp (t , prometheus .MustNewConstMetric (c .stockTurnoverMetric , prometheus .CounterValue , turnover , row [0 ], row [1 ], row [4 ], row [ 18 ], row [ 19 ] , row [5 ]))
54+ stockPrice := prometheus .NewMetricWithTimestamp (t , prometheus .MustNewConstMetric (c .stockPriceMetric , prometheus .GaugeValue , price , row [0 ], row [1 ], row [4 ], industry , superSector , row [5 ]))
55+ stockTrades := prometheus .NewMetricWithTimestamp (t , prometheus .MustNewConstMetric (c .stockTradeMetric , prometheus .CounterValue , trades , row [0 ], row [1 ], row [4 ], industry , superSector , row [5 ]))
56+ stockVolume := prometheus .NewMetricWithTimestamp (t , prometheus .MustNewConstMetric (c .stockVolumeMetric , prometheus .CounterValue , volume , row [0 ], row [1 ], row [4 ], industry , superSector , row [5 ]))
57+ stockTurnover := prometheus .NewMetricWithTimestamp (t , prometheus .MustNewConstMetric (c .stockTurnoverMetric , prometheus .CounterValue , turnover , row [0 ], row [1 ], row [4 ], industry , superSector , row [5 ]))
5058
5159
5260 ch <- stockPrice
0 commit comments