当前位置:   article > 正文

Prometheus 2.5 + Grafana 5.3 使用官方模板监控

Prometheus 2.5 + Grafana 5.3 使用官方模板监控

系统环境:Centos 7.2 + Prometheus 2.5 + Grafana 5.3 

Grafana 安装参考:Grafana 安装

Prometheus + Grafana 安装参考:Graphing MySQL performance with Prometheus and Grafana(版本较旧)

exporters:Third-party exporters

 

【prometheus 安装配置】

  1. #下载解压:
  2. wget https://github.com/prometheus/prometheus/releases/download/v2.5.0/prometheus-2.5.0.linux-amd64.tar.gz
  3. mkdir /opt/prometheus
  4. tar -zxf prometheus-2.5.0.linux-amd64.tar.gz -C /opt/prometheus --strip-components=1
  5. chown -R root:root /opt/prometheus
  6. #启动
  7. cd /opt/prometheus
  8. ./prometheus

打开站点访问: http://10.10.10.10:9090 ,出现界面说明已正常,安装完成!

可能遇到的问题:

  1. 启动问题:
  2. level=error ts=2018-11-19T06:01:05.697957445Z caller=main.go:625
  3. err="opening storage failed: lock DB directory: resource temporarily unavailable
  4. 解决:删除 lock 文件
  5. rm -f /opt/prometheus/data/lock
  6. 启动问题:
  7. level=error ts=2018-11-19T06:04:47.83421089Z caller=main.go:625
  8. err="error starting web server: listen tcp 0.0.0.0:9090: bind: address already in use"
  9. 解决:查找使用9090端口的PID并删掉
  10. lsof -i :9090
  11. kill -9 <pid>

 

【客户端组件 node_exporter 和 mysqld_exporter 安装配置】

  1. # 下载 node_exporter 和 mysqld_exporter
  2. wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0-rc.0/node_exporter-0.17.0-rc.0.linux-amd64.tar.gz
  3. wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz
  4. mkdir -p /opt/prometheus/exporters
  5. tar zxf node_exporter-0.17.0-rc.0.linux-amd64.tar.gz -C /opt/prometheus/exporters
  6. tar zxf mysqld_exporter-0.11.0.linux-amd64.tar.gz -C /opt/prometheus/exporters
  7. mv /opt/prometheus/exporters/mysqld_exporter-0.11.0.linux-amd64 /opt/prometheus/exporters/mysqld_exporter
  8. mv /opt/prometheus/exporters/node_exporter-0.17.0-rc.0.linux-amd64 /opt/prometheus/exporters/node_exporter
  9. # 在 MySQL 中创建访问账号
  10. GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'prom'@'localhost' identified by '123456';
  11. GRANT SELECT ON performance_schema.* TO 'prom'@'localhost';
  12. # 对MySQL的监控,客户端 MySQL 服务器创建账户文件
  13. vim /opt/prometheus/exporters/.my.cnf
  14. [client]
  15. user=prom
  16. password=123456
  17. host=localhost
  18. port=3306
  19. socket=/tmp/mysql.sock
  20. # 启动数据抓取
  21. chown -R root:root /opt/prometheus
  22. cd /opt/prometheus/
  23. nohup ./exporters/node_exporter/node_exporter &
  24. nohup ./exporters/mysqld_exporter/mysqld_exporter --config.my-cnf="/opt/prometheus/exporters/.my.cnf" &

prometheus 服务器端:编辑配置文件,新增 linux(9100) 和 mysql(9104)  (注意:官网版本格式不准确)

  1. # prometheus 服务器端:编辑配置文件,新增 linux(9100) 和 mysql(9104) (注意:官网上为2.x版本,不准确)
  2. vim /opt/prometheus/prometheus.yml
  3. global:
  4. scrape_interval: 15s
  5. evaluation_interval: 15s
  6. scrape_configs:
  7. - job_name: 'prometheus'
  8. static_configs:
  9. - targets: ['10.10.10.10:9090']
  10. - job_name: linux_10
  11. static_configs:
  12. - targets: ['10.10.10.10:9100','10.10.10.10:9104']
  13. labels:
  14. instance: server10
  15. - job_name: linux_8
  16. static_configs:
  17. - targets: ['10.10.10.8:9100','10.10.10.8:9104']
  18. labels:
  19. instance: kk
  20. # 启动 prometheus 服务
  21. cd /opt/prometheus
  22. nohup ./prometheus --storage.tsdb.retention=45d &

我在两台服务器都启动了 node_exporter 和 mysqld_exporter ,所以此时查看 Prometheus :

次数可以查看到 Prometheus 获取到的客户端数据:

 

【Grafana 安装配置】

Grafana 安装参考:Grafana 安装

编辑仪表盘文件位置,取消以下注释:

  1. # 编辑仪表盘文件位置,取消以下注释
  2. vim /etc/grafana/provisioning/dashboards/sample.yaml
  3. apiVersion: 1
  4. providers:
  5. - name: 'default'
  6. orgId: 1
  7. folder: ''
  8. type: file
  9. options:
  10. path: /var/lib/grafana/dashboards
  11. # 注意:官网这个是老方法,已经不用了,下面这里不需要添加 [dashboards.json],用上面的方法。
  12. # 参考:https://community.grafana.com/t/dashboard-provisioning/5667
  13. # vim /etc/grafana/grafana.ini
  14. # [dashboards.json]
  15. # enabled = true
  16. # path = /var/lib/grafana/dashboards

 

【PPM 安装配置】

  1. # 下载并拷贝到仪表盘模板到相应路径中
  2. git clone https://github.com/percona/grafana-dashboards.git
  3. cp -r grafana-dashboards/dashboards /var/lib/grafana
  4. # rm -fr grafana-dashboards (下载的文件其实也可以删除了)
  5. cp /usr/share/grafana/public/app/plugins/datasource/prometheus/query_ctrl.ts /usr/share/grafana/public/app/plugins/datasource/prometheus/query_ctrl.js
  6. cp /usr/share/grafana/public/app/plugins/datasource/prometheus/datasource.ts /usr/share/grafana/public/app/plugins/datasource/prometheus/datasource.js
  7. # 重启 grafana 服务
  8. service grafana-server restart

登录访问 grafana ,安装 Prometheus 数据源插件,添加数据库源。

系统新增的模板报表:

 

但是发现,还是有很多图像是没有数据的,因为模板比较旧,监控的变量名称与新的不匹配。以模板 System_Overview.json 为例,“system uptime ”是没有数据的,编辑图像可以看到变量名称不对。

 需要把名称 node_time 改为 node_time_secondsnode_boot_time 改为 node_boot_time_seconds ,如下:

  1. (node_time{instance="$host"} - node_boot_time{instance="$host"}) or (time() - node_boot_time{instance="$host"})
  2. 改为:
  3. (node_time_seconds{instance="$host"} - node_boot_time_seconds{instance="$host"}) or (time() - node_boot_time_seconds{instance="$host"})

为什么知道这么改呢?可以查看 Prometheus 图像,会提示相关名称,确认这些名称都能在这里能找到。

 

改为之后,grafana 的仪表盘却不允许修改,那只能到系统中更改啦。在模板目录 /var/lib/grafana/dashboards/ 找到文件,编辑替换掉相应的名称。完成!!

vim /var/lib/grafana/dashboards/System_Overview.json

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/307455?site
推荐阅读
相关标签
  

闽ICP备14008679号