Skip to content

Commit

Permalink
WindowsSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
syepes committed Dec 7, 2021
1 parent 5b7a681 commit 4be0d2a
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ builds:
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
Expand All @@ -19,6 +20,7 @@ builds:
- linux_amd64
- darwin_amd64
- darwin_arm64
- windows_amd64
main: .
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
binary: network_exporter
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.32.1
github.com/prometheus/procfs v0.7.3 // indirect
golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 // indirect
golang.org/x/net v0.0.0-20211206223403-eba003a116a9
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4 h1:DZshvxDdVoeKIbudAdFEKi+f7
golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c h1:WtYZ93XtWSO5KlOMgPZu7hXY9WhMZpprvlm5VwvAl8c=
golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211206223403-eba003a116a9 h1:HhGRSJWlxVO54+s9MeOVrZrbnwv+6oZQIvsUrMUte7U=
golang.org/x/net v0.0.0-20211206223403-eba003a116a9/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -327,6 +329,8 @@ golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 h1:kwrAHlwJ0DUBZwQ238v+Uod/3
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 h1:TyHqChC80pFkXWraUUf6RuB5IqFdQieMLwwCJokV2pc=
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E=
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
38 changes: 2 additions & 36 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"net"
"net/http"
"os"
"os/signal"
"syscall"
"time"

_ "net/http/pprof"
Expand All @@ -26,7 +24,7 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)

const version string = "1.3.8"
const version string = "1.4.0"

var (
listenAddress = kingpin.Flag("web.listen-address", "The address to listen on for HTTP requests").Default(":9427").String()
Expand Down Expand Up @@ -61,39 +59,7 @@ func main() {
os.Exit(1)
}

// Signal handling
hup := make(chan os.Signal, 1)
signal.Notify(hup, syscall.SIGHUP)
susr := make(chan os.Signal, 1)
signal.Notify(susr, syscall.SIGUSR1)
go func() {
for {
select {
case <-hup:
level.Debug(logger).Log("msg", "Signal: HUP")
level.Info(logger).Log("msg", "ReLoading config")
if err := sc.ReloadConfig(*configFile); err != nil {
level.Error(logger).Log("msg", "Reloading config skipped", "err", err)
continue
} else {
monitorPING.AddTargets()
monitorPING.DelTargets()
monitorMTR.AddTargets()
monitorMTR.DelTargets()
monitorTCP.AddTargets()
monitorTCP.DelTargets()
monitorHTTPGet.AddTargets()
monitorHTTPGet.DelTargets()
}
case <-susr:
level.Debug(logger).Log("msg", "Signal: USR1")
fmt.Printf("PING: %+v\n", monitorPING)
fmt.Printf("MTR: %+v\n", monitorMTR)
fmt.Printf("TCP: %+v\n", monitorTCP)
fmt.Printf("HTTPGet: %+v\n", monitorHTTPGet)
}
}
}()
reloadSignal()

resolver := getResolver()

Expand Down
50 changes: 50 additions & 0 deletions signal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//go:build !windows
// +build !windows

package main

import (
"fmt"
"os"
"os/signal"
"syscall"

"github.com/go-kit/log/level"
)

func reloadSignal() {

// Signal handling
hup := make(chan os.Signal, 1)
signal.Notify(hup, syscall.SIGHUP)
susr := make(chan os.Signal, 1)
signal.Notify(susr, syscall.SIGUSR1)
go func() {
for {
select {
case <-hup:
level.Debug(logger).Log("msg", "Signal: HUP")
level.Info(logger).Log("msg", "ReLoading config")
if err := sc.ReloadConfig(*configFile); err != nil {
level.Error(logger).Log("msg", "Reloading config skipped", "err", err)
continue
} else {
monitorPING.AddTargets()
monitorPING.DelTargets()
monitorMTR.AddTargets()
monitorMTR.DelTargets()
monitorTCP.AddTargets()
monitorTCP.DelTargets()
monitorHTTPGet.AddTargets()
monitorHTTPGet.DelTargets()
}
case <-susr:
level.Debug(logger).Log("msg", "Signal: USR1")
fmt.Printf("PING: %+v\n", monitorPING)
fmt.Printf("MTR: %+v\n", monitorMTR)
fmt.Printf("TCP: %+v\n", monitorTCP)
fmt.Printf("HTTPGet: %+v\n", monitorHTTPGet)
}
}
}()
}
41 changes: 41 additions & 0 deletions signal_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//go:build windows
// +build windows

package main

import (
"os"
"os/signal"
"syscall"

"github.com/go-kit/log/level"
)

func reloadSignal() {

// Signal handling
hup := make(chan os.Signal, 1)
signal.Notify(hup, syscall.SIGHUP)
go func() {
for {
select {
case <-hup:
level.Debug(logger).Log("msg", "Signal: HUP")
level.Info(logger).Log("msg", "ReLoading config")
if err := sc.ReloadConfig(*configFile); err != nil {
level.Error(logger).Log("msg", "Reloading config skipped", "err", err)
continue
} else {
monitorPING.AddTargets()
monitorPING.DelTargets()
monitorMTR.AddTargets()
monitorMTR.DelTargets()
monitorTCP.AddTargets()
monitorTCP.DelTargets()
monitorHTTPGet.AddTargets()
monitorHTTPGet.DelTargets()
}
}
}
}()
}

0 comments on commit 4be0d2a

Please sign in to comment.