master
go 140 lines 2.99 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package hpssa
4
5 import (
6 "fmt"
7 "strconv"
8 "strings"
9 )
10
11 func (c *Collector) collect() (map[string]int64, error) {
12 data, err := c.exec.controllersInfo()
13 if err != nil {
14 return nil, err
15 }
16
17 controllers, err := parseSsacliControllersInfo(data)
18 if err != nil {
19 return nil, err
20 }
21
22 mx := make(map[string]int64)
23
24 c.collectControllers(mx, controllers)
25
26 c.updateCharts(controllers)
27
28 return mx, nil
29 }
30
31 func (c *Collector) collectControllers(mx map[string]int64, controllers map[string]*hpssaController) {
32 for _, cntrl := range controllers {
33 c.collectController(mx, cntrl)
34
35 for _, pd := range cntrl.unassignedDrives {
36 c.collectPhysicalDrive(mx, pd)
37 }
38
39 for _, arr := range cntrl.arrays {
40 c.collectArray(mx, arr)
41
42 for _, ld := range arr.logicalDrives {
43 c.collectLogicalDrive(mx, ld)
44
45 for _, pd := range ld.physicalDrives {
46 c.collectPhysicalDrive(mx, pd)
47 }
48 }
49 }
50 }
51 }
52
53 func (c *Collector) collectController(mx map[string]int64, cntrl *hpssaController) {
54 px := fmt.Sprintf("cntrl_%s_slot_%s_", cntrl.model, cntrl.slot)
55
56 writeStatusOkNok(mx, px, cntrl.controllerStatus)
57
58 if v, ok := parseNumber(cntrl.controllerTemperatureC); ok {
59 mx[px+"temperature"] = v
60 }
61
62 mx[px+"cache_presence_status_present"] = 0
63 mx[px+"cache_presence_status_not_present"] = 0
64 if cntrl.cacheBoardPresent != "True" {
65 mx[px+"cache_presence_status_not_present"] = 1
66 return
67 }
68
69 mx[px+"cache_presence_status_present"] = 1
70
71 writeStatusOkNok(mx, px+"cache_", cntrl.cacheStatus)
72
73 if v, ok := parseNumber(cntrl.cacheModuleTemperatureC); ok {
74 mx[px+"cache_temperature"] = v
75 }
76
77 writeStatusOkNok(mx, px+"cache_battery_", cntrl.batteryCapacitorStatus)
78 }
79
80 func (c *Collector) collectArray(mx map[string]int64, arr *hpssaArray) {
81 if arr.cntrl == nil {
82 return
83 }
84
85 px := fmt.Sprintf("array_%s_cntrl_%s_slot_%s_",
86 arr.id, arr.cntrl.model, arr.cntrl.slot)
87
88 writeStatusOkNok(mx, px, arr.status)
89 }
90
91 func (c *Collector) collectLogicalDrive(mx map[string]int64, ld *hpssaLogicalDrive) {
92 if ld.cntrl == nil || ld.arr == nil {
93 return
94 }
95
96 px := fmt.Sprintf("ld_%s_array_%s_cntrl_%s_slot_%s_",
97 ld.id, ld.arr.id, ld.cntrl.model, ld.cntrl.slot)
98
99 writeStatusOkNok(mx, px, ld.status)
100 }
101
102 func (c *Collector) collectPhysicalDrive(mx map[string]int64, pd *hpssaPhysicalDrive) {
103 if pd.cntrl == nil {
104 return
105 }
106
107 px := fmt.Sprintf("pd_%s_ld_%s_array_%s_cntrl_%s_slot_%s_",
108 pd.location, pd.ldId(), pd.arrId(), pd.cntrl.model, pd.cntrl.slot)
109
110 writeStatusOkNok(mx, px, pd.status)
111
112 if v, ok := parseNumber(pd.currentTemperatureC); ok {
113 mx[px+"temperature"] = v
114 }
115 }
116
117 func parseNumber(s string) (int64, bool) {
118 v, err := strconv.ParseFloat(s, 64)
119 if err != nil {
120 return 0, false
121 }
122 return int64(v), true
123 }
124
125 func writeStatusOkNok(mx map[string]int64, prefix, status string) {
126 if !strings.HasSuffix(prefix, "_") {
127 prefix += "_"
128 }
129
130 mx[prefix+"status_ok"] = 0
131 mx[prefix+"status_nok"] = 0
132
133 switch status {
134 case "":
135 case "OK":
136 mx[prefix+"status_ok"] = 1
137 default:
138 mx[prefix+"status_nok"] = 1
139 }
140 }