Docker实战-部署GPE微服务的监控体系(二)

19 篇文章 0 订阅
18 篇文章 0 订阅

前言

上篇文章;我们介绍了GPE体系中,grafana的部署和安装(《Docker实战-部署GPE微服务的监控体系》),今天这个文章,我们继续介绍GPE体系中,Prometheus和Exporter的安装及部署,而且将Prometheus和Exporter集成在一起;

 

安装Promethus

获取镜像

root@boot2docker:~# docker image pull prom/prometheus

Using default tag: latest

latest: Pulling from prom/prometheus

3cb635b06aa2: Pull complete

34f699df6fe0: Pull complete

33d6c9635e0f: Pull complete

f2af7323bed8: Pull complete

c16675a6a294: Pull complete

827843f6afe6: Pull complete

3d272942eeaf: Pull complete

7e785cfa34da: Pull complete

05e324559e3b: Pull complete

170620261a59: Pull complete

ec35f5996032: Pull complete

5509173eb708: Pull complete

Digest: sha256:cb9817249c346d6cfadebe383ed3b3cd4c540f623db40c4ca00da2ada45259bb

Status: Downloaded newer image for

查看镜像

[root@izwz9g3javh5eeean08tbtz ~]# docker image ls | grep prometheus

prom/prometheus latest a3d385fc29f9 8 months ago 201MB

创建数据卷

[root@izwz9g3javh5eeean08tbtz ~]#mkdir -p /volume/prometheus

配置prometheus.yaml

[root@izwz9g3javh5eeean08tbtz ~]# vi /volume/prometheus/prometheus.yaml

global:
  scrape_interval:     10s
  evaluation_interval: 10s
  scrape_timeout: 10s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          type: prometheus
          group: default

启动Prometheus

[root@izwz9g3javh5eeean08tbtz ~]# docker run -d \
-p 3001:9090 \
--name=prometheus \
-v /volume/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yml \
prom/prometheus

查看日志

[root@izwz9g3javh5eeean08tbtz ~]# docker container logs prometheus -f

ts=2022-01-19T05:56:49.577Z caller=main.go:478 level=info msg="No time or size retention was set so using the default time retention" duration=15d

ts=2022-01-19T05:56:49.577Z caller=main.go:515 level=info msg="Starting Prometheus" version="(version=2.32.1, branch=HEAD, revision=41f1a8125e664985dd30674e5bdf6b683eff5d32)"

ts=2022-01-19T05:56:49.577Z caller=main.go:520 level=info build_context="(go=go1.17.5, user=root@54b6dbd48b97, date=20211217-22:08:06)"

ts=2022-01-19T05:56:49.577Z caller=main.go:521 level=info host_details="(Linux 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 015fbd6dac64 (none))"

ts=2022-01-19T05:56:49.577Z caller=main.go:522 level=info fd_limits="(soft=1048576, hard=1048576)"

ts=2022-01-19T05:56:49.577Z caller=main.go:523 level=info vm_limits="(soft=unlimited, hard=unlimited)"

ts=2022-01-19T05:56:49.579Z caller=web.go:570 level=info component=web msg="Start listening for connections" address=0.0.0.0:9090

ts=2022-01-19T05:56:49.579Z caller=main.go:924 level=info msg="Starting TSDB ..."

ts=2022-01-19T05:56:49.580Z caller=tls_config.go:195 level=info component=web msg="TLS is disabled." http2=false

ts=2022-01-19T05:56:49.584Z caller=head.go:488 level=info component=tsdb msg="Replaying on-disk memory mappable chunks if any"

ts=2022-01-19T05:56:49.584Z caller=head.go:522 level=info component=tsdb msg="On-disk memory mappable chunks replay completed" duration=5.129µs

ts=2022-01-19T05:56:49.584Z caller=head.go:528 level=info component=tsdb msg="Replaying WAL, this may take a while"

ts=2022-01-19T05:56:49.584Z caller=head.go:599 level=info component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0

ts=2022-01-19T05:56:49.584Z caller=head.go:605 level=info component=tsdb msg="WAL replay completed" checkpoint_replay_duration=27.991µs wal_replay_duration=178.868µs total_replay_duration=227.167µs

ts=2022-01-19T05:56:49.586Z caller=main.go:945 level=info fs_type=EXT4_SUPER_MAGIC

ts=2022-01-19T05:56:49.586Z caller=main.go:948 level=info msg="TSDB started"

ts=2022-01-19T05:56:49.586Z caller=main.go:1129 level=info msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml

ts=2022-01-19T05:56:49.586Z caller=main.go:1166 level=info msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml totalDuration=522.203µs db_storage=660ns remote_storage=2.649µs web_handler=247ns query_engine=714ns scrape=224.952µs scrape_sd=35.726µs notify=766ns notify_sd=1.601µs rules=2.568µs

ts=2022-01-19T05:56:49.586Z caller=main.go:897 level=info msg="Server is ready to receive web requests."

访问Prometheus

打开浏览器,在地址栏输入http://192.168.56.101:3001/targets

出现上面界面,表示已经成功;在prometheus.yaml里我们只配置了一个exporter,所以这里只出现一个Endpoint; 下面我们会使用docker安装一个cAdvisor。

安装cAdvisor

cAdvisor是个用来监控docker环境的工具,cAdvisor提供了支持Prometheus的exporter。 通过cAdvisor,prometheus就可以获取到docker的监控数据

获取镜像

root@boot2docker:~# docker image pull google/cadvisor

Using default tag: latest

latest: Pulling from google/cadvisor

Digest: sha256:815386ebbe9a3490f38785ab11bda34ec8dacf4634af77b8912832d4f85dca04

Status: Image is up to date for google/cadvisor:latest

docker.io/google/cadvisor:latest

查看镜像

root@boot2docker:~# docker image ls | grep google/cadvisor

google/cadvisor latest eb1210707573 3 years ago 69.6MB

启动cAdvisor

root@boot2docker:~# docker run \

--volume=/:/rootfs:ro \

--volume=/var/run:/var/run:rw \

--volume=/sys:/sys:ro \

--volume=/var/lib/docker/:/var/lib/docker:ro \

--volume=/dev/disk/:/dev/disk:ro \

--publish=8080:8080 \

--detach=true \

--name=cadvisor \

google/cadvisor:latest

访问CAdvisor

打开浏览器,地址栏输入http://192.168.56.101:8080;

出现上面界面,表示已经成功; 可以访问http://192.168.56.101:8080/metrics;这是cAdvisor提供的exporter的URL;

至此,cAvisor安装成功, 在Prometheus里使用这个URL来配置endpoint,prometheus就会定期访问这个URL,获取到这些数据后,保存在Prometheus的TSDB里。

Promethues配置cAvisor的endpoint

修改prometheus.yaml文件

global:
  scrape_interval:     10s
  evaluation_interval: 10s
  scrape_timeout: 10s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          type: prometheus
          group: default

  - job_name: cAvisor
    static_configs:
      - targets: ['192.168.56.101:8080']
        labels:
          type: docker
          group: group01

重启Prometheus

root@boot2docker:~# docker container restart prometheus

再次访问promethues;出现新增加的endpoint

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

inthirties

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值