make a version whitout the cups_job_state_total metric
This commit is contained in:
parent
9c81fabc19
commit
68b4a2e0fd
10
README.md
10
README.md
|
@ -41,7 +41,6 @@ $ docker run --rm --network="host" ghcr.io/camptocamp/cups_exporter:0.0.8
|
|||
| Metric | Meaning | Labels |
|
||||
| ------ | ------- | ------ |
|
||||
| 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_printer_state_total | Number of printers per state | printer, state |
|
||||
| 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:
|
||||
```
|
||||
# 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
|
||||
# TYPE cups_job_total counter
|
||||
cups_job_total{printer="CUPS_Printer_1"} 3
|
||||
|
|
|
@ -53,12 +53,6 @@ func NewExporter(cupsUri string, log logr.Logger) (*Exporter, error) {
|
|||
[]string{"printer"},
|
||||
nil,
|
||||
),
|
||||
jobStateTotal: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "job", "state_total"),
|
||||
"Number of jobs per state",
|
||||
[]string{"printer", "state"},
|
||||
nil,
|
||||
),
|
||||
printersTotal: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "printer", "total"),
|
||||
"Number of available printers",
|
||||
|
@ -84,7 +78,6 @@ type Exporter struct {
|
|||
cupsUp *prometheus.Desc
|
||||
scrapeDurationSeconds *prometheus.Desc
|
||||
jobsTotal *prometheus.Desc
|
||||
jobStateTotal *prometheus.Desc
|
||||
printersTotal *prometheus.Desc
|
||||
printerStateTotal *prometheus.Desc
|
||||
}
|
||||
|
@ -93,7 +86,6 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
|
|||
ch <- e.cupsUp
|
||||
ch <- e.scrapeDurationSeconds
|
||||
ch <- e.jobsTotal
|
||||
ch <- e.jobStateTotal
|
||||
ch <- e.printersTotal
|
||||
ch <- e.printerStateTotal
|
||||
}
|
||||
|
|
28
pkg/jobs.go
28
pkg/jobs.go
|
@ -3,7 +3,6 @@ package pkg
|
|||
import (
|
||||
"github.com/phin1x/go-ipp"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (e *Exporter) jobsMetrics(ch chan<- prometheus.Metric) error {
|
||||
|
@ -26,33 +25,6 @@ func (e *Exporter) jobsMetrics(ch chan<- prometheus.Metric) error {
|
|||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(e.jobsTotal, prometheus.CounterValue, float64(len(jobs)), printer)
|
||||
|
||||
states := map[int8]int{}
|
||||
|
||||
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.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
|
||||
|
|
Loading…
Reference in New Issue