diff --git a/context/amf_ran.go b/context/amf_ran.go index 9951be73..b0d34352 100644 --- a/context/amf_ran.go +++ b/context/amf_ran.go @@ -90,6 +90,12 @@ func (ran *AmfRan) Remove() { } } else { AMF_Self().DeleteAmfRan(ran.Conn) + count := 0 + AMF_Self().AmfRanPool.Range(func(key, value interface{}) bool { + count++ + return true + }) + metrics.SetNoOfActiveGnbStats(uint64(count)) } } diff --git a/context/amf_ue.go b/context/amf_ue.go index 4148aa2a..5103d84a 100644 --- a/context/amf_ue.go +++ b/context/amf_ue.go @@ -502,6 +502,12 @@ func (ue *AmfUe) Remove() { if len(ue.Supi) > 0 { AMF_Self().UePool.Delete(ue.Supi) + count := 0 + AMF_Self().UePool.Range(func(key, value interface{}) bool { + count++ + return true + }) + metrics.SetNoOfActiveSubStats(uint64(count)) } if ue.EventChannel != nil { ue.EventChannel.Event <- "quit" diff --git a/gmm/handler.go b/gmm/handler.go index 06111d41..88508d00 100644 --- a/gmm/handler.go +++ b/gmm/handler.go @@ -767,6 +767,12 @@ func HandleInitialRegistration(ue *context.AmfUe, anType models.AccessType) erro gmm_message.SendRegistrationAccept(ue, anType, nil, nil, nil, nil, nil) metrics.IncrementUeRegStats(context.AMF_Self().NfId, "success") metrics.SetNoOfUeConnectionStats(context.AMF_Self().NfId, ue.Suci, ue.Guti, 1) + count := 0 + context.AMF_Self().UePool.Range(func(key, value interface{}) bool { + count++ + return true + }) + metrics.SetNoOfActiveSubStats(uint64(count)) } else { // TS 23.502 4.12.2.2 10a ~ 13: if non-3gpp, AMF should send initial context setup request to N3IWF first, // and send registration accept after receiving initial context setup response @@ -1636,6 +1642,7 @@ func AuthenticationProcedure(ue *context.AmfUe, accessType models.AccessType) (b } ue.GmmLog.Infoln("ngKSI after 5G-AKA:", ue.NgKsi.Ksi) gmm_message.SendAuthenticationRequest(ue.RanUe[accessType]) + metrics.IncrementAuthReqStats(ue.Suci) return false, nil } diff --git a/metrics/telemetry.go b/metrics/telemetry.go index 72de6b9f..d321d62d 100644 --- a/metrics/telemetry.go +++ b/metrics/telemetry.go @@ -33,7 +33,10 @@ type AmfStats struct { n2HandoverFail *prometheus.CounterVec nfNonReachable *prometheus.CounterVec noOfUeConnect *prometheus.GaugeVec - noOfGnbConnect *prometheus.GaugeVec + noOfActiveSub prometheus.Gauge + noOfActiveGnb prometheus.Gauge + gnbConnect *prometheus.CounterVec + AuthRequestTotal *prometheus.CounterVec } var amfStats *AmfStats @@ -100,10 +103,25 @@ func initAmfStats() *AmfStats { Help: "UE connections total", }, []string{"id", "supi", "guti"}), - noOfGnbConnect: prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Name: "gnb_connected_total", - Help: "GNB connections total", - }, []string{"id", "gnb_id", "gnb_ip"}), + noOfActiveSub: prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "amf_active_subscribers", + Help: "current number of active subscribers in the core", + }), + + noOfActiveGnb: prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "amf_active_gnb", + Help: "current number of active gNB's in the core", + }), + + gnbConnect: prometheus.NewCounterVec(prometheus.CounterOpts{ + Name: "amf_gnb_connected_total", + Help: "Counter of total gNB connections", + }, []string{"gnb_id", "gnb_ip", "name"}), + + AuthRequestTotal: prometheus.NewCounterVec(prometheus.CounterOpts{ + Name: "amf_auth_request_total", + Help: "Counter of total authentication request send", + }, []string{"supi"}), } } @@ -146,7 +164,16 @@ func (ps *AmfStats) register() error { if err := prometheus.Register(ps.noOfUeConnect); err != nil { return err } - if err := prometheus.Register(ps.noOfGnbConnect); err != nil { + if err := prometheus.Register(ps.noOfActiveSub); err != nil { + return err + } + if err := prometheus.Register(ps.noOfActiveGnb); err != nil { + return err + } + if err := prometheus.Register(ps.gnbConnect); err != nil { + return err + } + if err := prometheus.Register(ps.AuthRequestTotal); err != nil { return err } return nil @@ -228,7 +255,22 @@ func SetNoOfUeConnectionStats(id, suci, guti string, count uint64) { amfStats.noOfUeConnect.WithLabelValues(id, suci, guti).Set(float64(count)) } -// SetNoOfGnbConnectionStats maintains total gNB connections info -func SetNoOfGnbConnectionStats(id, gnbid, gnbip string, count uint64) { - amfStats.noOfGnbConnect.WithLabelValues(id, gnbid, gnbip).Set(float64(count)) +// SetNoOfActiveSubStats maintains total active subscribers info +func SetNoOfActiveSubStats(count uint64) { + amfStats.noOfActiveSub.Set(float64(count)) +} + +// SetNoOfActiveGnbStats maintains total active subscribers info +func SetNoOfActiveGnbStats(count uint64) { + amfStats.noOfActiveGnb.Set(float64(count)) +} + +// IncrementGnbConnStats maintains gnb connection level stats +func IncrementGnbConnStats(gnbid, gnbip, name string) { + amfStats.gnbConnect.WithLabelValues(gnbid, gnbip, name).Inc() +} + +// IncrementAuthReqStats maintains gnb connection level stats +func IncrementAuthReqStats(supi string) { + amfStats.AuthRequestTotal.WithLabelValues(supi).Inc() } diff --git a/ngap/handler.go b/ngap/handler.go index 5655a9cd..d604b9c3 100644 --- a/ngap/handler.go +++ b/ngap/handler.go @@ -795,7 +795,13 @@ func HandleNGSetupRequest(ran *context.AmfRan, message *ngapType.NGAPPDU) { } if cause.Present == ngapType.CausePresentNothing { ngap_message.SendNGSetupResponse(ran) - metrics.SetNoOfGnbConnectionStats(context.AMF_Self().NfId, ran.GnbId, ran.GnbIp, 1) + count := 0 + context.AMF_Self().AmfRanPool.Range(func(key, value interface{}) bool { + count++ + return true + }) + metrics.SetNoOfActiveGnbStats(uint64(count)) + metrics.IncrementGnbConnStats(ran.GnbId, ran.GnbIp, ran.Name) // send nf(gnb) status notification gnbStatus := mi.MetricEvent{ EventType: mi.CNfStatusEvt, @@ -812,7 +818,6 @@ func HandleNGSetupRequest(ran *context.AmfRan, message *ngapType.NGAPPDU) { } } else { ngap_message.SendNGSetupFailure(ran, cause) - metrics.SetNoOfGnbConnectionStats(context.AMF_Self().NfId, ran.GnbId, ran.GnbIp, 0) } }