2023-04-30 21:22:42 +00:00
|
|
|
package internal
|
2019-12-26 20:52:54 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/phin1x/go-ipp"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (e *Exporter) printerMetrics(ch chan<- prometheus.Metric) error {
|
|
|
|
printers, err := e.client.GetPrinters([]string{"printer-state"})
|
|
|
|
if err != nil {
|
|
|
|
e.log.Error(err, "failed to fetch completed jobs")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-09-03 07:19:56 +00:00
|
|
|
states := map[int]int{
|
|
|
|
int(ipp.PrinterStateIdle): 0,
|
|
|
|
int(ipp.PrinterStateProcessing): 0,
|
|
|
|
int(ipp.PrinterStateStopped): 0,
|
2023-04-30 21:22:42 +00:00
|
|
|
}
|
2019-12-26 20:52:54 +00:00
|
|
|
|
|
|
|
for _, attr := range printers {
|
2023-09-03 07:19:56 +00:00
|
|
|
states[attr["printer-state"][0].Value.(int)]++
|
2019-12-26 20:52:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(e.printersTotal, prometheus.GaugeValue, float64(len(printers)))
|
2023-09-03 07:19:56 +00:00
|
|
|
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[int(ipp.PrinterStateIdle)]), "idle")
|
|
|
|
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[int(ipp.PrinterStateProcessing)]), "processing")
|
|
|
|
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[int(ipp.PrinterStateStopped)]), "stopped")
|
2019-12-26 20:52:54 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|