Prometheus动态配置目标

Prometheus动态配置目标

(金庆的专栏 2018.4)

最简单的配置是静态目标:

scrape_configs:
  - job_name: 'prometheus'

    static_configs:
      - targets: ['localhost:9090', 'localhost:9100']
        labels:
          group: 'prometheus'

更改此文件后,可以发送 SIGHUP 触发配置重新加载。

Prometheus 提供了服务发现功能,可以从 consul, dns, kubernetes, file 等等多种来源发现新的目标。
其中最简单的是从文件发现服务。

例如 /root/prometheus/prometheus.yml 配置如下:

global:
  scrape_interval: 15s
  evaluation_interval: 15s
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['127.0.0.1:9090', '127.0.0.1:9100']
        labels:
          group: 'prometheus'
  - job_name: 'test'
    file_sd_configs:
      - files: ['/etc/prometheus/test_sd_config/*.yml']
        refresh_interval: 5s

用 docker 启动 prometheus:

docker run -d --net=host \
  -v /root/prometheus:/etc/prometheus \
  --name prometheus-server \
  prom/prometheus

创建 /root/prometheus/test_sd_config/test.yml 如下

- targets: [ "192.168.93.192:8080" ]
  labels:
    group: "my_test_group"

5s内就会自动读取 test.yml 并添加新的目标。
可用浏览器打开Prometheus 9090 端口,
查看 Status 中的 Configuration, Targets, Service Discovery,
可以看到新添加的目标。

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 下载Prometheus 首先需要从Prometheus官网下载最新的Prometheus二进制文件,解压缩文件。 2. 配置Prometheus 在解压缩后的目录下,有一个名为prometheus.yml的文件,这个文件是Prometheus配置文件,需要根据实际情况进行修改。配置文件中包含了监控的目标和规则。 3. 运行Prometheus 在命令行中进入Prometheus解压缩后的目录,运行以下命令启动Prometheus: ``` ./prometheus ``` 4. 访问Prometheus 在浏览器中输入以下地址,即可访问Prometheus的Web界面: ``` http://localhost:9090/ ``` 5. 配置Prometheus监控 在Prometheus的Web界面中,可以通过左侧的导航栏进入“Targets”页面,点击“Add target”按钮,输入需要监控的目标地址和端口号,即可完成监控配置。 6. 配置Prometheus告警 在Prometheus配置文件中可以设置告警规则,当监控数据出现异常时,即可触发告警,通过邮件、短信等方式通知管理员。 7. 安装Prometheus Exporter Prometheus Exporter是一种将应用程序的指标数据暴露给Prometheus的工具,可以通过官网下载并安装。 8. 配置Prometheus Exporter 在Prometheus Exporter的配置文件中,需要设置暴露的指标、端口号等参数。 9. 运行Prometheus Exporter 在命令行中进入Prometheus Exporter的安装目录,运行以下命令启动Prometheus Exporter: ``` ./prometheus_exporter ``` 10. 配置Prometheus监控Prometheus Exporter 在Prometheus配置文件中,需要添加Prometheus Exporter的监控目标,即可开始监控Prometheus Exporter的指标数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值