mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-30 05:25:35 +00:00
5336362e64
- Wrap each prober function into a probe class that allows associating metric labels and custom metrics with a given probe; - Make sure all existing probe classes set a `class` metric label; - Move bandwidth probe size from being a metric label to a separate gauge metric; this will make it possible to use it to calculate average used bandwidth using a PromQL query; - Also export transfer time for the bandwidth prober (more accurate than the total probe time, since it excludes connection establishment time). Updates tailscale/corp#17912 Signed-off-by: Anton Tolchanov <anton@tailscale.com>
33 lines
638 B
Go
33 lines
638 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package prober
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
// TCP returns a Probe that healthchecks a TCP endpoint.
|
|
//
|
|
// The ProbeFunc reports whether it can successfully connect to addr.
|
|
func TCP(addr string) ProbeClass {
|
|
return ProbeClass{
|
|
Probe: func(ctx context.Context) error {
|
|
return probeTCP(ctx, addr)
|
|
},
|
|
Class: "tcp",
|
|
}
|
|
}
|
|
|
|
func probeTCP(ctx context.Context, addr string) error {
|
|
var d net.Dialer
|
|
conn, err := d.DialContext(ctx, "tcp", addr)
|
|
if err != nil {
|
|
return fmt.Errorf("dialing %q: %v", addr, err)
|
|
}
|
|
conn.Close()
|
|
return nil
|
|
}
|