作者:你看看我的世界_420 | 来源:互联网 | 2023-08-08 17:46
安装docker环境#yum-config-manager--add-repohttp:mirrors.aliyun.comdocker-celinuxcentosdocker-c
安装docker环境
# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# yum -y install docker-ce git
# systemctl start docker
# systemctl enable docker
安装prometheus + grafana + pushgateway
安装 prometheus+ grafana + pushgateway
# cd /opt/
# git clone https://github.com/evnsio/prom-stack.git
# cd prom-stack
version: "3"
services:
pushgateway:
image: prom/pushgateway:v0.4.0
command: --persistence.file=/pushgateway/pushgateway.data
ports:
- 9091:9091
volumes:
- ./data/pushgateway:/pushgateway
prometheus:
#image: prom/prometheus:v2.0.0
image: prom/prometheus:v2.18.1
command: --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.retention=60d
user: 0:0
ports:
- 9090:9090
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- ./prometheus/alerts/:/etc/prometheus/rules.d/
- ./data/prometheus:/prometheus
grafana:
#image: grafana/grafana:4.6.2
image: grafana/grafana:6.7.1
ports:
- 3000:3000
volumes:
- ./data/grafana:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=password
alertmanager:
image: prom/alertmanager:v0.11.0
command: --config.file=/etc/alertmanager/alertmanager.yml
ports:
- 9093:9093
volumes:
- ./alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml
grafana使用默认用户名密码 admin password 登陆
## 安装Docker-compose
# curl "https://dl.cactifans.com/zabbix_docker/docker-compose" -o /usr/bin/docker-compose
# chmod a+x /usr/bin/docker-compose
## 查看docker-compose版本
# docker-compose version
## 创建目录
# mkdir /data/monitor/prom-stack/data/{grafana,prometheus,pushgateway}
## 修改grafana目录属主和属组,否则容器无法启动
# chown 472:472 -R /data/monitor/prom-stack/data/grafana
# cd /opt/prom-stack
# docker-compose -f docker-compose.yml pull
# docker-compose -f docker-compose.yml up -d
查看服务安装情况
# docker-compse ps
# docker ps -a
使用curl生成测试数据
# while true; do
echo "mymetric $RANDOM" | curl --data-binary @- http://localhost:9091/metrics/job/my-push-job
sleep 1
done
"mymetric"就是这个被监控的指标,这个监控指标推送到pushgateway比较简洁直观的
- 在浏览器里打开pushgateway: "http://172.16.0.1:9091/"
可以看到测试的数据已经进入pushgateway了
在grafana配置可视化界面
配置从prometheus里获取监控数据
- 在浏览器里打开grafana:http://172.16.0.1:3000 配置好prometheus监控数据服务器的地址
创建监控数据展示页面
mymetric{exported_job="my-push-job",instance="172.16.0.1:9091",job="prom-stack"}
查询出这一步生成的用来测试的监控数据,点击保存生成图表
参考文档
https://juejin.im/post/5ce3e44bf265da1bd260c157