@@ -9,28 +9,59 @@ import (
99)
1010
1111const (
12- namespace = "cloudflared"
13- subsystem = "udp"
12+ namespace = "cloudflared"
13+ subsystem_udp = "udp"
14+ subsystem_icmp = "icmp"
1415
1516 commandMetricLabel = "command"
17+ reasonMetricLabel = "reason"
1618)
1719
20+ type DroppedReason int
21+
22+ const (
23+ DroppedWriteFailed DroppedReason = iota
24+ DroppedWriteDeadlineExceeded
25+ DroppedWriteFull
26+ DroppedWriteFlowUnknown
27+ DroppedReadFailed
28+ // Origin payloads that are too large to proxy.
29+ DroppedReadTooLarge
30+ )
31+
32+ var droppedReason = map [DroppedReason ]string {
33+ DroppedWriteFailed : "write_failed" ,
34+ DroppedWriteDeadlineExceeded : "write_deadline_exceeded" ,
35+ DroppedWriteFull : "write_full" ,
36+ DroppedWriteFlowUnknown : "write_flow_unknown" ,
37+ DroppedReadFailed : "read_failed" ,
38+ DroppedReadTooLarge : "read_too_large" ,
39+ }
40+
41+ func (dr DroppedReason ) String () string {
42+ return droppedReason [dr ]
43+ }
44+
1845type Metrics interface {
1946 IncrementFlows (connIndex uint8 )
2047 DecrementFlows (connIndex uint8 )
21- PayloadTooLarge (connIndex uint8 )
48+ FailedFlow (connIndex uint8 )
2249 RetryFlowResponse (connIndex uint8 )
2350 MigrateFlow (connIndex uint8 )
2451 UnsupportedRemoteCommand (connIndex uint8 , command string )
52+ DroppedUDPDatagram (connIndex uint8 , reason DroppedReason )
53+ DroppedICMPPackets (connIndex uint8 , reason DroppedReason )
2554}
2655
2756type metrics struct {
2857 activeUDPFlows * prometheus.GaugeVec
2958 totalUDPFlows * prometheus.CounterVec
30- payloadTooLarge * prometheus.CounterVec
3159 retryFlowResponses * prometheus.CounterVec
3260 migratedFlows * prometheus.CounterVec
3361 unsupportedRemoteCommands * prometheus.CounterVec
62+ droppedUDPDatagrams * prometheus.CounterVec
63+ droppedICMPPackets * prometheus.CounterVec
64+ failedFlows * prometheus.CounterVec
3465}
3566
3667func (m * metrics ) IncrementFlows (connIndex uint8 ) {
@@ -42,8 +73,8 @@ func (m *metrics) DecrementFlows(connIndex uint8) {
4273 m .activeUDPFlows .WithLabelValues (fmt .Sprintf ("%d" , connIndex )).Dec ()
4374}
4475
45- func (m * metrics ) PayloadTooLarge (connIndex uint8 ) {
46- m .payloadTooLarge .WithLabelValues (fmt .Sprintf ("%d" , connIndex )).Inc ()
76+ func (m * metrics ) FailedFlow (connIndex uint8 ) {
77+ m .failedFlows .WithLabelValues (fmt .Sprintf ("%d" , connIndex )).Inc ()
4778}
4879
4980func (m * metrics ) RetryFlowResponse (connIndex uint8 ) {
@@ -58,52 +89,74 @@ func (m *metrics) UnsupportedRemoteCommand(connIndex uint8, command string) {
5889 m .unsupportedRemoteCommands .WithLabelValues (fmt .Sprintf ("%d" , connIndex ), command ).Inc ()
5990}
6091
92+ func (m * metrics ) DroppedUDPDatagram (connIndex uint8 , reason DroppedReason ) {
93+ m .droppedUDPDatagrams .WithLabelValues (fmt .Sprintf ("%d" , connIndex ), reason .String ()).Inc ()
94+ }
95+
96+ func (m * metrics ) DroppedICMPPackets (connIndex uint8 , reason DroppedReason ) {
97+ m .droppedICMPPackets .WithLabelValues (fmt .Sprintf ("%d" , connIndex ), reason .String ()).Inc ()
98+ }
99+
61100func NewMetrics (registerer prometheus.Registerer ) Metrics {
62101 m := & metrics {
63102 activeUDPFlows : prometheus .NewGaugeVec (prometheus.GaugeOpts {
64103 Namespace : namespace ,
65- Subsystem : subsystem ,
104+ Subsystem : subsystem_udp ,
66105 Name : "active_flows" ,
67106 Help : "Concurrent count of UDP flows that are being proxied to any origin" ,
68107 }, []string {quic .ConnectionIndexMetricLabel }),
69108 totalUDPFlows : prometheus .NewCounterVec (prometheus.CounterOpts { //nolint:promlinter
70109 Namespace : namespace ,
71- Subsystem : subsystem ,
110+ Subsystem : subsystem_udp ,
72111 Name : "total_flows" ,
73112 Help : "Total count of UDP flows that have been proxied to any origin" ,
74113 }, []string {quic .ConnectionIndexMetricLabel }),
75- payloadTooLarge : prometheus .NewCounterVec (prometheus.CounterOpts { //nolint:promlinter
114+ failedFlows : prometheus .NewCounterVec (prometheus.CounterOpts { //nolint:promlinter
76115 Namespace : namespace ,
77- Subsystem : subsystem ,
78- Name : "payload_too_large " ,
79- Help : "Total count of UDP flows that have had origin payloads that are too large to proxy " ,
116+ Subsystem : subsystem_udp ,
117+ Name : "failed_flows " ,
118+ Help : "Total count of flows that errored and closed " ,
80119 }, []string {quic .ConnectionIndexMetricLabel }),
81120 retryFlowResponses : prometheus .NewCounterVec (prometheus.CounterOpts { //nolint:promlinter
82121 Namespace : namespace ,
83- Subsystem : subsystem ,
122+ Subsystem : subsystem_udp ,
84123 Name : "retry_flow_responses" ,
85124 Help : "Total count of UDP flows that have had to send their registration response more than once" ,
86125 }, []string {quic .ConnectionIndexMetricLabel }),
87126 migratedFlows : prometheus .NewCounterVec (prometheus.CounterOpts { //nolint:promlinter
88127 Namespace : namespace ,
89- Subsystem : subsystem ,
128+ Subsystem : subsystem_udp ,
90129 Name : "migrated_flows" ,
91130 Help : "Total count of UDP flows have been migrated across local connections" ,
92131 }, []string {quic .ConnectionIndexMetricLabel }),
93- unsupportedRemoteCommands : prometheus .NewCounterVec (prometheus.CounterOpts {
132+ unsupportedRemoteCommands : prometheus .NewCounterVec (prometheus.CounterOpts { //nolint:promlinter
94133 Namespace : namespace ,
95- Subsystem : subsystem ,
134+ Subsystem : subsystem_udp ,
96135 Name : "unsupported_remote_command_total" ,
97- Help : "Total count of unsupported remote RPC commands for the " ,
136+ Help : "Total count of unsupported remote RPC commands called " ,
98137 }, []string {quic .ConnectionIndexMetricLabel , commandMetricLabel }),
138+ droppedUDPDatagrams : prometheus .NewCounterVec (prometheus.CounterOpts { //nolint:promlinter
139+ Namespace : namespace ,
140+ Subsystem : subsystem_udp ,
141+ Name : "dropped_datagrams" ,
142+ Help : "Total count of UDP dropped datagrams" ,
143+ }, []string {quic .ConnectionIndexMetricLabel , reasonMetricLabel }),
144+ droppedICMPPackets : prometheus .NewCounterVec (prometheus.CounterOpts { //nolint:promlinter
145+ Namespace : namespace ,
146+ Subsystem : subsystem_icmp ,
147+ Name : "dropped_packets" ,
148+ Help : "Total count of ICMP dropped datagrams" ,
149+ }, []string {quic .ConnectionIndexMetricLabel , reasonMetricLabel }),
99150 }
100151 registerer .MustRegister (
101152 m .activeUDPFlows ,
102153 m .totalUDPFlows ,
103- m .payloadTooLarge ,
154+ m .failedFlows ,
104155 m .retryFlowResponses ,
105156 m .migratedFlows ,
106157 m .unsupportedRemoteCommands ,
158+ m .droppedUDPDatagrams ,
159+ m .droppedICMPPackets ,
107160 )
108161 return m
109162}
0 commit comments