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 安装配置】

#下载解压:
wget https://github.com/prometheus/prometheus/releases/download/v2.5.0/prometheus-2.5.0.linux-amd64.tar.gz
mkdir /opt/prometheus
tar -zxf prometheus-2.5.0.linux-amd64.tar.gz -C /opt/prometheus --strip-components=1
chown -R root:root /opt/prometheus


#启动	  
cd /opt/prometheus
./prometheus

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

可能遇到的问题:

启动问题:
level=error ts=2018-11-19T06:01:05.697957445Z caller=main.go:625 
err="opening storage failed: lock DB directory: resource temporarily unavailable

解决:删除 lock 文件
rm -f /opt/prometheus/data/lock


启动问题:
level=error ts=2018-11-19T06:04:47.83421089Z caller=main.go:625 
err="error starting web server: listen tcp 0.0.0.0:9090: bind: address already in use"

解决:查找使用9090端口的PID并删掉
lsof -i :9090
kill -9 <pid>

 

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

# 下载 node_exporter 和 mysqld_exporter
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
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz

mkdir -p /opt/prometheus/exporters
tar zxf node_exporter-0.17.0-rc.0.linux-amd64.tar.gz -C /opt/prometheus/exporters
tar zxf mysqld_exporter-0.11.0.linux-amd64.tar.gz -C /opt/prometheus/exporters

mv /opt/prometheus/exporters/mysqld_exporter-0.11.0.linux-amd64 /opt/prometheus/exporters/mysqld_exporter
mv /opt/prometheus/exporters/node_exporter-0.17.0-rc.0.linux-amd64 /opt/prometheus/exporters/node_exporter


# 在 MySQL 中创建访问账号
GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'prom'@'localhost' identified by '123456';
GRANT SELECT ON performance_schema.* TO 'prom'@'localhost';

  
# 对MySQL的监控,客户端 MySQL 服务器创建账户文件
vim /opt/prometheus/exporters/.my.cnf

[client]
user=prom
password=123456
host=localhost
port=3306
socket=/tmp/mysql.sock


# 启动数据抓取
chown -R root:root /opt/prometheus

cd /opt/prometheus/
nohup ./exporters/node_exporter/node_exporter &
nohup ./exporters/mysqld_exporter/mysqld_exporter --config.my-cnf="/opt/prometheus/exporters/.my.cnf" &

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

# prometheus 服务器端:编辑配置文件,新增 linux(9100) 和 mysql(9104)  (注意:官网上为2.x版本,不准确)
vim /opt/prometheus/prometheus.yml

global:
  scrape_interval:     15s
  evaluation_interval: 15s
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['10.10.10.10:9090']
  - job_name: linux_10
    static_configs:
      - targets: ['10.10.10.10:9100','10.10.10.10:9104']
        labels:
          instance: server10
  - job_name: linux_8
    static_configs:
      - targets: ['10.10.10.8:9100','10.10.10.8:9104']
        labels:
          instance: kk



# 启动 prometheus 服务	 
cd /opt/prometheus
nohup ./prometheus --storage.tsdb.retention=45d &

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

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

【Grafana 安装配置】

Grafana 安装参考:Grafana 安装

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

# 编辑仪表盘文件位置,取消以下注释
vim /etc/grafana/provisioning/dashboards/sample.yaml

apiVersion: 1
providers:
 - name: 'default'
   orgId: 1
   folder: ''
   type: file
   options:
     path: /var/lib/grafana/dashboards




# 注意:官网这个是老方法,已经不用了,下面这里不需要添加 [dashboards.json],用上面的方法。
# 参考:https://community.grafana.com/t/dashboard-provisioning/5667
# vim /etc/grafana/grafana.ini

# [dashboards.json]
# enabled = true
# path = /var/lib/grafana/dashboards

【PPM 安装配置】

# 下载并拷贝到仪表盘模板到相应路径中 
git clone https://github.com/percona/grafana-dashboards.git
cp -r grafana-dashboards/dashboards /var/lib/grafana

# rm -fr grafana-dashboards (下载的文件其实也可以删除了)


cp /usr/share/grafana/public/app/plugins/datasource/prometheus/query_ctrl.ts /usr/share/grafana/public/app/plugins/datasource/prometheus/query_ctrl.js
cp /usr/share/grafana/public/app/plugins/datasource/prometheus/datasource.ts /usr/share/grafana/public/app/plugins/datasource/prometheus/datasource.js

# 重启 grafana 服务
service grafana-server restart

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

系统新增的模板报表:

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

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


(node_time{instance="$host"} - node_boot_time{instance="$host"}) or (time() - node_boot_time{instance="$host"})

改为:

(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

猜你喜欢

转载自blog.csdn.net/kk185800961/article/details/84305970
今日推荐