
性能监控Prometheus+Grafana
prometheus+node_exporter+mysqld_exporter+Grafana
Docker 方式安装
Plain Text $ docker run --name prometheus -d -p 127.0.0.1:9090:9090 quay.io/prometheus/prometheus
Plain Text # 运行 docker ps 查看所有服务 docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e9ebc2435387 quay.io/prometheus/prometheus "/bin/prometheus -..." 26 minutes ago Up 26 minutes 127.0.0.1:9090->9090/tcp prometheus
运行 docker start prometheus 启动服务
运行 docker stats prometheus 查看 prometheus 状态
运行 docker stop prometheus 停止服务
UI 页面跟上面一样都使用 IP:9090
1)修改Prometheus主配置文件
[root@Docker ~]# docker cp prometheus:/etc/prometheus/prometheus.yml $PWD
[root@Docker ~]# vim prometheus.yml
在Prometheus配置文件按以下内容修改:
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux
static_configs:
- targets: ['192.168.1.1:9100'] #被监控端的IP地址和端口号(有多个被监控端可用 逗号 隔开)
labels:
instance: linux
- job_name: mysql
static_configs:
- targets: ['192.168.1.1:9104'] #被监控端的IP地址和端口号(有多个被监控端可用 逗号 隔开)
labels:
instance: mysql
[root@Docker ~]# docker cp $PWD/prometheus.yml prometheus:/etc/prometheus/prometheus.yml2)重启Prometheus容器
[root@Docker ~]# docker restart prometheusnode_exporter
服务器下载太慢时,可直接从github网站下载,并将压缩包上传至服务器。 文章最后分享了网盘链接也可自行下载。
tar -zxvf node_exporter-1.2.2.linux-amd64.tar.gz -C /usr/local/ cd /usr/local/ mv node_exporter-1.2.2.linux-amd64/ node_exporter/
nohup ./node_exporter &
导入模板8919 ,12884,
mysqld_exporter
tar -zxvf mysqld_exporter-0.14.0.linux-amd64.tar.gz
mv mysqld_exporter-0.14.0.linux-amd64 mysqld_exporter
cd mysqld_exporter
创建my.cnf
vi my.cnf
[client]
user=root
password=zdj1212
host=localhost
port=3306启动
nohup ./mysqld_exporter –config.my-cnf=‘my.cnf’&
使用模板(14057)
Grafana 安装
docker run -d -p 3000:3000 grafana/grafana
默认密码admin/admin
添加数据原为prometheus



保存提示
Error reading Prometheus: Post “http://localhost/:9090/api/v1/query”: dial tcp 127.0.0.1:80: connect: connection refused
如果是docker启动的Prometheus,url改为下面的
http://host.docker.internal:9090添加模板 (https://grafana.com/grafana/dashboards/ )

获取模板

node_exporter:8919 ,12884
mysqld_exporter:14057
读者评论
评论会同步写入该文在 Notion 中的页面底部(与正文同页,便于管理)。
暂无评论,欢迎抢沙发。