2022-02-07 09:42:07 +00:00
|
|
|
package proxy
|
2018-05-01 23:45:06 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2021-03-23 14:30:43 +00:00
|
|
|
|
|
|
|
"github.com/cloudflare/cloudflared/connection"
|
2018-05-01 23:45:06 +00:00
|
|
|
)
|
|
|
|
|
2020-10-08 10:12:26 +00:00
|
|
|
// Metrics uses connection.MetricsNamespace(aka cloudflared) as namespace and connection.TunnelSubsystem
|
|
|
|
// (tunnel) as subsystem to keep them consistent with the previous qualifier.
|
2018-05-01 23:45:06 +00:00
|
|
|
|
2020-10-08 10:12:26 +00:00
|
|
|
var (
|
|
|
|
totalRequests = prometheus.NewCounter(
|
2018-05-01 23:45:06 +00:00
|
|
|
prometheus.CounterOpts{
|
2020-10-08 10:12:26 +00:00
|
|
|
Namespace: connection.MetricsNamespace,
|
|
|
|
Subsystem: connection.TunnelSubsystem,
|
2019-11-05 20:37:40 +00:00
|
|
|
Name: "total_requests",
|
|
|
|
Help: "Amount of requests proxied through all the tunnels",
|
2018-05-01 23:45:06 +00:00
|
|
|
},
|
|
|
|
)
|
2020-10-08 10:12:26 +00:00
|
|
|
concurrentRequests = prometheus.NewGauge(
|
2018-05-01 23:45:06 +00:00
|
|
|
prometheus.GaugeOpts{
|
2020-10-08 10:12:26 +00:00
|
|
|
Namespace: connection.MetricsNamespace,
|
|
|
|
Subsystem: connection.TunnelSubsystem,
|
2019-11-05 20:37:40 +00:00
|
|
|
Name: "concurrent_requests_per_tunnel",
|
|
|
|
Help: "Concurrent requests proxied through each tunnel",
|
2018-05-01 23:45:06 +00:00
|
|
|
},
|
|
|
|
)
|
2020-10-08 10:12:26 +00:00
|
|
|
responseByCode = prometheus.NewCounterVec(
|
2018-05-01 23:45:06 +00:00
|
|
|
prometheus.CounterOpts{
|
2020-10-08 10:12:26 +00:00
|
|
|
Namespace: connection.MetricsNamespace,
|
|
|
|
Subsystem: connection.TunnelSubsystem,
|
2019-11-05 20:37:40 +00:00
|
|
|
Name: "response_by_code",
|
|
|
|
Help: "Count of responses by HTTP status code",
|
2018-05-01 23:45:06 +00:00
|
|
|
},
|
|
|
|
[]string{"status_code"},
|
|
|
|
)
|
2020-11-02 11:21:34 +00:00
|
|
|
requestErrors = prometheus.NewCounter(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: connection.MetricsNamespace,
|
|
|
|
Subsystem: connection.TunnelSubsystem,
|
|
|
|
Name: "request_errors",
|
|
|
|
Help: "Count of error proxying to origin",
|
|
|
|
},
|
|
|
|
)
|
2023-06-17 00:07:56 +00:00
|
|
|
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",
|
|
|
|
},
|
|
|
|
)
|
2024-02-07 14:32:39 +00:00
|
|
|
connectLatency = prometheus.NewHistogram(
|
|
|
|
prometheus.HistogramOpts{
|
|
|
|
Namespace: connection.MetricsNamespace,
|
|
|
|
Subsystem: "proxy",
|
|
|
|
Name: "connect_latency",
|
|
|
|
Help: "Time it takes to establish and acknowledge connections in milliseconds",
|
|
|
|
Buckets: []float64{1, 10, 25, 50, 100, 500, 1000, 5000},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
connectStreamErrors = prometheus.NewCounter(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: connection.MetricsNamespace,
|
|
|
|
Subsystem: "proxy",
|
|
|
|
Name: "connect_streams_errors",
|
|
|
|
Help: "Total count of failure to establish and acknowledge connections",
|
|
|
|
},
|
|
|
|
)
|
2020-10-08 10:12:26 +00:00
|
|
|
)
|
2019-04-16 20:26:31 +00:00
|
|
|
|
2020-10-08 10:12:26 +00:00
|
|
|
func init() {
|
|
|
|
prometheus.MustRegister(
|
|
|
|
totalRequests,
|
|
|
|
concurrentRequests,
|
|
|
|
responseByCode,
|
2020-11-02 11:21:34 +00:00
|
|
|
requestErrors,
|
2023-06-17 00:07:56 +00:00
|
|
|
activeTCPSessions,
|
|
|
|
totalTCPSessions,
|
2024-02-07 14:32:39 +00:00
|
|
|
connectLatency,
|
|
|
|
connectStreamErrors,
|
2020-01-28 16:43:37 +00:00
|
|
|
)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 10:12:26 +00:00
|
|
|
func incrementRequests() {
|
|
|
|
totalRequests.Inc()
|
|
|
|
concurrentRequests.Inc()
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 10:12:26 +00:00
|
|
|
func decrementConcurrentRequests() {
|
|
|
|
concurrentRequests.Dec()
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2023-06-17 00:07:56 +00:00
|
|
|
|
|
|
|
func incrementTCPRequests() {
|
|
|
|
incrementRequests()
|
|
|
|
totalTCPSessions.Inc()
|
|
|
|
activeTCPSessions.Inc()
|
|
|
|
}
|
|
|
|
|
|
|
|
func decrementTCPConcurrentRequests() {
|
|
|
|
decrementConcurrentRequests()
|
|
|
|
activeTCPSessions.Dec()
|
|
|
|
}
|