TUN-7477: Add UDP/TCP session metrics

New gauge metrics are exposed in the prometheus endpoint to
capture the current and total TCP and UDP sessions that
cloudflared has proxied.
This commit is contained in:
Devin Carr
2023-06-16 17:07:56 -07:00
parent 20e36c5bf3
commit a3bcf25fae
4 changed files with 73 additions and 2 deletions

View File

@@ -43,6 +43,22 @@ var (
Help: "Count of error proxying to origin",
},
)
activeTCPSessions = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: connection.MetricsNamespace,
Subsystem: "tcp",
Name: "active_sessions",
Help: "Concurrent count of TCP sessions that are being proxied to any origin",
},
)
totalTCPSessions = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: connection.MetricsNamespace,
Subsystem: "tcp",
Name: "total_sessions",
Help: "Total count of TCP sessions that have been proxied to any origin",
},
)
)
func init() {
@@ -51,6 +67,8 @@ func init() {
concurrentRequests,
responseByCode,
requestErrors,
activeTCPSessions,
totalTCPSessions,
)
}
@@ -62,3 +80,14 @@ func incrementRequests() {
func decrementConcurrentRequests() {
concurrentRequests.Dec()
}
func incrementTCPRequests() {
incrementRequests()
totalTCPSessions.Inc()
activeTCPSessions.Inc()
}
func decrementTCPConcurrentRequests() {
decrementConcurrentRequests()
activeTCPSessions.Dec()
}