@@ -33,6 +33,11 @@ type bondingCollector struct {
33
33
logger * slog.Logger
34
34
}
35
35
36
+ type bondingStats struct {
37
+ name string
38
+ slaves , active , miimon int
39
+ }
40
+
36
41
func init () {
37
42
registerCollector ("bonding" , defaultEnabled , NewBondingCollector )
38
43
}
@@ -71,27 +76,16 @@ func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error {
71
76
}
72
77
return err
73
78
}
74
- for master , status := range bondingStats {
75
- ch <- c .slaves .mustNewConstMetric (float64 (status [0 ]), master )
76
- ch <- c .active .mustNewConstMetric (float64 (status [1 ]), master )
77
- }
78
-
79
- bondingMiimon , err := readBondingMiimon (statusfile )
80
- if err != nil {
81
- if errors .Is (err , os .ErrNotExist ) {
82
- c .logger .Debug ("Not collecting bonding, file does not exist" , "file" , statusfile )
83
- return ErrNoData
84
- }
85
- return err
86
- }
87
- for bond , miimon := range bondingMiimon {
88
- ch <- c .miimon .mustNewConstMetric (float64 (miimon ), bond )
79
+ for _ , bond := range bondingStats {
80
+ ch <- c .slaves .mustNewConstMetric (float64 (bond .slaves ), bond .name )
81
+ ch <- c .active .mustNewConstMetric (float64 (bond .active ), bond .name )
82
+ ch <- c .miimon .mustNewConstMetric (float64 (bond .miimon ), bond .name )
89
83
}
90
84
return nil
91
85
}
92
86
93
- func readBondingStats (root string ) (status map [ string ][ 2 ] int , err error ) {
94
- status = map [ string ][ 2 ] int {}
87
+ func readBondingStats (root string ) (status [] bondingStats , err error ) {
88
+ status = [] bondingStats {}
95
89
masters , err := os .ReadFile (filepath .Join (root , "bonding_masters" ))
96
90
if err != nil {
97
91
return nil , err
@@ -116,30 +110,22 @@ func readBondingStats(root string) (status map[string][2]int, err error) {
116
110
sstat [1 ]++
117
111
}
118
112
}
119
- status [master ] = sstat
120
- }
121
- return status , err
122
- }
123
-
124
- func readBondingMiimon (root string ) (status map [string ]int , err error ) {
125
- status = map [string ]int {}
126
- masters , err := os .ReadFile (filepath .Join (root , "bonding_masters" ))
127
- if err != nil {
128
- return nil , err
129
- }
130
113
131
- for _ , master := range strings .Fields (string (masters )) {
132
114
miimon , err := os .ReadFile (filepath .Join (root , master , "bonding" , "miimon" ))
133
115
if err != nil {
134
116
return nil , err
135
117
}
136
-
137
118
intMiimon , err := strconv .Atoi (strings .TrimSpace (string (miimon )))
138
119
if err != nil {
139
120
return nil , err
140
121
}
141
122
142
- status [master ] = intMiimon
123
+ status = append (status , bondingStats {
124
+ name : master ,
125
+ slaves : sstat [0 ],
126
+ active : sstat [1 ],
127
+ miimon : intMiimon ,
128
+ })
143
129
}
144
130
return status , err
145
131
}
0 commit comments