2024-08-08 22:28:46 +08:00
|
|
|
package common
|
|
|
|
|
2024-08-19 21:58:14 +08:00
|
|
|
import (
|
2024-08-30 05:40:52 +08:00
|
|
|
"bbb-graphql-middleware/config"
|
2024-08-19 21:58:14 +08:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
2024-08-30 05:40:52 +08:00
|
|
|
var PrometheusAdvancedMetricsEnabled = config.GetConfig().PrometheusAdvancedMetricsEnabled
|
2024-08-08 22:28:46 +08:00
|
|
|
|
|
|
|
var (
|
|
|
|
HttpConnectionGauge = prometheus.NewGauge(prometheus.GaugeOpts{
|
|
|
|
Name: "http_connection_active",
|
|
|
|
Help: "Number of active HTTP connections",
|
|
|
|
})
|
|
|
|
HttpConnectionCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
|
|
|
Name: "http_connection_total",
|
|
|
|
Help: "Total number of HTTP connections",
|
|
|
|
})
|
|
|
|
WsConnectionAcceptedCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
|
|
|
Name: "ws_connection_accepted",
|
|
|
|
Help: "Total number of Websocket connections accepted",
|
|
|
|
})
|
|
|
|
WsConnectionRejectedCounter = prometheus.NewCounterVec(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Name: "ws_connection_rejected",
|
|
|
|
Help: "Total number of Websocket connections rejected",
|
|
|
|
},
|
|
|
|
[]string{"reason"},
|
|
|
|
)
|
2024-08-19 21:58:14 +08:00
|
|
|
GqlSubscribeCounter = prometheus.NewCounterVec(
|
2024-08-08 22:28:46 +08:00
|
|
|
prometheus.CounterOpts{
|
|
|
|
Name: "gql_subscription_total",
|
|
|
|
Help: "Total number of Graphql subscriptions",
|
|
|
|
},
|
2024-08-19 21:58:14 +08:00
|
|
|
[]string{"type", "operationName"},
|
2024-08-08 22:28:46 +08:00
|
|
|
)
|
2024-08-19 21:58:14 +08:00
|
|
|
GqlMutationsCounter = prometheus.NewCounterVec(
|
2024-08-08 22:28:46 +08:00
|
|
|
prometheus.CounterOpts{
|
2024-08-19 21:58:14 +08:00
|
|
|
Name: "gql_mutation_total",
|
|
|
|
Help: "Total number of Graphql mutations",
|
2024-08-08 22:28:46 +08:00
|
|
|
},
|
|
|
|
[]string{"operationName"},
|
|
|
|
)
|
2024-08-19 21:58:14 +08:00
|
|
|
GqlReceivedDataCounter = prometheus.NewCounterVec(
|
2024-08-08 22:28:46 +08:00
|
|
|
prometheus.CounterOpts{
|
2024-08-19 21:58:14 +08:00
|
|
|
Name: "gql_received_data_total",
|
|
|
|
Help: "Frequency of updates of a given data",
|
2024-08-08 22:28:46 +08:00
|
|
|
},
|
2024-08-19 21:58:14 +08:00
|
|
|
[]string{"type", "operationName"},
|
2024-08-08 22:28:46 +08:00
|
|
|
)
|
2024-08-19 21:58:14 +08:00
|
|
|
GqlReceivedDataPayloadLength = prometheus.NewHistogramVec(
|
|
|
|
prometheus.HistogramOpts{
|
|
|
|
Name: "gql_received_data_payload_length",
|
|
|
|
Help: "Length (number of positions) of received data payload",
|
|
|
|
Buckets: []float64{
|
|
|
|
1,
|
|
|
|
10,
|
|
|
|
50,
|
|
|
|
100,
|
|
|
|
300,
|
|
|
|
600,
|
|
|
|
},
|
2024-08-08 22:28:46 +08:00
|
|
|
},
|
2024-08-19 21:58:14 +08:00
|
|
|
[]string{"type", "operationName"},
|
|
|
|
)
|
|
|
|
GqlReceivedDataPayloadSize = prometheus.NewHistogramVec(
|
|
|
|
prometheus.HistogramOpts{
|
|
|
|
Name: "gql_received_data_payload_size",
|
|
|
|
Help: "Size (in bytes) of received data payload",
|
|
|
|
Buckets: []float64{
|
|
|
|
200,
|
|
|
|
600,
|
|
|
|
1200,
|
|
|
|
5000,
|
|
|
|
10000,
|
|
|
|
30000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]string{"type", "operationName"},
|
2024-08-08 22:28:46 +08:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
prometheus.MustRegister(HttpConnectionGauge)
|
|
|
|
prometheus.MustRegister(HttpConnectionCounter)
|
|
|
|
prometheus.MustRegister(WsConnectionAcceptedCounter)
|
|
|
|
prometheus.MustRegister(WsConnectionRejectedCounter)
|
2024-08-19 21:58:14 +08:00
|
|
|
prometheus.MustRegister(GqlSubscribeCounter)
|
|
|
|
prometheus.MustRegister(GqlReceivedDataCounter)
|
2024-08-08 22:28:46 +08:00
|
|
|
prometheus.MustRegister(GqlMutationsCounter)
|
2024-08-19 21:58:14 +08:00
|
|
|
prometheus.MustRegister(GqlReceivedDataPayloadSize)
|
|
|
|
if PrometheusAdvancedMetricsEnabled {
|
|
|
|
prometheus.MustRegister(GqlReceivedDataPayloadLength)
|
|
|
|
}
|
2024-08-08 22:28:46 +08:00
|
|
|
}
|