美文网首页
ubantu,docker搭建Prometheus和Grafan

ubantu,docker搭建Prometheus和Grafan

作者: ZaneInTheSun | 来源:发表于2024-03-25 13:09 被阅读0次

启动Prometheus
1、在本地新建配置文件prometheus.yml,用于启动Prometheus

global:
  scrape_interval:     60s
  evaluation_interval: 60s 
scrape_configs:
# 可随意指定
  - job_name: 'springboot_test'
    # 采集的路径
    metrics_path: '/actuator/prometheus'
    # 采集服务的地址,设置成Springboot应用所在服务器的具体地址
    static_configs:
      - targets: ['192.168.202.177:8849']

注意本地启动springboot的ip192.168.202.177不要使用localhost,不然就会访问容器里面的端口

2、启动 Prometheus
Prometheus是一个用于监控和警报的开源系统。我们将使用Docker容器来运行它。在终端中运行以下命令来启动Prometheus容器。

sudo docker run -d -p 9090:9090  -v  /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml --name=prometheus prom/prometheus

注意我的prometheus.yml本机文件位置在

/opt/prometheus/prometheus.yml

Prometheus的Web界面将在

 http://localhost:9090 

上可用


bb77ecfbdb3245e4adf07d6ff71c2013.png
876f6e1098ca413a9048687f1278db48.png

在这里看到普罗米修斯对目标springboot应用已经访问成功了,会一分钟一调用springboot的http://192.168.202.177:8849/actuator/prometheus

启动 Grafana
Grafana是一个流行的开源数据可视化和仪表盘工具。同样地,我们将使用Docker容器来运行它。运行以下命令来启动Grafana容器:

sudo docker run -d -p 3000:3000  --name=grafana grafana/grafana

这将从Docker Hub下载Grafana镜像(如果还没有下载),并将其运行在Docker容器中。Grafana的Web界面将在

http://localhost:3000 

配置Grafana

配置 Grafana 连接到 Prometheus
打开浏览器,访问 http://localhost:3000 来访问Grafana界面。
使用默认的用户名和密码登录(默认用户名和密码都是 admin)。
在home-connections-Data sources中 新增数据源

image.png image.png
image.png
image.png
image.png

接下来创建可视化界面
数据源配置成功后,选择Create->Import,在此界面上传或配置Dashboard,在https://github.com/percona/grafana-dashboards 这个项目,我们可以找到一些成熟的Dashboard配置,对于Linux监控可以选择 System_Overview.json,对于MySQL可以选择 MySQL_Overview.json,将这两个文件下载,依次选择 【Upload JSON file】按钮进行上传。
除了这个开源项目之外,Grafana还提供了官方的Dashboard市场:https://grafana.com/grafana/dashboards 。我们可以在这里找到各种数据源各种收集器的Dashboard配置。

相关文章

网友评论

      本文标题:ubantu,docker搭建Prometheus和Grafan

      本文链接:https://www.haomeiwen.com/subject/wrvdtjtx.html