@@ -33,6 +33,11 @@ type bondingCollector struct {
3333 logger * slog.Logger
3434}
3535
36+ type bondingStats struct {
37+ name string
38+ slaves , active , miimon int
39+ }
40+
3641func init () {
3742 registerCollector ("bonding" , defaultEnabled , NewBondingCollector )
3843}
@@ -71,27 +76,16 @@ func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error {
7176 }
7277 return err
7378 }
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 )
8983 }
9084 return nil
9185}
9286
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 {}
9589 masters , err := os .ReadFile (filepath .Join (root , "bonding_masters" ))
9690 if err != nil {
9791 return nil , err
@@ -116,30 +110,22 @@ func readBondingStats(root string) (status map[string][2]int, err error) {
116110 sstat [1 ]++
117111 }
118112 }
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- }
130113
131- for _ , master := range strings .Fields (string (masters )) {
132114 miimon , err := os .ReadFile (filepath .Join (root , master , "bonding" , "miimon" ))
133115 if err != nil {
134116 return nil , err
135117 }
136-
137118 intMiimon , err := strconv .Atoi (strings .TrimSpace (string (miimon )))
138119 if err != nil {
139120 return nil , err
140121 }
141122
142- status [master ] = intMiimon
123+ status = append (status , bondingStats {
124+ name : master ,
125+ slaves : sstat [0 ],
126+ active : sstat [1 ],
127+ miimon : intMiimon ,
128+ })
143129 }
144130 return status , err
145131}
0 commit comments