💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# **USE FILE-BASED SERVICE DISCOVERY TO DISCOVER SCRAPE TARGETS** Prometheus提供了多种[服务发现选项](https://github.com/prometheus/prometheus/tree/master/discovery)来发现抓取目标,包括[Kubernetes](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Ckubernetes_sd_config),[Consul](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Cconsul_sd_config)等。如果您需要使用当前不支持的服务发现系统,Prometheus[基于文件的服务发现](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Cfile_sd_config)机制可能会最好地满足您的用例,该机制使你能够在JSON文件中列出抓取目标(以及这些目标相关的元数据)。 该指南中,我们将会 * 在本地安装、运行一个Prometheus [Node Exporter](https://prometheus.io/docs/guides/node-exporter) * 创建一个`targets.json`文件,用以为Node Exporter指定主机和端口信息。 * 安装并运行Prometheus实例,该实例配置使用targets.json文件来发现Node exporter。 ## **安装运行Node Exporter** 查看`使用Node Exporter来监控Linux宿主机metrics`指南的[这部分](https://prometheus.io/docs/guides/node-exporter#installing-and-running-the-node-exporter)。该Node Exporter运行在9100端口。通过请求确认该Node Exporter确实在暴露metrics: ~~~ curl http://localhost:9100/metrics ~~~ metrics看上去像这样: ~~~ # HELP go_gc_duration_seconds A summary of the GC invocation durations. # TYPE go_gc_duration_seconds summary go_gc_duration_seconds{quantile="0"} 0 go_gc_duration_seconds{quantile="0.25"} 0 go_gc_duration_seconds{quantile="0.5"} 0 ... ~~~ ## **安装、配置、运行Prometheus** 下载、解压、安装Prometheus。 解压的目录里包含配置文件`prometheus.yml`。替换配置文件中相同的部分如下: ~~~ scrape_configs: - job_name: 'node' file_sd_configs: - files: - 'targets.json' ~~~ 该配置文件指定了一个名称为`node`的job,该job从targets.json文件中检索Node Exporter实例的主机和端口信息。 现在创建一个targets.json文件,同时添加内容如下: ~~~ [ { "labels": { "job": "node" }, "targets": [ "localhost:9100" ] } ] ~~~ 该配置指定了一个名称为`node`的job,其target为:`localhost:9100`。 现在你可以开启Prometheus: ~~~ ./prometheus ~~~ 如果Prometheus启动成功,你能够看到一行日志如下: ~~~ level=info ts=2018-08-13T20:39:24.905651509Z caller=main.go:500 msg="Server is ready to receive web requests." ~~~ ## **探索服务发现的metrics**