generated from sendnrw/template_golang
init
Some checks failed
build-binaries / build (, amd64, linux) (push) Has been skipped
build-binaries / build (, arm, 7, linux) (push) Has been skipped
build-binaries / build (, arm64, linux) (push) Has been skipped
build-binaries / build (.exe, amd64, windows) (push) Has been skipped
build-binaries / release (push) Has been skipped
build-binaries / publish-agent (push) Has been skipped
release-tag / release-image (push) Has been cancelled
Some checks failed
build-binaries / build (, amd64, linux) (push) Has been skipped
build-binaries / build (, arm, 7, linux) (push) Has been skipped
build-binaries / build (, arm64, linux) (push) Has been skipped
build-binaries / build (.exe, amd64, windows) (push) Has been skipped
build-binaries / release (push) Has been skipped
build-binaries / publish-agent (push) Has been skipped
release-tag / release-image (push) Has been cancelled
This commit is contained in:
72
main.go
Normal file
72
main.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfgFile := flag.String("config", "config.yaml", "path to config file")
|
||||
flag.Parse()
|
||||
|
||||
cfg, err := LoadConfig(*cfgFile)
|
||||
if err != nil {
|
||||
log.Fatalf("error loading config: %v", err)
|
||||
}
|
||||
|
||||
// HTTP server für Prometheus
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
go func() {
|
||||
log.Printf("listening on %s", cfg.ListenAddr)
|
||||
if err := http.ListenAndServe(cfg.ListenAddr, nil); err != nil {
|
||||
log.Fatalf("http server error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Targets starten
|
||||
stop := make(chan struct{})
|
||||
for _, t := range cfg.Targets {
|
||||
settings := mergeSettings(cfg.Defaults, t)
|
||||
r := NewTargetRunner(t.Name, t.Host, settings)
|
||||
go r.Run(stop)
|
||||
}
|
||||
|
||||
// sauber beenden
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
|
||||
<-sig
|
||||
close(stop)
|
||||
fmt.Println("shutting down...")
|
||||
}
|
||||
|
||||
func mergeSettings(def TargetSettings, t TargetConfig) TargetSettings {
|
||||
out := def
|
||||
|
||||
if t.Interval != nil {
|
||||
out.Interval = *t.Interval
|
||||
}
|
||||
if t.Timeout != nil {
|
||||
out.Timeout = *t.Timeout
|
||||
}
|
||||
if t.Size != nil {
|
||||
out.Size = *t.Size
|
||||
}
|
||||
if t.HistorySize != nil {
|
||||
out.HistorySize = *t.HistorySize
|
||||
}
|
||||
if t.DNSServer != nil {
|
||||
out.DNSServer = *t.DNSServer
|
||||
}
|
||||
if t.DisableIPv6 != nil {
|
||||
out.DisableIPv6 = *t.DisableIPv6
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user