Skip to content

Conversation

@Niahh
Copy link
Contributor

@Niahh Niahh commented Jul 10, 2025

This PR introduces Prometheus-compatible metrics to the NRF to support observability and performance monitoring in Free5GC deployments.

Key Features

  • SBI Metrics: Track inbound/outbound HTTP requests on the Service-Based Interface (SBI) with counters and latency histograms.
  • Built-in Metric Server: Exposes a /metrics HTTP endpoint that is configurable and compatible with Prometheus scraping.
  • Modular Design: Metrics logic is isolated in a dedicated metrics package in the Util project to minimize code coupling and simplify reuse across NFs.
  • No External Dependencies: Uses the official Prometheus Go client library only — no sidecars or exporters required.

Motivation

Introducing native metrics is a foundational step toward:

  • Understanding real-time behavior of the NRF
  • Coupled with testing tools such as PacketRusher, it can help with debugging some scenarios.
  • Integrating Free5GC into production-grade observability stacks (e.g., Prometheus + Grafana)

Configuration

The metrics server is disabled by default. To enable, add the proper section :

# Metrics configuration
# If using the same bindingIPv4 as the sbi server, make sure that the ports are different
metrics:
	enable: true # (Optional, default false)
	scheme: http # (Required) the protocol for metrics (http or https, default https)
	bindingIPv4: 127.0.0.18 # (Required) IP used to bind the metrics endpoint (default 0.0.0.0)
	port: 9091 # (Optional, default 9091) port used to bind the service
	tls: # (Optional) the local path of TLS key (Could be the same as the sbi ones)
		pem: /home/sam/private-network/code/free5gc/cert/NRF.pem # NRF TLS Certificate
		key: /home/sam/private-network/code/free5gc/cert/NRF.key # NRF TLS Private key
	namespace: free5gc # (Optional, default free5gc)

Backward Compatibility

100% backward compatible – metrics support is optional and deactivated until activated by the user.

Integration

The same metrics architecture is being adapted across other Free5GC NFs (AUSF, AMF, SMF , etc.) to ensure consistency and maintainability.

This work is sponsored by Free Mobile!

@Niahh
Copy link
Contributor Author

Niahh commented Jul 11, 2025

Working on aliging the PR with all the errors/warning from golangci-lint and taking the latest change of upgrad_cli_to_v2

@senselessDog
Copy link
Contributor

@Alonza0314 @ianchen0119 This PR can be merged.

@Niahh Niahh force-pushed the add-metrics branch 2 times, most recently from 16316b8 to 9791b78 Compare July 31, 2025 09:07
Alonza0314
Alonza0314 previously approved these changes Aug 1, 2025
Copy link
Member

@Alonza0314 Alonza0314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Alonza0314 Alonza0314 dismissed their stale review August 1, 2025 09:37

lint error

@ianchen0119
Copy link
Contributor

@Niahh

Would you please help fix the linter error?

Thank you!

@ianchen0119 ianchen0119 self-requested a review August 4, 2025 08:45
@Alonza0314
Copy link
Member

The check errors also exist at tngf and udm.

@Niahh
Copy link
Contributor Author

Niahh commented Aug 5, 2025

@Niahh

Would you please help fix the linter error?

Thank you!

Hi @ianchen0119, @Alonza0314

Sure thing ! Sorry I missed the nrf in my round of check for the lint errors !

@ianchen0119 ianchen0119 merged commit cc1ce6e into free5gc:main Aug 5, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants