@@ -2,80 +2,22 @@ package exporter
22
33import (
44 "log"
5- "regexp"
6- "strconv"
75)
86
97type ProductionCollector struct {
108 FRMAddress string
119}
1210
13- var prodPerMinRegex = regexp .MustCompile (`P: (?P<prod_current>[\d.]+)/(?P<prod_capacity>[\d.]+)/min - C: (?P<cons_current>[\d.]+)/(?P<cons_capacity>[\d.]+)/min` )
14-
1511type ProductionDetails struct {
1612 ItemName string `json:"ItemName"`
17- ProdPerMin string `json:"ProdPerMin"`
18- ProdPercent * float64 `json:"ProdPercent"`
19- ConsPercent * float64 `json:"ConsPercent"`
13+ ProdPercent float64 `json:"ProdPercent"`
14+ ConsPercent float64 `json:"ConsPercent"`
2015 CurrentProduction float64 `json:"CurrentProd"`
2116 CurrentConsumption float64 `json:"CurrentConsumed"`
2217 MaxProd float64 `json:"MaxProd"`
2318 MaxConsumed float64 `json:"MaxConsumed"`
2419}
2520
26- func (pd * ProductionDetails ) parseProdPerMin () (bool , map [string ]string ) {
27- match := prodPerMinRegex .FindStringSubmatch (pd .ProdPerMin )
28-
29- if len (match ) < 1 {
30- return false , nil
31- }
32-
33- paramsMap := make (map [string ]string )
34- for i , name := range prodPerMinRegex .SubexpNames () {
35- if i > 0 && i <= len (match ) {
36- paramsMap [name ] = match [i ]
37- }
38- }
39-
40- return true , paramsMap
41- }
42-
43- func (pd * ProductionDetails ) ItemProductionCapacity () * float64 {
44- hasMatched , params := pd .parseProdPerMin ()
45-
46- if ! hasMatched {
47- return nil
48- }
49-
50- value := params ["prod_capacity" ]
51-
52- v , err := strconv .ParseFloat (value , 64 )
53-
54- if err != nil {
55- return nil
56- }
57-
58- return & v
59- }
60-
61- func (pd * ProductionDetails ) ItemConsumptionCapacity () * float64 {
62- hasMatched , params := pd .parseProdPerMin ()
63-
64- if ! hasMatched {
65- return nil
66- }
67-
68- value := params ["cons_capacity" ]
69-
70- v , err := strconv .ParseFloat (value , 64 )
71-
72- if err != nil {
73- return nil
74- }
75-
76- return & v
77- }
78-
7921func NewProductionCollector (frmAddress string ) * ProductionCollector {
8022 return & ProductionCollector {
8123 FRMAddress : frmAddress ,
@@ -94,18 +36,9 @@ func (c *ProductionCollector) Collect() {
9436 ItemsProducedPerMin .WithLabelValues (d .ItemName ).Set (d .CurrentProduction )
9537 ItemsConsumedPerMin .WithLabelValues (d .ItemName ).Set (d .CurrentConsumption )
9638
97- ItemProductionCapacityPercent .WithLabelValues (d .ItemName ).Set (* d .ProdPercent )
98- ItemConsumptionCapacityPercent .WithLabelValues (d .ItemName ).Set (* d .ConsPercent )
99-
100- prodCapacity := d .ItemProductionCapacity ()
101- consCapacity := d .ItemConsumptionCapacity ()
102-
103- if prodCapacity != nil {
104- ItemProductionCapacityPerMinute .WithLabelValues (d .ItemName ).Set (* prodCapacity )
105- }
106-
107- if consCapacity != nil {
108- ItemConsumptionCapacityPerMinute .WithLabelValues (d .ItemName ).Set (* consCapacity )
109- }
39+ ItemProductionCapacityPercent .WithLabelValues (d .ItemName ).Set (d .ProdPercent )
40+ ItemConsumptionCapacityPercent .WithLabelValues (d .ItemName ).Set (d .ConsPercent )
41+ ItemProductionCapacityPerMinute .WithLabelValues (d .ItemName ).Set (d .MaxProd )
42+ ItemConsumptionCapacityPerMinute .WithLabelValues (d .ItemName ).Set (d .MaxConsumed )
11043 }
11144}
0 commit comments