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",
|
|
|
|
},
|
|
|
|
)
|
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,
|
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
|
|
|
}
|