> For the complete documentation index, see [llms.txt](https://gitbook.gpg123.vip/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.gpg123.vip/prometheus+nacos-ji-yu-wen-jian-shi-xian-dong-tai-jian-kong-fa-xian/prometheus+nacos-dong-tai-jian-kong-fa-xian.md).

# Prometheus+Nacos动态监控发现

## 准备环境

* [x] 已部署Prometheus
* [x] 已部署Nacos

## 整合步骤

* 创建nacos命名空间，如Prometheus

<figure><img src="/files/uaNf88Up9LhN4nTcONG2" alt=""><figcaption></figcaption></figure>

* 创建一个服务发现配置json文件，例如

```
[
  {
    "targets": [ "server.gpg123.vip:8090" ],
    "labels": {
      "job": "spring-boot-demo",
      "instance": "spring-boot-demo"
    }
  }
]
```

* 找到nacos文件产生的文件位置，将其路径添加到Prometheus的配置文件，例如（按照实际环境修改）

```
/home/nacos/data/tenant-config-data/
```

```
 - job_name: 'nacos_files'
    # 指定路径
    metrics_path: '/actuator/prometheus'
    # 收集数据的时间间隔
    scrape_interval: 5s
    file_sd_configs:
      - refresh_interval: 5s
        files:
          - ./nacos/prometheus/DEFAULT_GROUP/*.json
          - ./*.json

```

* 重启Prometheus，再nacos的Prometheus命名空间下添加.json文件，查看Prometheus面板Status->Targets，观察是否生效

<figure><img src="/files/zXuBIv8o8EkqHgEc0LKa" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.gpg123.vip/prometheus+nacos-ji-yu-wen-jian-shi-xian-dong-tai-jian-kong-fa-xian/prometheus+nacos-dong-tai-jian-kong-fa-xian.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
