@@ -119,14 +119,30 @@ func (w *expWriter) write() error {
119119
120120 defer mboxOpen .Close ()
121121
122- /*
123- * NB: As a convention, write headers before retrieving values so the output will indicate where
124- * something went wrong.
125- */
126-
127- /*
128- * Hardware.
129- */
122+ if err := w .writeHardware (mboxOpen ); err != nil {
123+ return err
124+ }
125+
126+ if err := w .writePower (mboxOpen ); err != nil {
127+ return err
128+ }
129+
130+ if err := w .writeClocks (mboxOpen ); err != nil {
131+ return err
132+ }
133+
134+ if err := w .writeTemperatures (mboxOpen ); err != nil {
135+ return err
136+ }
137+
138+ if err := w .writeVoltages (mboxOpen ); err != nil {
139+ return err
140+ }
141+
142+ return nil
143+ }
144+
145+ func (w * expWriter ) writeHardware (mboxOpen * mbox.Mailbox ) error {
130146 w .writeHeaderGauge ("rpi_vc_revision" , "Firmware revision of the VideoCore device." , metricTypeGauge )
131147
132148 rev , err := mboxOpen .GetFirmwareRevision ()
@@ -154,48 +170,45 @@ func (w *expWriter) write() error {
154170
155171 w .writeSample (rev )
156172
157- /*
158- * Power.
159- */
160- w .writeHeaderGauge (
161- "rpi_power_state" ,
162- "Component power state (0: off, 1: on, 2: missing)." ,
163- metricTypeGauge ,
164- "id" ,
165- )
173+ return nil
174+ }
175+
176+ func (w * expWriter ) writePower (mboxOpen * mbox.Mailbox ) error {
177+ w .writeHeaderGauge ("rpi_power_state" , "Component power state (0: off, 1: on, 2: missing)." , metricTypeGauge , "id" )
166178
167179 for id , label := range powerLabelsByID {
168- powerState , err := mboxOpen .GetPowerState (id )
180+ state , err := mboxOpen .GetPowerState (id )
169181 if err != nil {
170182 return fmt .Errorf ("unable to get power state: %w" , err )
171183 }
172184
173- w .writeSample (powerState , label )
185+ w .writeSample (state , label )
174186 }
175187
176- /*
177- * Clocks.
178- */
188+ return nil
189+ }
190+
191+ func (w * expWriter ) writeClocks (mboxOpen * mbox.Mailbox ) error {
179192 w .writeHeaderGauge ("rpi_clock_rate_hz" , "Clock rate in Hertz." , metricTypeGauge , "id" )
180193
181194 for id , label := range clockLabelsByID {
182- clockRate , err := mboxOpen .GetClockRate (id )
195+ rate , err := mboxOpen .GetClockRate (id )
183196 if err != nil {
184197 return fmt .Errorf ("unable to get clock rate: %w" , err )
185198 }
186199
187- w .writeSample (clockRate , label )
200+ w .writeSample (rate , label )
188201 }
189202
190203 w .writeHeaderGauge ("rpi_clock_rate_measured_hz" , "Measured clock rate in Hertz." , metricTypeGauge , "id" )
191204
192205 for id , label := range clockLabelsByID {
193- clockRate , err := mboxOpen .GetClockRateMeasured (id )
206+ rate , err := mboxOpen .GetClockRateMeasured (id )
194207 if err != nil {
195208 return fmt .Errorf ("unable to get measured clock rate: %w" , err )
196209 }
197210
198- w .writeSample (clockRate , label )
211+ w .writeSample (rate , label )
199212 }
200213
201214 w .writeHeaderGauge ("rpi_turbo" , "Turbo state." , metricTypeGauge )
@@ -207,59 +220,38 @@ func (w *expWriter) write() error {
207220
208221 w .writeSample (formatBool (turbo ))
209222
210- /*
211- * Temperature sensors.
212- */
223+ return nil
224+ }
213225
214- // Current SoC temperature
215- w .writeHeaderGauge (
216- "rpi_temperature_c" ,
217- "Temperature of the SoC in degrees celsius." ,
218- metricTypeGauge ,
219- "id" ,
220- )
226+ func (w * expWriter ) writeTemperatures (mboxOpen * mbox.Mailbox ) error {
227+ w .writeHeaderGauge ("rpi_temperature_c" , "Temperature of the SoC in degrees celsius." , metricTypeGauge , "id" )
221228
222229 temp , err := mboxOpen .GetTemperature ()
223230 if err != nil {
224231 return fmt .Errorf ("unable to get temperature: %w" , err )
225232 }
226233
227234 w .writeSample (formatTemp (temp ), "soc" )
228- w .writeHeaderGauge (
229- "rpi_temperature_f" ,
230- "Temperature of the SoC in degrees fahrenheit." ,
231- metricTypeGauge ,
232- "id" ,
233- )
235+
236+ w .writeHeaderGauge ("rpi_temperature_f" , "Temperature of the SoC in degrees fahrenheit." , metricTypeGauge , "id" )
234237 w .writeSample (formatTemp (temp * 9 / 5 + 32 ), "soc" )
235238
236- // Max SoC temperature
237- w .writeHeaderGauge (
238- "rpi_max_temperature_c" ,
239- "Maximum temperature of the SoC in degrees celsius." ,
240- metricTypeGauge ,
241- "id" ,
242- )
239+ w .writeHeaderGauge ("rpi_max_temperature_c" , "Maximum temperature of the SoC in degrees celsius." , metricTypeGauge , "id" )
243240
244241 maxTemp , err := mboxOpen .GetMaxTemperature ()
245242 if err != nil {
246243 return fmt .Errorf ("unable to get maximum temperature: %w" , err )
247244 }
248245
249246 w .writeSample (formatTemp (maxTemp ), "soc" )
250- w .writeHeaderGauge (
251- "rpi_max_temperature_f" ,
252- "Maximum temperature of the SoC in degrees fahrenheit." ,
253- metricTypeGauge ,
254- "id" ,
255- )
247+
248+ w .writeHeaderGauge ("rpi_max_temperature_f" , "Maximum temperature of the SoC in degrees fahrenheit." , metricTypeGauge , "id" )
256249 w .writeSample (formatTemp (maxTemp * 9 / 5 + 32 ), "soc" )
257250
258- /*
259- * Voltages
260- */
251+ return nil
252+ }
261253
262- // Current voltages.
254+ func ( w * expWriter ) writeVoltages ( mboxOpen * mbox. Mailbox ) error {
263255 w .writeHeaderGauge ("rpi_voltage" , "Current component voltage." , metricTypeGauge , "id" )
264256
265257 for id , label := range voltageLabelsByID {
0 commit comments