S7:Docker、Prometheus、Grafana

2020-05-09  本文已影响0人  睦月MTK

声明:所有的实验示例大部分来自《learn-docker-in-a-month-of-lunches》的作者Elton Stoneman,但运行结果并不都是照搬,大部分实验结果可能与原书不同


一、前言

虽然通过health check可以判断一个容器是否正常运行,但是其实除此之外,我们更想得到更多的运行相关信息,这样就可以避免应用的状态变得更差之前发现问题,从而避免服务的停止。这比health check只是在容器变得不正常后才提醒你来得更加有效。PrometheusGrafana都是开源的性能监控类工具,前者负责将应用的各种运行详情抽取出来,后者则负责将抽取出来的数据进行一个可视化的显示。


二、Prometheus镜像的制作与自定义配置

三、Grafana镜像的制作与自定义配置

四、Docker自身的监控信息怎么输出
  1. 修改配置文件/etc/docker/daemon.json
{
  //...
  "metrics-addr" : "0.0.0.0:9323",
  "experimental" : true
  //...
}
  1. 重新启动Docker
$ systemctl restart docker
  1. 访问localhost:9323/metrics查看Docker输出的监控信息

五、Docker、Prometheus、Grafana整合实验
  1. 获取当前机器的IP
$ ip route get 1 | awk '{print $NF;exit}'
  1. 修改Elton Stoneman提供的docker-compose-with-grafana.yml
version: "3.7"

services:
  accesslog:
    image: diamol/ch09-access-log
    ports:
      - "80"
    networks:
      - app-net

  iotd:
    image: diamol/ch09-image-of-the-day
    ports:
      - "8011:80"
    networks:
      - app-net

  image-gallery:
    image: diamol/ch09-image-gallery
    ports:
      - "8010:80"
    depends_on:
      - accesslog
      - iotd
    networks:
      - app-net

  prometheus:
    image: diamol/ch09-prometheus
    ports:
      - "9090:9090"
    environment:
      - DOCKER_HOST=172.17.0.8
    networks:
      - app-net

  grafana:
    image: diamol/ch09-grafana
    ports:
      - "8989:3000"
    depends_on:
      - prometheus
    networks:
      - app-net

networks:
  app-net:
    external:
      name: nat

DOCKER_HOST修改为你机器的IP

  1. 部署应用
$ docker-compose -f docker-compose-with-grafana.yml up --detach --scale accesslog=3
  1. 打开localhost:9090/targets查看监控源是否都正常
  2. 打开localhost:8989/登录Grafana,点击左上角切换面板“Image Gallery”
  3. 访问localhost:8010发出一个请求,然后查看Grafana的监控面板,我的是这个样子
    Image Gallery

参考文档:
[1] learn-docker-in-a-month-of-lunches
[2] 官方文档


附:
[1] Elton Stoneman的github项目

上一篇 下一篇

猜你喜欢

热点阅读