44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
|
|
"metrics-collector/internal/api"
|
|
"metrics-collector/ui"
|
|
)
|
|
|
|
func main() {
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8091"
|
|
}
|
|
|
|
srv := api.NewServer()
|
|
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/health", func(w http.ResponseWriter, _ *http.Request) {
|
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
|
_, _ = w.Write([]byte("ok\n"))
|
|
})
|
|
mux.HandleFunc("/metrics", srv.HandleMetrics)
|
|
// ⛔ /cron/metrics — внешний путь через ingress /cron → metrics-collector:8091.
|
|
// ⛔ НЕ УДАЛЯТЬ. Без этого маршрута UI на /cron не получает данные.
|
|
mux.HandleFunc("/cron/metrics", srv.HandleMetrics)
|
|
mux.Handle("/", ui.Handler())
|
|
|
|
httpSrv := &http.Server{
|
|
Addr: ":" + port,
|
|
Handler: mux,
|
|
ReadTimeout: 15 * time.Second,
|
|
WriteTimeout: 15 * time.Second,
|
|
}
|
|
|
|
log.Printf("metrics-collector listening on :%s", port)
|
|
if err := httpSrv.ListenAndServe(); err != nil {
|
|
log.Fatalf("listen: %v", err)
|
|
}
|
|
}
|