Refactor printerMetrics function to use int instead of int8 for printer states
- Replace int8 with int in the states map - Cast the printer state values to int when updating the states map - Update the metrics values to use int(ipp.PrinterState<state>) with the corresponding state names as labels
This commit is contained in:
parent
d501d5a79b
commit
a96c9d88b7
1 changed files with 8 additions and 8 deletions
|
@ -12,20 +12,20 @@ func (e *Exporter) printerMetrics(ch chan<- prometheus.Metric) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
states := map[int8]int{
|
states := map[int]int{
|
||||||
ipp.PrinterStateIdle: 0,
|
int(ipp.PrinterStateIdle): 0,
|
||||||
ipp.PrinterStateProcessing: 0,
|
int(ipp.PrinterStateProcessing): 0,
|
||||||
ipp.PrinterStateStopped: 0,
|
int(ipp.PrinterStateStopped): 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, attr := range printers {
|
for _, attr := range printers {
|
||||||
states[attr["printer-state"][0].Value.(int8)]++
|
states[attr["printer-state"][0].Value.(int)]++
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(e.printersTotal, prometheus.GaugeValue, float64(len(printers)))
|
ch <- prometheus.MustNewConstMetric(e.printersTotal, prometheus.GaugeValue, float64(len(printers)))
|
||||||
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateIdle]), "idle")
|
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[int(ipp.PrinterStateIdle)]), "idle")
|
||||||
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateProcessing]), "processing")
|
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[int(ipp.PrinterStateProcessing)]), "processing")
|
||||||
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateStopped]), "stopped")
|
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[int(ipp.PrinterStateStopped)]), "stopped")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue