基于docker 搭建Prometheus+Grafana

1:下载镜像

dailong-MacBook-Pro:~ dailong$ docker pull prom/node-exporter
dailong-MacBook-Pro:~ dailong$ docker pull prom/prometheus
dailong-MacBook-Pro:~ dailong$ docker pull grafana/grafana

dailong-MacBook-Pro:~ dailong$ docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
grafana/grafana      latest              4933878f8ba5        5 days ago          228MB
prom/prometheus      latest              7317640d555e        3 weeks ago         130MB
prom/node-exporter   latest              e5a616e4b9cf        6 months ago        22.9MB

2:启动node-exporter

docker run -d -p 9100:9100 -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" prom/node-exporter

dailong-MacBook-Pro:~ dailong$ docker ps
CONTAINER ID        IMAGE                COMMAND                CREATED             STATUS              PORTS               NAMES
019b721282ce        prom/node-exporter   "/bin/node_exporter"   7 seconds ago       Up 6 seconds                            sweet_bardeen

访问URL,可查看收集的系统信息

http://localhost:9100/metrics
image.png

启动prometheus

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

mkdir /Users/dailong/Desktop/prometheus
cd /Users/dailong/Desktop/prometheus
vim prometheus.yml

增加如下内容,你还可以按照格式加mysql,mongo等:

global:
  scrape_interval:     60s
  evaluation_interval: 60s
 
scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus
 
  - job_name: linux
    static_configs:
      - targets: ['192.168.204.241:9100']
        labels:
          instance: localhost
  - job_name: mysql
    static_configs:
      - targets: ['192.168.204.241:3306']
        labels:
          instance: mysql

启动prometheus

docker run  -d -p 9090:9090 -v /Users/dailong/Desktop/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

查看执行结果

dailong-MacBook-Pro:dl dailong$ docker run  -d -p 9090:9090 -v /Users/dailong/Desktop/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
9eb61ab9b3dfa89aa2671a4fab91428ac64c44cc6309fd03c0a4e4faf1226600
dailong-MacBook-Pro:dl dailong$ docker ps
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                    NAMES
9eb61ab9b3df        prom/prometheus      "/bin/prometheus --c…"   42 seconds ago      Up 41 seconds       0.0.0.0:9090->9090/tcp   keen_lamarr
7c48156037f6        prom/node-exporter   "/bin/node_exporter"     17 minutes ago      Up 17 minutes       0.0.0.0:9100->9100/tcp   vigilant_williamson
dailong-MacBook-Pro:dl dailong$ 

访问URL
http://localhost:9090/graph
效果如下:

image.png

访问RUL
http://localhost:9090/targets
效果如下:

image.png

如果状态没有UP起来,等待一会,就会UP了

启动grafana

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

dailong-MacBook-Pro:dl dailong$ mkdir /Users/dailong/Desktop/grafana-storage
dailong-MacBook-Pro:dl dailong$ chmod 777 /Users/dailong/Desktop/grafana-storage

启动grafana

docker run -d -p 3000:3000 --name=grafana -v /Users/dailong/Desktop/grafana-storage:/var/lib/grafana grafana/grafana

查看执行结果

dailong-MacBook-Pro:dl dailong$ docker ps
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                    NAMES
0fa18202b25d        grafana/grafana      "/run.sh"                6 seconds ago       Up 5 seconds        0.0.0.0:3000->3000/tcp   grafana
9eb61ab9b3df        prom/prometheus      "/bin/prometheus --c…"   11 minutes ago      Up 11 minutes       0.0.0.0:9090->9090/tcp   keen_lamarr
7c48156037f6        prom/node-exporter   "/bin/node_exporter"     28 minutes ago      Up 28 minutes       0.0.0.0:9100->9100/tcp   vigilant_williamson
dailong-MacBook-Pro:dl dailong$ 

访问RUL
http://localhost:3000/login
效果如下,默认admin/admin,输入默认密码后,会要求需修改密码(sumalaod)

image.png

登陆效果如下
image.png

然后添加源
image.png

选择prometheu


image.png

填必要信息


image.png

当前页面往下滑,点击添加


image.png

image.png

点击左上角图标,回主页,点击New dashboard


image.png

点击Choose Visualization

image.png

点击Graph


image.png

导入模版

image.png

导入json串


image.png

导入


image.png
image.png

模版文件内容过多,就不贴了,完毕

参考链接:
https://blog.csdn.net/qq_40460909/article/details/81386666
https://www.cnblogs.com/xiao987334176/p/9930517.html

你可能感兴趣的:(基于docker 搭建Prometheus+Grafana)