prometheus+grafana安装使用

298 阅读1分钟

1 服务安装

1.1 下载文件

官网下载地址:prometheus.io/download/

此笔记下载了最新的prometheus-2.42.0.linux-amd64.tar.gz

1.2 安装上传工具

apt install -y lrzsz

1.3 解压

tar vxf prometheus-2.42.0.linux-amd64.tar.gz

1.4 运行

cd prometheus-2.42.0.linux-amd64 && nohup ./prometheus &

1.5 访问

http://127.0.0.1:9090/

2 主机监控配置

2.1 node_exporter 安装

官网下载地址:prometheus.io/download/#n…

此笔记下载了最新的 node_exporter-1.5.0.linux-amd64.tar.gz

2.2 解压

tar zvxf node_exporter-1.5.0.linux-amd64.tar.gz

2.3 运行

cd node_exporter-1.5.0.linux-amd64 && nohup ./node_exporter &

2.4 访问

http://127.0.0.1:9100/

2.5 配置

pkill prometheus 
vim prometheus.yml 

cat prometheus.yml |tail -3
- job_name: "node_exporter" 
    static_configs: 
    - targets: ["localhost:9100"] 

nohup ./prometheus &

2.6 访问监控

http://127.0.0.1:9090/targets?search=

3 mysql监控配置

3.1 mysqld_exporter 安装

官网下载地址:prometheus.io/download/#m…

此笔记下载了最新的 mysqld_exporter-0.14.0.linux-amd64.tar.gz

3.2 解压

tar zvxf mysqld_exporter-0.14.0.linux-amd64.tar.gz

3.3 运行

cd mysqld_exporter-0.14.0.linux-amd64 
chown -R root:root mysqld_exporter 
chmod 755 mysqld_exporter 

vim .my.cnf 
    [client] 
    host=127.0.0.1 
    port=3306 
    user=root 
    password=xxx 

vim ./start.sh 
    #!/bin/bash 
    nohup ./mysqld_exporter --config.my-cnf=./.my.cnf & 

./start.sh

3.4 访问

http://127.0.0.1:9104/

3.5 配置

pkill prometheus vim prometheus.yml cat prometheus.yml |tail -3 - job_name: "mysqld_exporter" static_configs: - targets: ["localhost:9104"] nohup ./prometheus &

2.6 访问监控

http://127.0.0.1:9090/targets?search=

4 安装grafana

4.1 下载

grafana.com/grafana/dow…

sudo apt-get install -y adduser libfontconfig1 
wget https://dl.grafana.com/enterprise/release/grafana-enterprise_9.3.6_amd64.deb 
sudo dpkg -i grafana-enterprise_9.3.6_amd64.deb

4.2 运行

systemctl start grafana-server 
systemctl status grafana-server

4.3 访问

http://127.0.0.1:3000/login clipboard.png 默认账号密码:admin/admin

4.4 使用

  • 添加数据来源
    image.png

  • 选择Prometheus
    image.png

  • 填入数据来源地址
    image.png

  • 添加完成
    image.png

  • 打开面板
    image.png

  • 新建
    image.png

  • 进入导入页面
    image.png

  • 在仪表盘市场找到你需要的:grafana.com/grafana/das… image.png

  • 下载JSON
    image.png

  • 导入即可,以下为MYSQL Exporter的示例
    clipboard2.png

    clipboard1.png

使用参考:zhuanlan.zhihu.com/p/521815619