Compare commits

...

3 Commits

Author SHA1 Message Date
lconsuegra e6c278ad8f use orig version of go ipp lib 2021-01-15 13:20:54 +01:00
lconsuegra 4b61efaff6 do not request jobs states anymore 2021-01-15 12:03:40 +01:00
lconsuegra 68b4a2e0fd make a version whitout the cups_job_state_total metric 2021-01-15 11:13:35 +01:00
6 changed files with 16 additions and 57 deletions

View File

@ -41,7 +41,6 @@ $ docker run --rm --network="host" ghcr.io/camptocamp/cups_exporter:0.0.8
| Metric | Meaning | Labels | | Metric | Meaning | Labels |
| ------ | ------- | ------ | | ------ | ------- | ------ |
| cups_up | Was the last scrape of cups successful | | | cups_up | Was the last scrape of cups successful | |
| cups_job_state_total | Number of current print jobs per state | printer, state |
| cups_job_total | Total number of print jobs per printer | printer | | cups_job_total | Total number of print jobs per printer | printer |
| cups_printer_state_total | Number of printers per state | printer, state | | cups_printer_state_total | Number of printers per state | printer, state |
| cups_printer_total | Total number of available printers | | | cups_printer_total | Total number of available printers | |
@ -50,15 +49,6 @@ $ docker run --rm --network="host" ghcr.io/camptocamp/cups_exporter:0.0.8
Examples: Examples:
``` ```
# HELP cups_job_state_total Number of jobs per state
# TYPE cups_job_state_total gauge
cups_job_state_total{printer="CUPS_Printer_1",state="aborted"} 0
cups_job_state_total{printer="CUPS_Printer_1",state="canceled"} 0
cups_job_state_total{printer="CUPS_Printer_1",state="completed"} 2
cups_job_state_total{printer="CUPS_Printer_1",state="held"} 0
cups_job_state_total{printer="CUPS_Printer_1",state="pending"} 0
cups_job_state_total{printer="CUPS_Printer_1",state="processing"} 1
cups_job_state_total{printer="CUPS_Printer_1",state="stopped"} 0
# HELP cups_job_total Total number of print jobs # HELP cups_job_total Total number of print jobs
# TYPE cups_job_total counter # TYPE cups_job_total counter
cups_job_total{printer="CUPS_Printer_1"} 3 cups_job_total{printer="CUPS_Printer_1"} 3

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.13
require ( require (
github.com/go-logr/logr v0.3.0 github.com/go-logr/logr v0.3.0
github.com/go-logr/zapr v0.3.0 github.com/go-logr/zapr v0.3.0
github.com/phin1x/go-ipp v1.5.0 github.com/phin1x/go-ipp v1.2.1-0.20191226192803-6c9dee854ace
github.com/prometheus/client_golang v1.9.0 github.com/prometheus/client_golang v1.9.0
go.uber.org/multierr v1.6.0 // indirect go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.16.0 go.uber.org/zap v1.16.0

4
go.sum
View File

@ -204,8 +204,8 @@ github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIw
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/phin1x/go-ipp v1.5.0 h1:3WLi0RLI3LbF93lHK7TBsK7h53u8tNXZNEokfFOurno= github.com/phin1x/go-ipp v1.2.1-0.20191226192803-6c9dee854ace h1:ELNodn+xPzMsqbwObNVFRt/OYlcCEw51IlRYdCtURcM=
github.com/phin1x/go-ipp v1.5.0/go.mod h1:GZwyNds6grdLi2xRBX22Cvt7Dh7ITWsML0bjrqBF5uo= github.com/phin1x/go-ipp v1.2.1-0.20191226192803-6c9dee854ace/go.mod h1:GZwyNds6grdLi2xRBX22Cvt7Dh7ITWsML0bjrqBF5uo=
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

View File

@ -53,12 +53,6 @@ func NewExporter(cupsUri string, log logr.Logger) (*Exporter, error) {
[]string{"printer"}, []string{"printer"},
nil, nil,
), ),
jobStateTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "job", "state_total"),
"Number of jobs per state",
[]string{"printer", "state"},
nil,
),
printersTotal: prometheus.NewDesc( printersTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "printer", "total"), prometheus.BuildFQName(namespace, "printer", "total"),
"Number of available printers", "Number of available printers",
@ -84,7 +78,6 @@ type Exporter struct {
cupsUp *prometheus.Desc cupsUp *prometheus.Desc
scrapeDurationSeconds *prometheus.Desc scrapeDurationSeconds *prometheus.Desc
jobsTotal *prometheus.Desc jobsTotal *prometheus.Desc
jobStateTotal *prometheus.Desc
printersTotal *prometheus.Desc printersTotal *prometheus.Desc
printerStateTotal *prometheus.Desc printerStateTotal *prometheus.Desc
} }
@ -93,7 +86,6 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
ch <- e.cupsUp ch <- e.cupsUp
ch <- e.scrapeDurationSeconds ch <- e.scrapeDurationSeconds
ch <- e.jobsTotal ch <- e.jobsTotal
ch <- e.jobStateTotal
ch <- e.printersTotal ch <- e.printersTotal
ch <- e.printerStateTotal ch <- e.printerStateTotal
} }

View File

@ -3,12 +3,11 @@ package pkg
import ( import (
"github.com/phin1x/go-ipp" "github.com/phin1x/go-ipp"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"strconv"
) )
func (e *Exporter) jobsMetrics(ch chan<- prometheus.Metric) error { func (e *Exporter) jobsMetrics(ch chan<- prometheus.Metric) error {
printers, err := e.client.GetPrinters([]string{"printer-state"}) printers, err := e.client.GetPrinters([]string{})
if err != nil { if err != nil {
e.log.Error(err, "failed to fetch printers") e.log.Error(err, "failed to fetch printers")
@ -17,42 +16,20 @@ func (e *Exporter) jobsMetrics(ch chan<- prometheus.Metric) error {
for _, attr := range printers { for _, attr := range printers {
printer := attr["printer-name"][0].Value.(string) if len(attr["printer-name"]) == 1 {
jobs, err := e.client.GetJobs(printer, "", ipp.JobStateFilterAll, false, 0, 0, []string{"job-state"}) printer := attr["printer-name"][0].Value.(string)
if err != nil {
e.log.Error(err, "failed to fetch all jobs states")
return err
}
ch <- prometheus.MustNewConstMetric(e.jobsTotal, prometheus.CounterValue, float64(len(jobs)), printer) jobs, err := e.client.GetJobs(printer, "", ipp.JobStateFilterAll, false, 0, 0, []string{})
if err != nil {
states := map[int8]int{} e.log.Error(err, "failed to fetch all jobs")
return err
for _, attr := range jobs {
if len(attr["job-state"]) == 1 {
value := int8(attr["job-state"][0].Value.(int))
if value <= 9 && value >= 3 {
states[value]++
} else {
e.log.Info("Unknow job state : " + strconv.Itoa(int(value)))
}
} else {
e.log.Info("job state attribute missing")
} }
ch <- prometheus.MustNewConstMetric(e.jobsTotal, prometheus.CounterValue, float64(len(jobs)), printer)
} else {
e.log.Info("printer name attribute missing")
} }
ch <- prometheus.MustNewConstMetric(e.jobStateTotal, prometheus.GaugeValue, float64(states[ipp.JobStatePending]), printer, "pending")
ch <- prometheus.MustNewConstMetric(e.jobStateTotal, prometheus.GaugeValue, float64(states[ipp.JobStateHeld]), printer, "held")
ch <- prometheus.MustNewConstMetric(e.jobStateTotal, prometheus.GaugeValue, float64(states[ipp.JobStateProcessing]), printer, "processing")
ch <- prometheus.MustNewConstMetric(e.jobStateTotal, prometheus.GaugeValue, float64(states[ipp.JobStateStopped]), printer, "stopped")
ch <- prometheus.MustNewConstMetric(e.jobStateTotal, prometheus.GaugeValue, float64(states[ipp.JobStateCanceled]), printer, "canceled")
ch <- prometheus.MustNewConstMetric(e.jobStateTotal, prometheus.GaugeValue, float64(states[ipp.JobStateAborted]), printer, "aborted")
ch <- prometheus.MustNewConstMetric(e.jobStateTotal, prometheus.GaugeValue, float64(states[ipp.JobStateCompleted]), printer, "completed")
} }
return nil return nil

View File

@ -18,12 +18,12 @@ func (e *Exporter) printerMetrics(ch chan<- prometheus.Metric) error {
printer := attr["printer-name"][0].Value.(string) printer := attr["printer-name"][0].Value.(string)
states := make(map[int8]int) states := make(map[ipp.PrinterState]int)
states[ipp.PrinterStateIdle] = 0 states[ipp.PrinterStateIdle] = 0
states[ipp.PrinterStateProcessing] = 0 states[ipp.PrinterStateProcessing] = 0
states[ipp.PrinterStateStopped] = 0 states[ipp.PrinterStateStopped] = 0
states[int8(attr["printer-state"][0].Value.(int))]++ states[ipp.PrinterState(attr["printer-state"][0].Value.(int))]++
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateIdle]), printer, "idle") ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateIdle]), printer, "idle")
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateProcessing]), printer, "processing") ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateProcessing]), printer, "processing")