| 23 | } |
| 24 | |
| 25 | func newAgentMetrics(registerer prometheus.Registerer) *agentMetrics { |
| 26 | connectionsTotal := prometheus.NewCounter(prometheus.CounterOpts{ |
| 27 | Namespace: "agent", Subsystem: "reconnecting_pty", Name: "connections_total", |
| 28 | }) |
| 29 | registerer.MustRegister(connectionsTotal) |
| 30 | |
| 31 | reconnectingPTYErrors := prometheus.NewCounterVec( |
| 32 | prometheus.CounterOpts{ |
| 33 | Namespace: "agent", |
| 34 | Subsystem: "reconnecting_pty", |
| 35 | Name: "errors_total", |
| 36 | }, |
| 37 | []string{"error_type"}, |
| 38 | ) |
| 39 | registerer.MustRegister(reconnectingPTYErrors) |
| 40 | |
| 41 | startupScriptSeconds := prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
| 42 | Namespace: "coderd", |
| 43 | Subsystem: "agentstats", |
| 44 | Name: "startup_script_seconds", |
| 45 | Help: "Amount of time taken to run the startup script in seconds.", |
| 46 | }, []string{"success"}) |
| 47 | registerer.MustRegister(startupScriptSeconds) |
| 48 | |
| 49 | currentConnections := prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
| 50 | Namespace: "coderd", |
| 51 | Subsystem: "agentstats", |
| 52 | Name: "currently_reachable_peers", |
| 53 | Help: "The number of peers (e.g. clients) that are currently reachable over the encrypted network.", |
| 54 | }, []string{"connection_type"}) |
| 55 | registerer.MustRegister(currentConnections) |
| 56 | |
| 57 | return &agentMetrics{ |
| 58 | connectionsTotal: connectionsTotal, |
| 59 | reconnectingPTYErrors: reconnectingPTYErrors, |
| 60 | startupScriptSeconds: startupScriptSeconds, |
| 61 | currentConnections: currentConnections, |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | func (a *agent) collectMetrics(ctx context.Context) []*proto.Stats_Metric { |
| 66 | var collected []*proto.Stats_Metric |