Skip to content

Commit f255b0e

Browse files
committed
Bug fixes and QoL changes
1 parent 9f05410 commit f255b0e

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

metrics.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

sample_metrics.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
stock_price{industry="Industrials", instance="xx.xxx.x.xxx:33171", job="stocks", marketplace="TLN", name="Airobot Technologies", segment="First North Baltic Share List", supersector="Construction and Materials", ticker="AIR"} 2.97
2-
stock_trades{industry="Industrials", instance="xx.xxx.x.xxx:33171", job="stocks", marketplace="TLN", name="Airobot Technologies", segment="First North Baltic Share List", supersector="Construction and Materials", ticker="AIR"} 3
3-
stock_volume{industry="Industrials", instance="xx.xxx.x.xxx:33171", job="stocks", marketplace="TLN", name="Airobot Technologies", segment="First North Baltic Share List", supersector="Construction and Materials", ticker="AIR"} 102
4-
stock_turnover{industry="Industrials", instance="xx.xxx.x.xxx:33171", job="stocks", marketplace="TLN", name="Airobot Technologies", segment="First North Baltic Share List", supersector="Construction and Materials", ticker="AIR"} 303
1+
stock_price{industry="Industrials", marketplace="TLN", name="Airobot Technologies", segment="First North Baltic Share List", supersector="Construction and Materials", ticker="AIR"} 2.97
2+
stock_trades{industry="Industrials", marketplace="TLN", name="Airobot Technologies", segment="First North Baltic Share List", supersector="Construction and Materials", ticker="AIR"} 3
3+
stock_volume{industry="Industrials", marketplace="TLN", name="Airobot Technologies", segment="First North Baltic Share List", supersector="Construction and Materials", ticker="AIR"} 102
4+
stock_turnover{industry="Industrials", marketplace="TLN", name="Airobot Technologies", segment="First North Baltic Share List", supersector="Construction and Materials", ticker="AIR"} 303

0 commit comments

Comments
 (0)