switch to go-kit logger

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2023-04-22 12:17:51 +02:00
parent e0e31254e2
commit 8509bc69a6
70 changed files with 1052 additions and 993 deletions

View File

@@ -6,16 +6,21 @@ package collector
import (
"strings"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)
type cpuCollectorBasic struct {
logger log.Logger
CStateSecondsTotal *prometheus.Desc
TimeTotal *prometheus.Desc
InterruptsTotal *prometheus.Desc
DPCsTotal *prometheus.Desc
}
type cpuCollectorFull struct {
logger log.Logger
CStateSecondsTotal *prometheus.Desc
TimeTotal *prometheus.Desc
InterruptsTotal *prometheus.Desc
@@ -33,10 +38,11 @@ type cpuCollectorFull struct {
}
// newCPUCollector constructs a new cpuCollector, appropriate for the running OS
func newCPUCollector() (Collector, error) {
func newCPUCollector(logger log.Logger) (Collector, error) {
const subsystem = "cpu"
logger = log.With(logger, "collector", subsystem)
version := getWindowsVersion()
version := getWindowsVersion(logger)
// For Windows 2008 (version 6.0) or earlier we only have the "Processor"
// class. As of Windows 2008 R2 (version 6.1) the more detailed
// "Processor Information" set is available (although some of the counters
@@ -45,6 +51,7 @@ func newCPUCollector() (Collector, error) {
// Value 6.05 was selected to split between Windows versions.
if version < 6.05 {
return &cpuCollectorBasic{
logger: logger,
CStateSecondsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "cstate_seconds_total"),
"Time spent in low-power idle state",
@@ -73,6 +80,7 @@ func newCPUCollector() (Collector, error) {
}
return &cpuCollectorFull{
logger: logger,
CStateSecondsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "cstate_seconds_total"),
"Time spent in low-power idle state",
@@ -175,7 +183,7 @@ type perflibProcessor struct {
func (c *cpuCollectorBasic) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) error {
data := make([]perflibProcessor, 0)
err := unmarshalObject(ctx.perfObjects["Processor"], &data)
err := unmarshalObject(ctx.perfObjects["Processor"], &data, c.logger)
if err != nil {
return err
}
@@ -284,7 +292,7 @@ type perflibProcessorInformation struct {
func (c *cpuCollectorFull) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) error {
data := make([]perflibProcessorInformation, 0)
err := unmarshalObject(ctx.perfObjects["Processor Information"], &data)
err := unmarshalObject(ctx.perfObjects["Processor Information"], &data, c.logger)
if err != nil {
return err
}