MCPcopy
hub / github.com/seaweedfs/seaweedfs / main

Function main

telemetry/server/main.go:26–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24)
25
26func main() {
27 flag.Parse()
28
29 // Create Prometheus storage instance
30 store := storage.NewPrometheusStorage()
31
32 // Start cleanup routine
33 go func() {
34 ticker := time.NewTicker(*cleanupInterval)
35 defer ticker.Stop()
36 for range ticker.C {
37 store.CleanupOldInstances(*maxInstanceAge)
38 }
39 }()
40
41 // Setup HTTP handlers
42 mux := http.NewServeMux()
43
44 // Prometheus metrics endpoint
45 mux.Handle("/metrics", promhttp.Handler())
46
47 // API endpoints
48 apiHandler := api.NewHandler(store)
49 mux.HandleFunc("/api/collect", corsMiddleware(logMiddleware(apiHandler.CollectTelemetry)))
50 mux.HandleFunc("/api/stats", corsMiddleware(logMiddleware(apiHandler.GetStats)))
51 mux.HandleFunc("/api/instances", corsMiddleware(logMiddleware(apiHandler.GetInstances)))
52 mux.HandleFunc("/api/metrics", corsMiddleware(logMiddleware(apiHandler.GetMetrics)))
53
54 // Dashboard (optional)
55 if *enableDashboard {
56 dashboardHandler := dashboard.NewHandler()
57 mux.HandleFunc("/", corsMiddleware(dashboardHandler.ServeIndex))
58 mux.HandleFunc("/dashboard", corsMiddleware(dashboardHandler.ServeIndex))
59 mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
60 }
61
62 // Health check
63 mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
64 w.Header().Set("Content-Type", "application/json")
65 json.NewEncoder(w).Encode(map[string]string{
66 "status": "ok",
67 "time": time.Now().UTC().Format(time.RFC3339),
68 })
69 })
70
71 addr := fmt.Sprintf(":%d", *port)
72 log.Printf("Starting telemetry server on %s", addr)
73 log.Printf("Prometheus metrics: http://localhost%s/metrics", addr)
74 if *enableDashboard {
75 log.Printf("Dashboard: http://localhost%s/dashboard", addr)
76 }
77 log.Printf("Cleanup interval: %v, Max instance age: %v", *cleanupInterval, *maxInstanceAge)
78
79 if err := http.ListenAndServe(addr, mux); err != nil {
80 log.Fatalf("Server failed: %v", err)
81 }
82}
83

Callers

nothing calls this directly

Calls 15

CleanupOldInstancesMethod · 0.95
NewPrometheusStorageFunction · 0.92
NewHandlerFunction · 0.92
NewHandlerFunction · 0.92
corsMiddlewareFunction · 0.85
logMiddlewareFunction · 0.85
ParseMethod · 0.80
HandlerMethod · 0.80
DirMethod · 0.80
EncodeMethod · 0.80
NowMethod · 0.80
ListenAndServeMethod · 0.80

Tested by

no test coverage detected