fix: 接线 Prometheus 指标到连接与投递事件
This commit is contained in:
@@ -190,6 +190,7 @@ func (h *nixHook) OnSessionEstablished(cl *mqtt.Client, _ packets.Packet) {
|
||||
MaxPacketSize: st.maxPacketSize,
|
||||
}
|
||||
_ = h.b.uplink.OnSessionEstablished(context.Background(), info)
|
||||
h.noteConnectionOpen(st)
|
||||
}
|
||||
|
||||
func (h *nixHook) OnDisconnect(cl *mqtt.Client, err error, _ bool) {
|
||||
@@ -229,9 +230,27 @@ func (h *nixHook) OnDisconnect(cl *mqtt.Client, err error, _ bool) {
|
||||
}
|
||||
if sess, ok := h.b.uplink.(*Session); ok {
|
||||
sess.HandleDisconnect(context.Background(), info, reason, isCurrent)
|
||||
h.noteConnectionClose(st)
|
||||
return
|
||||
}
|
||||
h.b.uplink.OnDisconnect(context.Background(), info, reason)
|
||||
h.noteConnectionClose(st)
|
||||
}
|
||||
|
||||
func (h *nixHook) noteConnectionOpen(st *connState) {
|
||||
if h.b.metrics == nil || st == nil || st.metricsCounted {
|
||||
return
|
||||
}
|
||||
h.b.metrics.Connections.WithLabelValues(string(st.transport)).Inc()
|
||||
st.metricsCounted = true
|
||||
}
|
||||
|
||||
func (h *nixHook) noteConnectionClose(st *connState) {
|
||||
if h.b.metrics == nil || st == nil || !st.metricsCounted {
|
||||
return
|
||||
}
|
||||
h.b.metrics.Connections.WithLabelValues(string(st.transport)).Dec()
|
||||
st.metricsCounted = false
|
||||
}
|
||||
|
||||
func (h *nixHook) OnQosComplete(cl *mqtt.Client, pk packets.Packet) {
|
||||
|
||||
Reference in New Issue
Block a user