-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
60 lines (50 loc) · 1.51 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"flag"
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"time"
"github.com/supporttools/prometheus-tunnel/pkg/config"
"github.com/supporttools/prometheus-tunnel/pkg/logging"
"github.com/supporttools/prometheus-tunnel/pkg/metrics"
"github.com/supporttools/prometheus-tunnel/pkg/proxy"
)
func main() {
flag.Parse()
config.LoadConfiguration()
log := logging.SetupLogging(config.CFG.Debug)
log.Debug("Debug logging enabled")
log.Info("Starting Prometheus-Tunnel...")
// Start Prometheus metrics server
log.Infoln("Starting metrics server")
go metrics.StartMetricsServer()
// Set up signal handling for graceful shutdown
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
done := make(chan bool, 1)
// Create and start proxy server
proxyHandler, err := proxy.NewProxyHandler(config.CFG.ServerIP, config.CFG.ServerPort, config.CFG.Debug)
if err != nil {
log.Fatalf("Failed to create proxy handler: %v", err)
}
go func() {
log.Printf("Starting proxy server on port %d\n", config.CFG.ServerPort)
srv := &http.Server{
Addr: ":" + strconv.Itoa(config.CFG.ServerPort),
Handler: http.HandlerFunc(proxyHandler),
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 15 * time.Second,
}
if err := srv.ListenAndServe(); err != nil {
log.Fatal(err)
}
}()
<-sigs
log.Infoln("Received shutdown signal, shutting down proxy server...")
done <- true
log.Infoln("Prometheus-Tunnel shut down gracefully")
}