前言:
软件环境准备好:两台centos 7虚机(一个安装promethus、一个安装agent)

  1. # 常用liunx命令
  2. # 查看ip
  3. ip a
  4. # xshell拖拽上传文件
  5. yum install -y lrzsz
  6. # 安装git
  7. yum install -y git
  8. # 安装java环境
  9. yum -y install java java-devel
  10. # 安装 maven
  11. yum -y install maven
  12. # 安装 docker
  13. yum -y install docker
  14. yum install -y net-tools

1. 安装promethus

docker拉镜像

  1. docker pull prom/node-exporter
  2. docker pull prom/prometheus
  3. docker pull grafana/grafana

启动node-exporter

  1. docker run -d -p 9100:9100 \
  2. -v "/proc:/host/proc:ro" \
  3. -v "/sys:/host/sys:ro" \
  4. -v "/:/rootfs:ro" \
  5. --net="host" \
  6. prom/node-exporter

netstat -anpt命令,查看端口起来没
image.png
访问 http://192.168.27.25:9100/
image.png

image.png
如上所示,promethus搭建成功一半了

新建目录prometheus,编辑配置文件prometheus.yml

  1. mkdir /opt/prometheus
  2. cd /opt/prometheus/
  3. vim prometheus.yml

prometheus.yml如下

  1. global:
  2. scrape_interval: 60s
  3. evaluation_interval: 60s
  4. scrape_configs:
  5. - job_name: prometheus
  6. static_configs:
  7. - targets: ['localhost:9090']
  8. labels:
  9. instance: prometheus
  10. - job_name: linux
  11. static_configs:
  12. - targets: ['192.168.27.25:9100']
  13. labels:
  14. instance: localhost

prometheus.yml
注意:修改IP地址,这里的192.168.27.25就是本机地址

启动 prometheus

  1. docker run -d \
  2. -p 9090:9090 \
  3. -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
  4. prom/prometheus

访问:http://192.168.27.25:9090/graph
image.png

访问:http://192.168.27.25:9090/targets
image.png

2. 搭建grafana

新建空文件夹grafana-storage,用来存储数据

  1. mkdir /opt/grafana-storage

设置权限 因为grafana用户会在这个目录写入文件,直接设置777,比较简单粗暴!

  1. chmod 777 -R /opt/grafana-storage
  2. chmod 777 /var/lib

启动grafana

  1. docker run -d \
  2. --privileged=true \
  3. -p 3000:3000 \
  4. --name=grafana \
  5. -v /opt/grafana-storage:/var/lib/grafana \
  6. grafana/grafana

访问 http://192.168.27.25:3000/ admin admin
image.png

后续步骤
image.png

image.png

image.png
点击下面的Save & Test,如果出现绿色的,说明ok了
image.png

3.监控java应用

准备:新虚机;jar包;test-remote-0.0.1-SNAPSHOT-exec.jar