mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-08 05:56:37 +00:00
printer collector: Use ENUM pattern for printer status (#1500)
This commit is contained in:
@@ -158,17 +158,21 @@ func (c *collector) collectPrinterStatus(ch chan<- prometheus.Metric) error {
|
||||
continue
|
||||
}
|
||||
|
||||
printerStatus, ok := printerStatusMap[printer.PrinterStatus]
|
||||
if !ok {
|
||||
printerStatus = "Unknown"
|
||||
for printerStatus, printerStatusName := range printerStatusMap {
|
||||
isCurrentStatus := 0.0
|
||||
if printerStatus == printer.PrinterStatus {
|
||||
isCurrentStatus = 1.0
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.printerStatus,
|
||||
prometheus.GaugeValue,
|
||||
isCurrentStatus,
|
||||
printer.Name,
|
||||
printerStatusName,
|
||||
)
|
||||
}
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.printerStatus,
|
||||
prometheus.GaugeValue,
|
||||
1,
|
||||
printer.Name,
|
||||
printerStatus,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.printerJobCount,
|
||||
prometheus.CounterValue,
|
||||
|
||||
@@ -9,12 +9,13 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/go-ole/go-ole"
|
||||
"github.com/go-ole/go-ole/oleutil"
|
||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user