Update map types
This commit is contained in:
parent
056190757b
commit
7fda4c0761
|
@ -1,17 +1,18 @@
|
|||
FROM golang:1.13 as builder
|
||||
FROM golang:1.19 as builder
|
||||
|
||||
WORKDIR /build
|
||||
ADD . /build
|
||||
RUN go build -o cups_exporter main.go
|
||||
|
||||
FROM golang:1.13
|
||||
FROM golang:1.19
|
||||
|
||||
LABEL maintainer="lenny.consuegra@camptocamp.com"
|
||||
|
||||
ENV CUPS_URI "https://localhost:631"
|
||||
|
||||
COPY --from=builder /build/cups_exporter /bin/cups_exporter
|
||||
COPY --from=builder /build/cups-exporter /bin/cups-exporter
|
||||
|
||||
EXPOSE 9329
|
||||
|
||||
CMD [ "/bin/sh", "-c", "/bin/cups_exporter -cups.uri ${CUPS_URI}" ]
|
||||
|
||||
|
|
29
pkg/jobs.go
29
pkg/jobs.go
|
@ -1,24 +1,27 @@
|
|||
/*
|
||||
Copyright 2022 Dolysis Consulting Limited
|
||||
Copyright 2022 Dolysis Consulting Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
For changes see the git log
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
For changes see the git log
|
||||
*/
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
ipp "git.st8l.com/dolysis/go-ipp"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (e *Exporter) jobsMetrics(ch chan<- prometheus.Metric) error {
|
||||
|
@ -44,13 +47,13 @@ func (e *Exporter) jobsMetrics(ch chan<- prometheus.Metric) error {
|
|||
|
||||
ch <- prometheus.MustNewConstMetric(e.jobsTotal, prometheus.CounterValue, float64(len(jobs)), printer)
|
||||
|
||||
states := map[ipp.JobState]int{}
|
||||
states := map[int8]int{}
|
||||
|
||||
for _, attr := range jobs {
|
||||
|
||||
if len(attr["job-state"]) == 1 {
|
||||
|
||||
value := ipp.JobState(attr["job-state"][0].Value.(int))
|
||||
value := int8(attr["job-state"][0].Value.(int))
|
||||
|
||||
if value <= 9 && value >= 3 {
|
||||
states[value]++
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
/*
|
||||
Copyright 2022 Dolysis Consulting Limited
|
||||
Copyright 2022 Dolysis Consulting Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
For changes see the git log
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
For changes see the git log
|
||||
*/
|
||||
package pkg
|
||||
|
||||
|
@ -33,12 +35,12 @@ func (e *Exporter) printerMetrics(ch chan<- prometheus.Metric) error {
|
|||
|
||||
printer := attr["printer-name"][0].Value.(string)
|
||||
|
||||
states := make(map[ipp.PrinterState]int)
|
||||
states := make(map[int8]int)
|
||||
states[ipp.PrinterStateIdle] = 0
|
||||
states[ipp.PrinterStateProcessing] = 0
|
||||
states[ipp.PrinterStateStopped] = 0
|
||||
|
||||
states[ipp.PrinterState(attr["printer-state"][0].Value.(int))]++
|
||||
states[int8(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.PrinterStateProcessing]), printer, "processing")
|
||||
|
|
Loading…
Reference in New Issue