mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-05 09:04:09 -04:00
The health check endpoint listens on a dedicated HTTP server. By default, it is available at 0.0.0.0:9000/health. This can be configured using the --health-listen-address flag. The results are cached for 3 seconds to avoid excessive calls. The health check performs the following: Checks the number of active listeners. Validates each listener via WebSocket and QUIC dials, including TLS certificate verification.
29 lines
549 B
Go
29 lines
549 B
Go
package healthcheck
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/coder/websocket"
|
|
|
|
"github.com/netbirdio/netbird/shared/relay"
|
|
)
|
|
|
|
func dialWS(ctx context.Context, address string) error {
|
|
url := fmt.Sprintf("wss://%s%s", address, relay.WebSocketURLPath)
|
|
|
|
conn, resp, err := websocket.Dial(ctx, url, nil)
|
|
if resp != nil {
|
|
defer func() {
|
|
_ = resp.Body.Close()
|
|
}()
|
|
|
|
}
|
|
if err != nil {
|
|
return fmt.Errorf("failed to connect to websocket: %w", err)
|
|
}
|
|
|
|
_ = conn.Close(websocket.StatusNormalClosure, "availability check complete")
|
|
return nil
|
|
}
|