mirror of
https://github.com/prometheus-community/windows_exporter
synced 2024-12-28 17:32:05 +00:00
Add gokit adapter to make https toolkit work
Signed-off-by: Calle Pettersson <carlpett@users.noreply.github.com>
This commit is contained in:
parent
c5a545540d
commit
eaa003f5af
@ -404,7 +404,7 @@ func main() {
|
||||
go func() {
|
||||
log.Infoln("Starting server on", *listenAddress)
|
||||
server := &http.Server{Addr: *listenAddress}
|
||||
if err := https.Listen(server, *httpsConfig, logger); err != nil {
|
||||
if err := https.Listen(server, *httpsConfig, log.NewToolkitAdapter()); err != nil {
|
||||
log.Fatalf("cannot start windows_exporter: %s", err)
|
||||
}
|
||||
}()
|
||||
|
1
go.mod
1
go.mod
@ -7,6 +7,7 @@ require (
|
||||
github.com/Microsoft/hcsshim v0.8.6
|
||||
github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f
|
||||
github.com/dimchansky/utfbom v1.1.0
|
||||
github.com/go-kit/kit v0.10.0
|
||||
github.com/go-ole/go-ole v1.2.1 // indirect
|
||||
github.com/google/go-cmp v0.5.1 // indirect
|
||||
github.com/leoluk/perflib_exporter v0.1.0
|
||||
|
46
log/gokit_adapter.go
Normal file
46
log/gokit_adapter.go
Normal file
@ -0,0 +1,46 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/log/level"
|
||||
)
|
||||
|
||||
// Returns an adapter implementing the go-kit/kit/log.Logger interface on our
|
||||
// logrus logger
|
||||
func NewToolkitAdapter() *logAdapter {
|
||||
return &logAdapter{}
|
||||
}
|
||||
|
||||
type logAdapter struct{}
|
||||
|
||||
func (*logAdapter) Log(keyvals ...interface{}) error {
|
||||
var lvl level.Value
|
||||
var msg string
|
||||
for i := 0; i < len(keyvals); i += 2 {
|
||||
switch keyvals[i] {
|
||||
case "level":
|
||||
tlvl, ok := keyvals[i+1].(level.Value)
|
||||
if !ok {
|
||||
Warnf("Could not cast level of type %T", keyvals[i+1])
|
||||
} else {
|
||||
lvl = tlvl
|
||||
}
|
||||
case "msg":
|
||||
msg = keyvals[i+1].(string)
|
||||
}
|
||||
}
|
||||
|
||||
switch lvl {
|
||||
case level.ErrorValue():
|
||||
Errorln(msg)
|
||||
case level.WarnValue():
|
||||
Warnln(msg)
|
||||
case level.InfoValue():
|
||||
Infoln(msg)
|
||||
case level.DebugValue():
|
||||
Debugln(msg)
|
||||
default:
|
||||
Warnf("Unmatched log level: '%v' for message %q", lvl, msg)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user