Cloud Native 5 min read

Automate Prometheus Service Discovery with Nacos: A Step‑by‑Step Guide

Learn how to replace static Prometheus target files with dynamic service discovery by integrating Alibaba’s open‑source Nacos registry, configuring a Go‑based adapter, adding HTTP‑SD configs to the Prometheus Operator, and validating the automated monitoring of large‑scale microservice deployments.

Linux Ops Smart Journey
Linux Ops Smart Journey
Linux Ops Smart Journey
Automate Prometheus Service Discovery with Nacos: A Step‑by‑Step Guide

In microservice architectures with dozens or hundreds of instances, static Prometheus target files become impractical. This guide shows how to use Alibaba’s open‑source Nacos as a dynamic service registry and combine it with Prometheus automatic discovery.

Deploy Nacos Adapter for Monitoring

1. Create the adapter’s configuration file (config.yaml) with system, logger, and Nacos connection settings.

system:
  port: 8090

logger:
  output: console
  level: info

nacos:
  address: 172.139.20.100
  port: 8848
  context_path: /nacos
  namespace_id: 46f891fb-c1a2-4b67-a0cb-b9d3888ac9be
  username: mon_admin
  password: 123456

2. Start the adapter:

$ ./nacos-monitor-discovery -c config.yaml
{ "time":"2025-07-06 17:08:57.3407","level":"INFO","source":"app/run.go:68","msg":"service prepare listen port :8090"}
{ "time":"2025-07-06 17:09:34.5224","level":"INFO","source":"app/run.go:35","msg":"Received request","Proto":"HTTP/1.1","Method":"GET","URL":"/actuator/prometheus"}
{ "time":"2025-07-06 17:09:34.6910","level":"INFO","source":"app/run.go:50","msg":"Request response","Proto":"HTTP/1.1","Code":200,"Method":"GET","URL":"/actuator/prometheus","RemoteAddr":"172.139.20.175:12629","cost":"168.629233ms","UserAgent":"Prometheus/2.46.0"}

Add Static Scrape Config to Prometheus Operator

Create a Prometheus additional scrape configuration file that uses HTTP‑SD to pull targets from the adapter.

$ cat prometheus-additional.yml
- job_name: nacos
  http_sd_configs:
  - url: http://172.139.20.170:8090/actuator/prometheus
  relabel_configs:
  - source_labels: [__meta_nacos_service_name]
    target_label: job
  - source_labels: [__meta_nacos_metadata_metrics_path]
    regex: (.+)
    target_label: __metrics_path__
    replacement: $1

Store the file as a Kubernetes secret and reference it in the Prometheus custom resource:

$ kubectl -n obs-system create secret generic additional-scrape-configs --from-file prometheus-additional.yml
secret/additional-scrape-configs created

$ k -n obs-system edit prometheus monitor
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  name: monitor
  namespace: obs-system
spec:
  additionalScrapeConfigs:
    key: redis.yaml
    name: additional-scrape-configs
    ...

Validate Collection

Check the Prometheus UI for the new Nacos targets and query the exported metrics to confirm successful discovery.

Conclusion

By integrating Nacos with Prometheus, service discovery becomes fully automated, reducing operational overhead and providing reliable monitoring for large‑scale microservice deployments.

service discoveryNacosPrometheus
Linux Ops Smart Journey
Written by

Linux Ops Smart Journey

The operations journey never stops—pursuing excellence endlessly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.