From bd6d72053eebebfcf15ab1ccf4d57f6e09cca356 Mon Sep 17 00:00:00 2001 From: Mitya_Eremeev Date: Thu, 5 Dec 2024 21:37:08 +0300 Subject: [PATCH] Add TLS and basic authentication in web interface 1) TLS and basic authentication are in flag `--web.config.file`: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md#web-configuration 2) All command-line arguments are with two dashes now. Example: ./ovs-exporter --web.listen-address 10.224.141.48:9134 --database.vswitch.file.pid.path /run/openvswitch/ovsdb-server.pid --database.vswitch.socket.remote unix:/run/openvswitch/db.sock --service.vswitchd.file.pid.path /run/openvswitch/ovs-vswitchd.pid --system.run.dir /run/openvswitch --database.vswitch.file.log.path /var/log/kolla/openvswitch/ovsdb-server.log --service.vswitchd.file.log.path /var/log/kolla/openvswitch/ovs-vswitchd.log --log.level=debug --web.config.file web_config.yml Prometheus Exporter Toolkit provides TLS and basic authentication in exporters. The Toolkit requires newer command-line and log packages. So packages "flag" and "go-kit/log" were replaced. https://github.com/greenpau/ovs_exporter/issues --- README.md | 8 + cmd/ovs_exporter/main.go | 142 ++++++-------- go.mod | 39 ++-- go.sum | 102 +++++++--- pkg/ovs_exporter/ovs_exporter.go | 323 +++++++------------------------ 5 files changed, 235 insertions(+), 379 deletions(-) diff --git a/README.md b/README.md index f91c2d5..46a89b1 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,14 @@ make make qtest ``` +## TLS and basic authentication + +The OVS Exporter supports TLS and basic authentication. + +To use TLS and/or basic authentication, you need to pass a configuration file +using the `--web.config.file` parameter. The format of the file is described +[in the exporter-toolkit repository](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md). + ## Exported Metrics | Metric | Meaning | Labels | diff --git a/cmd/ovs_exporter/main.go b/cmd/ovs_exporter/main.go index 8341f3d..c6546e5 100644 --- a/cmd/ovs_exporter/main.go +++ b/cmd/ovs_exporter/main.go @@ -1,68 +1,41 @@ package main import ( - "flag" "fmt" + "log/slog" "net/http" "os" - "github.com/go-kit/log/level" + "github.com/alecthomas/kingpin/v2" + "github.com/greenpau/ovs_exporter/pkg/ovs_exporter" ovs "github.com/greenpau/ovs_exporter/pkg/ovs_exporter" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/prometheus/exporter-toolkit/web" + webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag" ) func main() { - var listenAddress string - var metricsPath string - var pollTimeout int - var pollInterval int - var isShowVersion bool - var logLevel string - var systemRunDir string - var databaseVswitchName string - var databaseVswitchSocketRemote string - var databaseVswitchFileDataPath string - var databaseVswitchFileLogPath string - var databaseVswitchFilePidPath string - var databaseVswitchFileSystemIDPath string - var serviceVswitchdFileLogPath string - var serviceVswitchdFilePidPath string - var serviceOvnControllerFileLogPath string - var serviceOvnControllerFilePidPath string - - flag.StringVar(&listenAddress, "web.listen-address", ":9475", "Address to listen on for web interface and telemetry.") - flag.StringVar(&metricsPath, "web.telemetry-path", "/metrics", "Path under which to expose metrics.") - flag.IntVar(&pollTimeout, "ovs.timeout", 2, "Timeout on JSON-RPC requests to OVS.") - flag.IntVar(&pollInterval, "ovs.poll-interval", 15, "The minimum interval (in seconds) between collections from OVS server.") - flag.BoolVar(&isShowVersion, "version", false, "version information") - flag.StringVar(&logLevel, "log.level", "info", "logging severity level") - - flag.StringVar(&systemRunDir, "system.run.dir", "/var/run/openvswitch", "OVS default run directory.") - - flag.StringVar(&databaseVswitchName, "database.vswitch.name", "Open_vSwitch", "The name of OVS db.") - flag.StringVar(&databaseVswitchSocketRemote, "database.vswitch.socket.remote", "unix:/var/run/openvswitch/db.sock", "JSON-RPC unix socket to OVS db.") - flag.StringVar(&databaseVswitchFileDataPath, "database.vswitch.file.data.path", "/etc/openvswitch/conf.db", "OVS db file.") - flag.StringVar(&databaseVswitchFileLogPath, "database.vswitch.file.log.path", "/var/log/openvswitch/ovsdb-server.log", "OVS db log file.") - flag.StringVar(&databaseVswitchFilePidPath, "database.vswitch.file.pid.path", "/var/run/openvswitch/ovsdb-server.pid", "OVS db process id file.") - flag.StringVar(&databaseVswitchFileSystemIDPath, "database.vswitch.file.system.id.path", "/etc/openvswitch/system-id.conf", "OVS system id file.") - - flag.StringVar(&serviceVswitchdFileLogPath, "service.vswitchd.file.log.path", "/var/log/openvswitch/ovs-vswitchd.log", "OVS vswitchd daemon log file.") - flag.StringVar(&serviceVswitchdFilePidPath, "service.vswitchd.file.pid.path", "/var/run/openvswitch/ovs-vswitchd.pid", "OVS vswitchd daemon process id file.") - - flag.StringVar(&serviceOvnControllerFileLogPath, "service.ovncontroller.file.log.path", "/var/log/openvswitch/ovn-controller.log", "OVN controller daemon log file.") - flag.StringVar(&serviceOvnControllerFilePidPath, "service.ovncontroller.file.pid.path", "/var/run/openvswitch/ovn-controller.pid", "OVN controller daemon process id file.") - - var usageHelp = func() { - fmt.Fprintf(os.Stderr, "\n%s - Prometheus Exporter for Open Virtual Switch (OVS)\n\n", ovs.GetExporterName()) - fmt.Fprintf(os.Stderr, "Usage: %s [arguments]\n\n", ovs.GetExporterName()) - flag.PrintDefaults() - fmt.Fprintf(os.Stderr, "\nDocumentation: https://github.com/greenpau/ovs_exporter/\n\n") - } - flag.Usage = usageHelp - flag.Parse() - - if isShowVersion { + var metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.",).Default("/metrics").String() + var pollTimeout = kingpin.Flag("ovs.timeout", "Timeout on JSON-RPC requests to OVS.").Default("2").Int() + var pollInterval = kingpin.Flag("ovs.poll-interval", "The minimum interval (in seconds) between collections from OVS server.").Default("15").Int() + var isShowVersion = kingpin.Flag("version", "version information").Default("false").Bool() + var logLevel = kingpin.Flag("log.level", "logging severity level").Default("info").String() + var systemRunDir = kingpin.Flag("system.run.dir", "OVS default run directory.").Default("/var/run/openvswitch").String() + var databaseVswitchName = kingpin.Flag("database.vswitch.name", "The name of OVS db.").Default("Open_vSwitch").String() + var databaseVswitchSocketRemote = kingpin.Flag("database.vswitch.socket.remote", "JSON-RPC unix socket to OVS db.").Default("unix:/var/run/openvswitch/db.sock").String() + var databaseVswitchFileDataPath = kingpin.Flag("database.vswitch.file.data.path", "OVS db file.").Default("/etc/openvswitch/conf.db").String() + var databaseVswitchFileLogPath = kingpin.Flag("database.vswitch.file.log.path", "OVS db log file.").Default("/var/log/openvswitch/ovsdb-server.log").String() + var databaseVswitchFilePidPath = kingpin.Flag("database.vswitch.file.pid.path", "OVS db process id file.").Default("/var/run/openvswitch/ovsdb-server.pid").String() + var databaseVswitchFileSystemIDPath = kingpin.Flag("database.vswitch.file.system.id.path", "OVS system id file.").Default("/etc/openvswitch/system-id.conf").String() + var serviceVswitchdFileLogPath = kingpin.Flag("service.vswitchd.file.log.path", "OVS vswitchd daemon log file.").Default("/var/log/openvswitch/ovs-vswitchd.log").String() + var serviceVswitchdFilePidPath = kingpin.Flag("service.vswitchd.file.pid.path", "OVS vswitchd daemon process id file.").Default("/var/run/openvswitch/ovs-vswitchd.pid").String() + var serviceOvnControllerFileLogPath = kingpin.Flag("service.ovncontroller.file.log.path", "OVN controller daemon log file.").Default("/var/log/openvswitch/ovn-controller.log").String() + var serviceOvnControllerFilePidPath = kingpin.Flag("service.ovncontroller.file.pid.path", "OVN controller daemon process id file.").Default("/var/run/openvswitch/ovn-controller.pid").String() + var toolkitFlags = webflag.AddFlags(kingpin.CommandLine, ":9475") + kingpin.Parse() + + if *isShowVersion { fmt.Fprintf(os.Stdout, "%s %s", ovs.GetExporterName(), ovs.GetVersion()) if ovs.GetRevision() != "" { fmt.Fprintf(os.Stdout, ", commit: %s\n", ovs.GetRevision()) @@ -71,70 +44,63 @@ func main() { } os.Exit(0) } - - logger, err := ovs.NewLogger(logLevel) - if err != nil { - fmt.Fprintf(os.Stderr, "failed initializing logger: %v", err) - os.Exit(1) + logger, error := ovs_exporter.NewLogger(*logLevel) + if error != nil { + panic(error) } + slog.SetDefault(&logger) - level.Info(logger).Log( - "msg", "Starting exporter", - "exporter", ovs.GetExporterName(), - "version", ovs.GetVersionInfo(), - "build_context", ovs.GetVersionBuildContext(), + slog.Info("Starting exporter", + "exporter", ovs.GetExporterName(), + "version", ovs.GetVersionInfo(), + "build_context", ovs.GetVersionBuildContext(), ) opts := ovs.Options{ - Timeout: pollTimeout, - Logger: logger, + Timeout: *pollTimeout, + Logger: *slog.Default(), } exporter := ovs.NewExporter(opts) - exporter.Client.System.RunDir = systemRunDir + exporter.Client.System.RunDir = *systemRunDir - exporter.Client.Database.Vswitch.Name = databaseVswitchName - exporter.Client.Database.Vswitch.Socket.Remote = databaseVswitchSocketRemote - exporter.Client.Database.Vswitch.File.Data.Path = databaseVswitchFileDataPath - exporter.Client.Database.Vswitch.File.Log.Path = databaseVswitchFileLogPath - exporter.Client.Database.Vswitch.File.Pid.Path = databaseVswitchFilePidPath - exporter.Client.Database.Vswitch.File.SystemID.Path = databaseVswitchFileSystemIDPath + exporter.Client.Database.Vswitch.Name = *databaseVswitchName + exporter.Client.Database.Vswitch.Socket.Remote = *databaseVswitchSocketRemote + exporter.Client.Database.Vswitch.File.Data.Path = *databaseVswitchFileDataPath + exporter.Client.Database.Vswitch.File.Log.Path = *databaseVswitchFileLogPath + exporter.Client.Database.Vswitch.File.Pid.Path = *databaseVswitchFilePidPath + exporter.Client.Database.Vswitch.File.SystemID.Path = *databaseVswitchFileSystemIDPath - exporter.Client.Service.Vswitchd.File.Log.Path = serviceVswitchdFileLogPath - exporter.Client.Service.Vswitchd.File.Pid.Path = serviceVswitchdFilePidPath + exporter.Client.Service.Vswitchd.File.Log.Path = *serviceVswitchdFileLogPath + exporter.Client.Service.Vswitchd.File.Pid.Path = *serviceVswitchdFilePidPath - exporter.Client.Service.OvnController.File.Log.Path = serviceOvnControllerFileLogPath - exporter.Client.Service.OvnController.File.Pid.Path = serviceOvnControllerFilePidPath + exporter.Client.Service.OvnController.File.Log.Path = *serviceOvnControllerFileLogPath + exporter.Client.Service.OvnController.File.Pid.Path = *serviceOvnControllerFilePidPath if err := exporter.Connect(); err != nil { - level.Error(logger).Log( - "msg", "failed to init properly", - "error", err.Error(), - ) + slog.Error("failed to init properly", "error", err.Error(),) os.Exit(1) } - level.Info(logger).Log("ovs_system_id", exporter.Client.System.ID) + slog.Info("ovs_system_id", "ovs_system_id", exporter.Client.System.ID) - exporter.SetPollInterval(int64(pollInterval)) + exporter.SetPollInterval(int64(*pollInterval)) prometheus.MustRegister(exporter) - http.Handle(metricsPath, promhttp.Handler()) + http.Handle(*metricsPath, promhttp.Handler()) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(` OVS Exporter

OVS Exporter

-

Metrics

+

Metrics

`)) }) - level.Info(logger).Log("listen_on ", listenAddress) - if err := http.ListenAndServe(listenAddress, nil); err != nil { - level.Error(logger).Log( - "msg", "listener failed", - "error", err.Error(), + server := &http.Server{} + if err := web.ListenAndServe(server, toolkitFlags, slog.Default()); err != nil { + slog.Error("listener failed", "error", err.Error(), ) os.Exit(1) } diff --git a/go.mod b/go.mod index 740fb44..df49c2a 100644 --- a/go.mod +++ b/go.mod @@ -1,22 +1,37 @@ module github.com/greenpau/ovs_exporter -go 1.20 +go 1.22 + +toolchain go1.22.8 require ( - github.com/go-kit/log v0.2.1 + github.com/alecthomas/kingpin/v2 v2.4.0 + github.com/prometheus/client_golang v1.20.4 + github.com/prometheus/common v0.60.1 + github.com/prometheus/exporter-toolkit v0.13.1 github.com/greenpau/ovsdb v1.0.4 - github.com/prometheus/client_golang v1.16.0 - github.com/prometheus/common v0.44.0 ) require ( + github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/go-logfmt/logfmt v0.5.1 // indirect - github.com/golang/protobuf v1.5.3 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/prometheus/client_model v0.4.0 // indirect - github.com/prometheus/procfs v0.10.1 // indirect - golang.org/x/sys v0.8.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/coreos/go-systemd/v22 v22.5.0 // indirect + github.com/jpillora/backoff v1.0.0 // indirect + github.com/klauspost/compress v1.17.9 // indirect + github.com/mdlayher/socket v0.4.1 // indirect + github.com/mdlayher/vsock v1.2.1 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/procfs v0.15.1 // indirect + github.com/xhit/go-str2duration/v2 v2.1.0 // indirect + golang.org/x/crypto v0.28.0 // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/text v0.19.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 404877d..c290889 100644 --- a/go.sum +++ b/go.sum @@ -1,36 +1,78 @@ +github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjHpqDjYY= +github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE= +github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc= +github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= -github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= -github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA= -github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U= +github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA= +github.com/mdlayher/vsock v1.2.1 h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ= +github.com/mdlayher/vsock v1.2.1/go.mod h1:NRfCibel++DgeMD8z/hP+PPTjlNJsdPOmxcnENvE+SE= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI= +github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.60.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc= +github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= +github.com/prometheus/exporter-toolkit v0.13.1 h1:Evsh0gWQo2bdOHlnz9+0Nm7/OFfIwhE2Ws4A2jIlR04= +github.com/prometheus/exporter-toolkit v0.13.1/go.mod h1:ujdv2YIOxtdFxxqtloLpbqmxd5J0Le6IITUvIRSWjj0= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc= +github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= github.com/greenpau/ovsdb v1.0.4 h1:ekvfucZr5Dl/bYgcz6+nido4lSBDqG5kqLFUv55BqvQ= github.com/greenpau/ovsdb v1.0.4/go.mod h1:eZ72kooepm3wDa9o4YgmfEmbFCeibzSYrrZazwaopxo= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= -github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8= -github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc= -github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= -github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= -github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= -github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= -github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= -github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/ovs_exporter/ovs_exporter.go b/pkg/ovs_exporter/ovs_exporter.go index 87dc580..1b2b5a5 100644 --- a/pkg/ovs_exporter/ovs_exporter.go +++ b/pkg/ovs_exporter/ovs_exporter.go @@ -16,16 +16,16 @@ package ovs_exporter import ( "fmt" + "log/slog" _ "net/http/pprof" + "os" "sync" "sync/atomic" "time" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/greenpau/ovsdb" "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/common/promlog" + versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version" "github.com/prometheus/common/version" ) @@ -324,32 +324,32 @@ var ( // the prometheus metrics package. type Exporter struct { sync.RWMutex - Client *ovsdb.OvsClient - timeout int - pollInterval int64 - errors int64 - errorsLocker sync.RWMutex - nextCollectionTicker int64 - metrics []prometheus.Metric - logger log.Logger + Client *ovsdb.OvsClient + timeout int + pollInterval int64 + errors int64 + errorsLocker sync.RWMutex + nextCollectionTicker int64 + metrics []prometheus.Metric + logger slog.Logger } type Options struct { - Timeout int - Logger log.Logger + Timeout int + Logger slog.Logger } // NewLogger returns an instance of logger. -func NewLogger(logLevel string) (log.Logger, error) { - allowedLogLevel := &promlog.AllowedLevel{} - if err := allowedLogLevel.Set(logLevel); err != nil { - return nil, err +func NewLogger(logLevel string) (slog.Logger, error) { + slogLevel := slog.Level.Level(slog.LevelInfo) + error := slogLevel.UnmarshalText([]byte(logLevel)) + if error != nil { + slog.Error("Allowed case-independent log level values: debug, info, warn, error.", "log.level", logLevel) + return *slog.New(nil), error } - promlogConfig := &promlog.Config{ - Level: allowedLogLevel, - } - logger := promlog.New(promlogConfig) - return logger, nil + logHandlerOptions := slog.HandlerOptions{Level: slogLevel} + logger := slog.New(slog.NewTextHandler(os.Stdout, &logHandlerOptions)) + return *logger, nil } // NewExporter returns an initialized Exporter. @@ -365,34 +365,25 @@ func NewExporter(opts Options) *Exporter { client := ovsdb.NewOvsClient() client.Timeout = opts.Timeout e.Client = client - e.logger = opts.Logger + e.logger = *opts.Logger.With("system_id", e.Client.System.ID) return &e } func (e *Exporter) Connect() error { e.Client.GetSystemID() - level.Debug(e.logger).Log( - "msg", "NewExporter() calls Connect()", - "system_id", e.Client.System.ID, - ) + e.logger.Debug("NewExporter() calls Connect()") if err := e.Client.Connect(); err != nil { return err } - level.Debug(e.logger).Log( - "msg", "NewExporter() calls GetSystemInfo()", - "system_id", e.Client.System.ID, - ) + e.logger.Debug("NewExporter() calls GetSystemInfo()") if err := e.Client.GetSystemInfo(); err != nil { - return err + e.logger.Debug("Error occured during GetSystemInfo()", "error", err.Error()) } - level.Debug(e.logger).Log( - "msg", "NewExporter() initialized successfully", - "system_id", e.Client.System.ID, - ) + e.logger.Debug("NewExporter() initialized successfully") return nil } @@ -464,18 +455,12 @@ func (e *Exporter) IncrementErrorCounter() { func (e *Exporter) Collect(ch chan<- prometheus.Metric) { e.GatherMetrics() - level.Debug(e.logger).Log( - "msg", "Collect() calls RLock()", - "system_id", e.Client.System.ID, - ) + e.logger.Debug("Collect() calls RLock()") e.RLock() defer e.RUnlock() if len(e.metrics) == 0 { - level.Debug(e.logger).Log( - "msg", "Collect() no metrics found", - "system_id", e.Client.System.ID, - ) + e.logger.Debug("Collect() no metrics found") ch <- prometheus.MustNewConstMetric( up, @@ -505,11 +490,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { return } - level.Debug(e.logger).Log( - "msg", "Collect() sends metrics to a shared channel", - "system_id", e.Client.System.ID, - "metric_count", len(e.metrics), - ) + e.logger.Debug("Collect() sends metrics to a shared channel", "metric_count", len(e.metrics)) for _, m := range e.metrics { ch <- m @@ -519,26 +500,17 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { // GatherMetrics collect data from OVN server and stores them // as Prometheus metrics. func (e *Exporter) GatherMetrics() { - level.Debug(e.logger).Log( - "msg", "GatherMetrics() called", - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() called", ) if time.Now().Unix() < e.nextCollectionTicker { return } e.Lock() - level.Debug(e.logger).Log( - "msg", "GatherMetrics() locked", - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() locked") defer e.Unlock() if len(e.metrics) > 0 { e.metrics = e.metrics[:0] - level.Debug(e.logger).Log( - "msg", "GatherMetrics() cleared metrics", - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() cleared metrics") } upValue := 1 @@ -546,20 +518,13 @@ func (e *Exporter) GatherMetrics() { err = e.Client.GetSystemInfo() if err != nil { - level.Error(e.logger).Log( - "msg", "GetSystemInfo() failed", - "vswitch_name", e.Client.Database.Vswitch.Name, - "system_id", e.Client.System.ID, - "error", err.Error(), - ) + e.logger.Debug("GetSystemInfo() failed", + "vswitch_name", e.Client.Database.Vswitch.Name, + "error", err.Error()) e.IncrementErrorCounter() upValue = 0 } else { - level.Debug(e.logger).Log( - "msg", "GetSystemInfo() successful", - "vswitch_name", e.Client.Database.Vswitch.Name, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GetSystemInfo() successful", "vswitch_name", e.Client.Database.Vswitch.Name) } components := []string{ @@ -568,19 +533,9 @@ func (e *Exporter) GatherMetrics() { } for _, component := range components { p, err := e.Client.GetProcessInfo(component) - level.Debug(e.logger).Log( - "msg", "GatherMetrics() calls GetProcessInfo()", - "component", component, - "system_id", e.Client.System.ID, - ) - + e.logger.Debug("GatherMetrics() calls GetProcessInfo()", "component", component) if err != nil { - level.Error(e.logger).Log( - "msg", "GetProcessInfo() failed", - "component", component, - "system_id", e.Client.System.ID, - "error", err.Error(), - ) + e.logger.Error("GetProcessInfo() failed", "component", component, "error", err.Error()) e.IncrementErrorCounter() upValue = 0 } @@ -593,11 +548,7 @@ func (e *Exporter) GatherMetrics() { p.User, p.Group, )) - level.Debug(e.logger).Log( - "msg", "GatherMetrics() completed GetProcessInfo()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() completed GetProcessInfo()", "component", component) } components = []string{ @@ -605,28 +556,15 @@ func (e *Exporter) GatherMetrics() { "ovs-vswitchd", } for _, component := range components { - level.Debug(e.logger).Log( - "msg", "GatherMetrics() calls GetLogFileInfo()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() calls GetLogFileInfo()", "component", component) file, err := e.Client.GetLogFileInfo(component) if err != nil { - level.Error(e.logger).Log( - "msg", "GetLogFileInfo() failed", - "component", component, - "system_id", e.Client.System.ID, - "error", err.Error(), - ) + e.logger.Error("GetLogFileInfo() failed", "component", component, "error", err.Error()) e.IncrementErrorCounter() continue } - level.Debug(e.logger).Log( - "msg", "GatherMetrics() completed GetLogFileInfo()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() completed GetLogFileInfo()", "component", component) e.metrics = append(e.metrics, prometheus.MustNewConstMetric( logFileSize, @@ -637,29 +575,16 @@ func (e *Exporter) GatherMetrics() { file.Path, )) - level.Debug(e.logger).Log( - "msg", "GatherMetrics() calls GetLogFileEventStats()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() calls GetLogFileEventStats()", "component", component) eventStats, err := e.Client.GetLogFileEventStats(component) if err != nil { - level.Error(e.logger).Log( - "msg", "GetLogFileEventStats() failed", - "component", component, - "system_id", e.Client.System.ID, - "error", err.Error(), - ) + e.logger.Error("GetLogFileEventStats() failed", "component", component, "error", err.Error()) e.IncrementErrorCounter() continue } - level.Debug(e.logger).Log( - "msg", "GatherMetrics() completed GetLogFileEventStats()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() completed GetLogFileEventStats()", "component", component) for sev, sources := range eventStats { for source, count := range sources { @@ -680,47 +605,20 @@ func (e *Exporter) GatherMetrics() { "ovsdb-server", "vswitchd-service", } - for _, component := range components { - level.Debug(e.logger).Log( - "msg", "GatherMetrics() calls AppListCommands()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() calls AppListCommands()", "component", component) if cmds, err := e.Client.AppListCommands(component); err != nil { - level.Error(e.logger).Log( - "msg", "AppListCommands() failed", - "component", component, - "system_id", e.Client.System.ID, - "error", err.Error(), - ) + e.logger.Error("AppListCommands() failed", "component", component, "error", err.Error()) e.IncrementErrorCounter() - level.Debug(e.logger).Log( - "msg", "GatherMetrics() completed AppListCommands()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() completed AppListCommands()", "component", component) } else { - level.Debug(e.logger).Log( - "msg", "GatherMetrics() completed AppListCommands()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() completed AppListCommands()", "component", component) if cmds["coverage/show"] { - level.Debug(e.logger).Log( - "msg", "GatherMetrics() calls GetAppCoverageMetrics()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() calls GetAppCoverageMetrics()", "component", component) if metrics, err := e.Client.GetAppCoverageMetrics(component); err != nil { - level.Error(e.logger).Log( - "msg", "GetAppCoverageMetrics() failed", - "component", component, - "system_id", e.Client.System.ID, - "error", err.Error(), - ) + e.logger.Error("GetAppCoverageMetrics() failed", "component", component, "error", err.Error()) e.IncrementErrorCounter() } else { for event, metric := range metrics { @@ -748,25 +646,12 @@ func (e *Exporter) GatherMetrics() { } } } - level.Debug(e.logger).Log( - "msg", "GatherMetrics() completed GetAppCoverageMetrics()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() completed GetAppCoverageMetrics()", "component", component) } if cmds["memory/show"] { - level.Debug(e.logger).Log( - "msg", "GatherMetrics() calls GetAppMemoryMetrics()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() calls GetAppMemoryMetrics()", "component", component) if metrics, err := e.Client.GetAppMemoryMetrics(component); err != nil { - level.Error(e.logger).Log( - "msg", "GetAppMemoryMetrics() failed", - "component", component, - "system_id", e.Client.System.ID, - "error", err.Error(), - ) + e.logger.Error("GetAppMemoryMetrics() failed", "component", component, "error", err.Error()) e.IncrementErrorCounter() } else { for facility, value := range metrics { @@ -780,26 +665,13 @@ func (e *Exporter) GatherMetrics() { )) } } - level.Debug(e.logger).Log( - "msg", "GatherMetrics() completed GetAppMemoryMetrics()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() completed GetAppMemoryMetrics()", "component", component) } if cmds["dpif/show"] && (component == "vswitchd-service") { - level.Debug(e.logger).Log( - "msg", "GatherMetrics() calls GetAppDatapath()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() calls GetAppDatapath()", "component", component) if dps, brs, intfs, err := e.Client.GetAppDatapath(component); err != nil { - level.Error(e.logger).Log( - "msg", "GetAppDatapath() failed", - "component", component, - "system_id", e.Client.System.ID, - "error", err.Error(), - ) + e.logger.Error("GetAppDatapath() failed", "component", component, "error", err.Error()) e.IncrementErrorCounter() } else { for _, dp := range dps { @@ -892,26 +764,15 @@ func (e *Exporter) GatherMetrics() { )) } } - level.Debug(e.logger).Log( - "msg", "GatherMetrics() completed GetAppDatapath()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() completed GetAppDatapath()", "component", component) } } } - level.Debug(e.logger).Log( - "msg", "GatherMetrics() calls GetDbInterfaces()", - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() calls GetDbInterfaces()") if intfs, err := e.Client.GetDbInterfaces(); err != nil { - level.Error(e.logger).Log( - "msg", "GetDbInterfaces() failed", - "system_id", e.Client.System.ID, - "error", err.Error(), - ) + e.logger.Error("GetDbInterfaces() failed", "error", err.Error()) e.IncrementErrorCounter() } else { for _, intf := range intfs { @@ -1136,12 +997,10 @@ func (e *Exporter) GatherMetrics() { intf.UUID, )) default: - level.Debug(e.logger).Log( - "msg", "detected malformed interface statistics", - "system_id", e.Client.System.ID, - "key", key, - "value", value, - "error", "OVS interface statistics has unsupported key", + e.logger.Debug("detected malformed interface statistics", + "key", key, + "value", value, + "error", "OVS interface statistics has unsupported key", ) } } @@ -1195,29 +1054,17 @@ func (e *Exporter) GatherMetrics() { } } - level.Debug(e.logger).Log( - "msg", "GatherMetrics() completed GetDbInterfaces()", - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() completed GetDbInterfaces()") components = []string{ "ovsdb-server", } for _, component := range components { - level.Debug(e.logger).Log( - "msg", "GatherMetrics() calls IsDefaultPortUp()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() calls IsDefaultPortUp()", "component", component) defaultPortUp, err := e.Client.IsDefaultPortUp(component) if err != nil { - level.Error(e.logger).Log( - "msg", "IsDefaultPortUp() failed", - "component", component, - "system_id", e.Client.System.ID, - "error", err.Error(), - ) + e.logger.Error("IsDefaultPortUp() failed", "component", component, "error", err.Error()) e.IncrementErrorCounter() } e.metrics = append(e.metrics, prometheus.MustNewConstMetric( @@ -1228,25 +1075,12 @@ func (e *Exporter) GatherMetrics() { component, "default", )) - level.Debug(e.logger).Log( - "msg", "GatherMetrics() completed IsDefaultPortUp()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() completed IsDefaultPortUp()", "component", component) - level.Debug(e.logger).Log( - "msg", "GatherMetrics() calls IsSslPortUp()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() calls IsSslPortUp()", "component", component) sslPortUp, err := e.Client.IsSslPortUp(component) if err != nil { - level.Error(e.logger).Log( - "msg", "IsSslPortUp() failed", - "component", component, - "system_id", e.Client.System.ID, - "error", err.Error(), - ) + e.logger.Error("IsSslPortUp() failed", "component", component, "error", err.Error()) e.IncrementErrorCounter() } e.metrics = append(e.metrics, prometheus.MustNewConstMetric( @@ -1257,11 +1091,7 @@ func (e *Exporter) GatherMetrics() { component, "ssl", )) - level.Debug(e.logger).Log( - "msg", "GatherMetrics() completed IsSslPortUp()", - "component", component, - "system_id", e.Client.System.ID, - ) + e.logger.Debug("GatherMetrics() completed IsSslPortUp()", "component", component) } e.metrics = append(e.metrics, prometheus.MustNewConstMetric( @@ -1295,16 +1125,11 @@ func (e *Exporter) GatherMetrics() { e.nextCollectionTicker = time.Now().Add(time.Duration(e.pollInterval) * time.Second).Unix() - level.Debug(e.logger).Log( - "msg", "GatherMetrics() returns", - "system_id", e.Client.System.ID, - ) - - return + e.logger.Debug("GatherMetrics() returns") } func init() { - prometheus.MustRegister(version.NewCollector(namespace + "_exporter")) + prometheus.MustRegister(versioncollector.NewCollector(namespace + "_exporter")) } // GetVersionInfo returns exporter info.