(ctx context.Context)
| 63 | } |
| 64 | |
| 65 | func (a *agent) collectMetrics(ctx context.Context) []*proto.Stats_Metric { |
| 66 | var collected []*proto.Stats_Metric |
| 67 | |
| 68 | // Tailscale internal metrics |
| 69 | metrics := clientmetric.Metrics() |
| 70 | for _, m := range metrics { |
| 71 | if isIgnoredMetric(m.Name()) { |
| 72 | continue |
| 73 | } |
| 74 | |
| 75 | collected = append(collected, &proto.Stats_Metric{ |
| 76 | Name: m.Name(), |
| 77 | Type: asMetricType(m.Type()), |
| 78 | Value: float64(m.Value()), |
| 79 | }) |
| 80 | } |
| 81 | |
| 82 | metricFamilies, err := a.prometheusRegistry.Gather() |
| 83 | if err != nil { |
| 84 | a.logger.Error(ctx, "can't gather agent metrics", slog.Error(err)) |
| 85 | return collected |
| 86 | } |
| 87 | |
| 88 | for _, metricFamily := range metricFamilies { |
| 89 | for _, metric := range metricFamily.GetMetric() { |
| 90 | labels := toAgentMetricLabels(metric.Label) |
| 91 | |
| 92 | switch { |
| 93 | case metric.Counter != nil: |
| 94 | collected = append(collected, &proto.Stats_Metric{ |
| 95 | Name: metricFamily.GetName(), |
| 96 | Type: proto.Stats_Metric_COUNTER, |
| 97 | Value: metric.Counter.GetValue(), |
| 98 | Labels: labels, |
| 99 | }) |
| 100 | case metric.Gauge != nil: |
| 101 | collected = append(collected, &proto.Stats_Metric{ |
| 102 | Name: metricFamily.GetName(), |
| 103 | Type: proto.Stats_Metric_GAUGE, |
| 104 | Value: metric.Gauge.GetValue(), |
| 105 | Labels: labels, |
| 106 | }) |
| 107 | default: |
| 108 | a.logger.Error(ctx, "unsupported metric type", slog.F("type", metricFamily.Type.String())) |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | return collected |
| 113 | } |
| 114 | |
| 115 | func toAgentMetricLabels(metricLabels []*prompb.LabelPair) []*proto.Stats_Metric_Label { |
| 116 | if len(metricLabels) == 0 { |
no test coverage detected