2023-08-16 01:40:00 +00:00
|
|
|
package lightpush
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/libp2p/go-libp2p/p2p/metricshelper"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
var lightpushMessages = prometheus.NewCounter(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Name: "waku_lightpush_messages",
|
|
|
|
Help: "The number of messages sent via lightpush protocol",
|
|
|
|
})
|
|
|
|
|
|
|
|
var lightpushErrors = prometheus.NewCounterVec(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Name: "waku_lightpush_errors",
|
|
|
|
Help: "The distribution of the lightpush protocol errors",
|
|
|
|
},
|
|
|
|
[]string{"error_type"},
|
|
|
|
)
|
|
|
|
|
|
|
|
var collectors = []prometheus.Collector{
|
|
|
|
lightpushMessages,
|
|
|
|
lightpushErrors,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Metrics exposes the functions required to update prometheus metrics for lightpush protocol
|
|
|
|
type Metrics interface {
|
|
|
|
RecordMessage()
|
|
|
|
RecordError(err metricsErrCategory)
|
|
|
|
}
|
|
|
|
|
|
|
|
type metricsImpl struct {
|
|
|
|
reg prometheus.Registerer
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMetrics(reg prometheus.Registerer) Metrics {
|
|
|
|
metricshelper.RegisterCollectors(reg, collectors...)
|
|
|
|
return &metricsImpl{
|
|
|
|
reg: reg,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RecordMessage is used to increase the counter for the number of messages received via waku lightpush
|
|
|
|
func (m *metricsImpl) RecordMessage() {
|
|
|
|
lightpushMessages.Inc()
|
|
|
|
}
|
|
|
|
|
|
|
|
type metricsErrCategory string
|
|
|
|
|
|
|
|
var (
|
2023-10-24 16:26:02 +00:00
|
|
|
decodeRPCFailure metricsErrCategory = "decode_rpc_failure"
|
|
|
|
writeRequestFailure metricsErrCategory = "write_request_failure"
|
|
|
|
writeResponseFailure metricsErrCategory = "write_response_failure"
|
|
|
|
dialFailure metricsErrCategory = "dial_failure"
|
2024-02-05 12:53:15 +00:00
|
|
|
rateLimitFailure metricsErrCategory = "ratelimit_failure"
|
2023-10-24 16:26:02 +00:00
|
|
|
messagePushFailure metricsErrCategory = "message_push_failure"
|
|
|
|
requestBodyFailure metricsErrCategory = "request_failure"
|
|
|
|
responseBodyFailure metricsErrCategory = "response_body_failure"
|
|
|
|
peerNotFoundFailure metricsErrCategory = "peer_not_found_failure"
|
2023-08-16 01:40:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// RecordError increases the counter for different error types
|
|
|
|
func (m *metricsImpl) RecordError(err metricsErrCategory) {
|
|
|
|
lightpushErrors.WithLabelValues(string(err)).Inc()
|
|
|
|
}
|