MCPcopy Create free account
hub / github.com/facebook/time / Start

Method Start

cmd/ntripper/stats/json.go:44–60  ·  view source on GitHub ↗

Start launches the HTTP server and a background goroutine that computes per-second rates.

(port int)

Source from the content-addressed store, hash-verified

42// Start launches the HTTP server and a background goroutine that computes
43// per-second rates.
44func (s *JSONStats) Start(port int) {
45 go s.computeRates()
46
47 mux := http.NewServeMux()
48 mux.HandleFunc("/", s.handleRequest)
49 addr := fmt.Sprintf(":%d", port)
50 slog.Info("starting JSON monitoring server", "addr", addr)
51 srv := &http.Server{
52 Addr: addr,
53 Handler: mux,
54 ReadTimeout: 5 * time.Second,
55 WriteTimeout: 5 * time.Second,
56 }
57 if err := srv.ListenAndServe(); err != nil {
58 slog.Error("monitoring server failed", "error", err)
59 }
60}
61
62func (s *JSONStats) computeRates() {
63 ticker := time.NewTicker(time.Second)

Callers 6

mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
doWorkFunction · 0.95

Calls 2

computeRatesMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected