File tree 3 files changed +49
-9
lines changed 3 files changed +49
-9
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ import (
16
16
"os"
17
17
"os/user"
18
18
"path/filepath"
19
- "reflect"
20
19
"sort"
21
20
"strconv"
22
21
"strings"
@@ -1221,11 +1220,11 @@ func (a *agent) startReportingConnectionStats(ctx context.Context) {
1221
1220
// Convert from microseconds to milliseconds.
1222
1221
stats .ConnectionMedianLatencyMS /= 1000
1223
1222
1224
- lastStat := a . latestStat . Load ()
1225
- if lastStat != nil && reflect . DeepEqual ( lastStat , stats ) {
1226
- a . logger . Info ( ctx , "skipping stat because nothing changed" )
1227
- return
1228
- }
1223
+ // Collect agent metrics.
1224
+ // Agent metrics are changing all the time, so there is no need to perform
1225
+ // reflect.DeepEqual to see if stats should be transferred.
1226
+ stats . Metrics = collectMetrics ()
1227
+
1229
1228
a .latestStat .Store (stats )
1230
1229
1231
1230
select {
Original file line number Diff line number Diff line change
1
+ package agent
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ "tailscale.com/util/clientmetric"
7
+
8
+ "github.com/coder/coder/codersdk/agentsdk"
9
+ )
10
+
11
+ func collectMetrics () []agentsdk.AgentMetric {
12
+ // Tailscale metrics
13
+ metrics := clientmetric .Metrics ()
14
+ collected := make ([]agentsdk.AgentMetric , 0 , len (metrics ))
15
+ for _ , m := range metrics {
16
+ collected = append (collected , agentsdk.AgentMetric {
17
+ Name : m .Name (),
18
+ Type : asMetricType (m .Type ()),
19
+ Value : float64 (m .Value ()),
20
+ })
21
+ }
22
+ return collected
23
+ }
24
+
25
+ func asMetricType (typ clientmetric.Type ) agentsdk.AgentMetricType {
26
+ switch typ {
27
+ case clientmetric .TypeGauge :
28
+ return agentsdk .AgentMetricTypeGauge
29
+ case clientmetric .TypeCounter :
30
+ return agentsdk .AgentMetricTypeCounter
31
+ default :
32
+ panic (fmt .Sprintf ("unknown metric type: %d" , typ ))
33
+ }
34
+ }
Original file line number Diff line number Diff line change @@ -488,10 +488,17 @@ type Stats struct {
488
488
Metrics []AgentMetric `json:"metrics"`
489
489
}
490
490
491
+ type AgentMetricType string
492
+
493
+ const (
494
+ AgentMetricTypeCounter AgentMetricType = "counter"
495
+ AgentMetricTypeGauge AgentMetricType = "gauge"
496
+ )
497
+
491
498
type AgentMetric struct {
492
- Name string `json:"name"`
493
- Type string `json:"type"`
494
- Value float64 `json:"value"`
499
+ Name string `json:"name" validate:"required "`
500
+ Type AgentMetricType `json:"type" validate:"required" enums:"counter,gauge "`
501
+ Value float64 `json:"value" validate:"required "`
495
502
}
496
503
497
504
type StatsResponse struct {
You can’t perform that action at this time.
0 commit comments