@ -43,6 +43,7 @@ import (
"tailscale.com/types/appctype"
"tailscale.com/types/dnstype"
"tailscale.com/types/key"
"tailscale.com/util/clientmetric"
"tailscale.com/util/eventbus"
)
@ -385,18 +386,14 @@ func (lc *Client) IncrementCounter(ctx context.Context, name string, delta int)
if ! buildfeatures . HasClientMetrics {
return nil
}
type metricUpdate struct {
Name string ` json:"name" `
Type string ` json:"type" `
Value int ` json:"value" ` // amount to increment by
}
if delta < 0 {
return errors . New ( "negative delta not allowed" )
}
_ , err := lc . send ( ctx , "POST" , "/localapi/v0/upload-client-metrics" , 200 , jsonBody ( [ ] metricUpdate{ {
_ , err := lc . send ( ctx , "POST" , "/localapi/v0/upload-client-metrics" , 200 , jsonBody ( [ ] clientmetric . MetricUpdate { {
Name : name ,
Type : "counter" ,
Value : delta ,
Op : "add" ,
} } ) )
return err
}
@ -405,15 +402,23 @@ func (lc *Client) IncrementCounter(ctx context.Context, name string, delta int)
// metric by the given delta. If the metric has yet to exist, a new gauge
// metric is created and initialized to delta. The delta value can be negative.
func ( lc * Client ) IncrementGauge ( ctx context . Context , name string , delta int ) error {
type metricUpdate struct {
Name string ` json:"name" `
Type string ` json:"type" `
Value int ` json:"value" ` // amount to increment by
}
_ , err := lc . send ( ctx , "POST" , "/localapi/v0/upload-client-metrics" , 200 , jsonBody ( [ ] metricUpdate { {
_ , err := lc . send ( ctx , "POST" , "/localapi/v0/upload-client-metrics" , 200 , jsonBody ( [ ] clientmetric . MetricUpdate { {
Name : name ,
Type : "gauge" ,
Value : delta ,
Op : "add" ,
} } ) )
return err
}
// SetGauge sets the value of a Tailscale daemon's gauge metric to the given value.
// If the metric has yet to exist, a new gauge metric is created and initialized to value.
func ( lc * Client ) SetGauge ( ctx context . Context , name string , value int ) error {
_ , err := lc . send ( ctx , "POST" , "/localapi/v0/upload-client-metrics" , 200 , jsonBody ( [ ] clientmetric . MetricUpdate { {
Name : name ,
Type : "gauge" ,
Value : value ,
Op : "set" ,
} } ) )
return err
}