基于devops利用微服务引入三方服务---监控hello容器并进行并发测试

1、监控hello

监控hello,除了必要的容器资源情况监控,还需要监控api,hello无法自己暴露metrics,这里通过代理服务wrapper来暴露
部署hello应用
cat docker-compose.yml

version: "3.4"
services:
  hello:
    image: 192.168.0.152:8082/waka2020/wrapper-hello:latest
    networks:
      - service_overlay
      - monitor_overlay
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
    environment:
      - CENTER_HOSTNAME=nacos
      - SERVICE_ETHERNET_NAME=eth2
    deploy:
      mode: replicated
      replicas: 3
      resources:
        limits:
          cpus: '1'
          memory: '1G'
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
networks:
  service_overlay:
    external: true
  monitor_overlay:
    external: true

启动服务
docker stack deploy -c docker-compose.yml 150

添加采集点
cat promethesu.yml

...
 - job_name: 'wrapper-hello'
    scrape_interval: 5s
    static_configs:
      - targets: ['hello:58080']

查看endpoints
08api42

监控hello应用http请求情况

  • 请求总时间
    查询语句

  • 请求总次数
    查询语句

2、测试并发请求次数及响应时间

测试地址 192.168.0.150/api/hello/data
08api54
测试地址 192.168.0.150:58080/data
08api56

两者相差接近100ms,如果请求并发数增大,这个时差会更大

请求到了wrapper代理端口后都是通过swarm的负载均衡来自动发往后端容器,那么这相差接近100ms的时差应该是由nginx和vip进行通信时导致的

那么如果通过dnsrr的方式来进行服务与后端容器的通信会不会有所改善呢,我们需要知道直接访问hello应用的响应时间与通过dnsrr方式的响应时间时差是多少才能判断有无必要修改

先修改hello配置文件
cat docker-compose.yml

version: "3.4"
services:
  hello:
    image: 192.168.0.152:8082/waka2020/wrapper-hello:latest
    networks:
      - service_overlay
      - monitor_overlay
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
    ports:
      - "58080:58080"
    environment:
      - CENTER_HOSTNAME=nacos
      - SERVICE_ETHERNET_NAME=eth2
    deploy:
      placement:
        constraints: [node.hostname==node150]
      mode: replicated
      replicas: 1
      resources:
        limits:
          cpus: '1'
          memory: '1G'
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
networks:
  service_overlay:
    external: true
  monitor_overlay:
    external: true

08api57

改用dnsrr模式来分发请求
cat docker-compose.yml

version: "3.4"
services:
  hello:
    image: 192.168.0.152:8082/waka2020/wrapper-hello:latest
    networks:
      - service_overlay
      - monitor_overlay
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
    environment:
      - CENTER_HOSTNAME=nacos
      - SERVICE_ETHERNET_NAME=eth2
    deploy:
      mode: replicated
      replicas: 3
      endpoint_mode: dnsrr
      resources:
        limits:
          cpus: '1'
          memory: '1G'
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
networks:
  service_overlay:
    external: true
  monitor_overlay:
    external: true

08api58