安装Prometheus

下载安装包:https://prometheus.io/download/
image.png
解压安装包

  1. tar -zxvf prometheus-2.34.0.linux-amd64.tar.gz

启动prometheus

  1. cd prometheus-2.34.0.linux-amd64
  2. ./prometheus --config.file=prometheus.yml

推荐使用动态更新配置方式启动

  1. ./prometheus --config.file=prometheus.yml --web.enable-lifecycle

每当配置更新了,可以通过两种热加载方式来操作,一个是直接用kill命令发送HUP信号,一个是开启web.enable-lifecycle选项后使用curl命令

  1. kill -HUP `pidof prometheus`
  2. curl -X POST http://localhost:9090/-/reload

prometheus UI页面:http://192.168.1.10:9090/graph

prometheus.yml参数介绍

  1. global: #这里的配置项可以单独配置在某个job中
  2. scrape_interval: 15s #采集数据间隔,默认15秒
  3. evaluation_interval: 15s 告警规则监测频率,比如已经设置了内存使用大于70%就告警的规则,这里就会每15秒执行一次告警规则
  4. scrape_timeout:10s #采集超时时间
  5. #alerting:
  6. # alertmanagers:
  7. # - static_configs:
  8. # - targets:
  9. # - alertmanager:9093
  10. scrape_configs:
  11. - job_name: 'prometheus-server' #被监控资源的组名称为job
  12. metrics_path defaults to '/metrics' #该行可不写,获取数据URI默认为/metrics
  13. scheme defaults to 'http' #默认http方式采集
  14. static_configs:
  15. - targets: ['localhost:9090','192.168.1.100:9100'] #节点地址与获取Metrics数据端口,多个地址用逗号分隔,也可以写多行
  16. - job_name: 'nodes'
  17. file_sd_configs:
  18. static_configs:
  19. - targets:
  20. - 192.168.1.101:9100
  21. - 192.168.1.102:9100
  22. - 192.168.1.103:9100

安装可视化工具Grafana

下载地址:https://grafana.com/grafana/download

  1. wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.4.6-1.x86_64.rpm
  2. sudo yum install grafana-enterprise-8.4.6-1.x86_64.rpm
  1. systemctl daemon-reload
  2. systemctl start grafana-server
  3. systemctl status grafana-server

登录:http://192.168.1.10:3000/login,账号:admin 密码:admin

Grafana集成Prometheus

1、新增一个数据源,数据源类型选择Prometheus
image.png
image.png
2、配置Prometheus服务端的地址和端口
image.png
3、添加Dashbord,可以直接导入现成模板,也可以去https://grafana.com/dashboards网站上下载其他Dashboard模板
image.png
4、返回Dashboard可以查看到漂亮的图表了
image.png
image.png