exporter: Rename up metric to cups_up and add printer label for state metrics
This commit is contained in:
parent
f1e5de93a3
commit
5b3260d47c
|
@ -35,8 +35,8 @@ func NewExporter(cupsUri string, log logr.Logger) (*Exporter, error) {
|
|||
lastJobId: 0,
|
||||
lastCompletedJobId: 0,
|
||||
|
||||
up: prometheus.NewDesc(
|
||||
"up",
|
||||
cupsUp: prometheus.NewDesc(
|
||||
"cups_up",
|
||||
"Was the last scrape of cups successful",
|
||||
nil,
|
||||
nil,
|
||||
|
@ -47,16 +47,16 @@ func NewExporter(cupsUri string, log logr.Logger) (*Exporter, error) {
|
|||
nil,
|
||||
nil,
|
||||
),
|
||||
jobsActiveTotal: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "job", "active_total"),
|
||||
"Number of current print jobs",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
jobsTotal: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "job", "total"),
|
||||
"Total number of print jobs",
|
||||
[]string{"printer"},
|
||||
nil,
|
||||
),
|
||||
jobStateTotal: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "job", "state_total"),
|
||||
"Number of jobs per state",
|
||||
[]string{"printer", "state"},
|
||||
nil,
|
||||
),
|
||||
printersTotal: prometheus.NewDesc(
|
||||
|
@ -68,7 +68,7 @@ func NewExporter(cupsUri string, log logr.Logger) (*Exporter, error) {
|
|||
printerStateTotal: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "printer", "state_total"),
|
||||
"Number of printers per state",
|
||||
[]string{"state"},
|
||||
[]string{"printer", "state"},
|
||||
nil,
|
||||
),
|
||||
}, nil
|
||||
|
@ -81,39 +81,39 @@ type Exporter struct {
|
|||
lastJobId int
|
||||
lastCompletedJobId int
|
||||
|
||||
up *prometheus.Desc
|
||||
cupsUp *prometheus.Desc
|
||||
scrapeDurationSeconds *prometheus.Desc
|
||||
jobsActiveTotal *prometheus.Desc
|
||||
jobsTotal *prometheus.Desc
|
||||
jobStateTotal *prometheus.Desc
|
||||
printersTotal *prometheus.Desc
|
||||
printerStateTotal *prometheus.Desc
|
||||
}
|
||||
|
||||
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- e.up
|
||||
ch <- e.cupsUp
|
||||
ch <- e.scrapeDurationSeconds
|
||||
ch <- e.jobsTotal
|
||||
ch <- e.jobsActiveTotal
|
||||
ch <- e.jobStateTotal
|
||||
ch <- e.printersTotal
|
||||
ch <- e.printerStateTotal
|
||||
}
|
||||
|
||||
func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
|
||||
up := float64(1)
|
||||
cupsUp := float64(1)
|
||||
scrapeStartTime := time.Now()
|
||||
|
||||
if err := e.jobsMetrics(ch); err != nil {
|
||||
e.log.Error(err, "failed to get job metrics")
|
||||
up = 0
|
||||
cupsUp = 0
|
||||
}
|
||||
|
||||
if err := e.printerMetrics(ch); err != nil {
|
||||
e.log.Error(err, "failed to get printer metrics")
|
||||
up = 0
|
||||
cupsUp = 0
|
||||
}
|
||||
|
||||
scrapeDuration := time.Now().Sub(scrapeStartTime)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(e.scrapeDurationSeconds, prometheus.GaugeValue, scrapeDuration.Seconds())
|
||||
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, up)
|
||||
ch <- prometheus.MustNewConstMetric(e.cupsUp, prometheus.GaugeValue, cupsUp)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue