环境:Centos7 64
版本:springboot2.x,prometheus-2.31.1.linux-amd64,grafana-enterprise-8.2.3.linux-amd64
1. Prometheus 1.1.下载解压
官网下载地址 https://prometheus.io/download/
选择版本 prometheus-2.31.1.linux-amd64
下载后解压 tar zxvf prometheus-2.31.1.linux-amd64.tar.gz
1.2. Prometheus启动前配置进入目录 cd prometheus-2.31.1.linux-amd64
编辑配置文件 vim prometheus.yml
按以下配置修改 找到 scrape_configs 新增 job相关配置 其余配置均为默认配置不必改动
# my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=1.3. Prometheus启动` to any timeseries scraped from this config. - job_name: "prometheus" # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ["localhost:9090"] ### springboot 应用配置 对应spring.application.name - job_name: 'spring-boot-application' scrape_interval: 5s ### 对应actuator endpoints.web.base-path metrics_path: '/actuator/prometheus' static_configs: - targets: ['localhost:8080'] # springboot服务端口
nohup ./prometheus &
2. Grafana 2.1.下载解压
官网下载地址 https://grafana.com/grafana/downloa
或直接执行命令 wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.2.3.linux-amd64.tar.gz
下载后解压 tar zxvf grafana-enterprise-8.2.3.linux-amd64.tar.gz
2.2 启动 进入目录 cd grafana-8.2.3/bin
执行启动命令 nohup ./grafana-server &
Docker版部署
Docker version 18.09.7
1. Prometheus
拉取docker镜像
docker pull prom/prometheus
准备一个存放配置文件的目录
mkdir /home/prometheus
准备prometheus.yml文件,可直接使用安装版本中修改后的配置文件
vim prometheus.yml 注意springboot服务路径,因为不在同一容器内所以使用物理机对应IP
- targets: ['192.168.1.1:8080'] # springboot服务端口
启动容器 -d 后台启动 -p 指定物理机和容器端口绑定 -v 挂载物理机目录与容器目录 参数
docker run -d -p 9090:9090 -v /home/Prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml
2. Grafana
拉取docker镜像
docker pull grafana/grafana
启动容器
docker run -d -p 3000:3000 grafana/grafana
至此安装完成,开始关联使用 Prometheus默认端口为9090 直接通过浏览器访问 http://xxx.xxx.xxx.xxx:9090 看到下图证明成功部署 Grafana默认端口为3000 同上直接浏览器访问 http://xxx.xxx.xxx.xxx:3000 看到下图证明成功部署
为Grafana配置数据源
URL填入你的Prometheus的url
安装包部署Prometheus与grafana在同一物理机上所以直接使用 127.0.0.1
容器部署填入物理机IP比如 192.168.1.1
然后直接拉到最下方点击这个
为Grafana配置Dashboard
我个人选择模板 12900,有更好的可以自行更改
到此结束,由于一些原因我展示的是无信息的效果。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)