依赖

一个内置的with-http_stub_status_module模块

配置

启用的时候只须要配置server块当中加上一小段拜访url即可获取到

location /status {    stub_status on; }

docker实现

目前采纳nginx:alpine作为镜像,实现拜访http://127.0.0.1/status获取到服务状态信息

因为须要批改/etc/nginx/conf.d/default.conf文件,所以咱们能够抉择挂载一个文件或者从新构建一个镜像

上面咱们创立一个Dockerfile,该文件次要是在default.conf文件应用sed查找server_name localhost;并且在前面退出一段location

FROM nginx:alpineRUN sed -i '/server_name  localhost;/a\    location /status {\n        stub_status on;\n    }' /etc/nginx/conf.d/default.conf

创立compose.yaml文件如下

services:  nginx:    container_name: demo-nginx    image: demo-nginx    build: .    restart: always    ports:      - "80:80"

开始构建镜像

$ docker compose build

启动容器

$ docker compose up -d

查看容器外部nginx配置确认location /status块存在

$ docker exec demo-nginx cat /etc/nginx/conf.d/default.confserver {    listen       80;    server_name  localhost;    location /status {        stub_status on;    }    #access_log  /var/log/nginx/host.access.log  main;        location / {        root   /usr/share/nginx/html;        index  index.html index.htm;    }....

后果验证

浏览器拜访地址http://127.0.0.1/status获取返回数据如下

Active connections: 2 server accepts handled requests 2 2 4 Reading: 0 Writing: 1 Waiting: 1 

字段含意

  • Active connections: 沉闷连接数
  • server

    • accepts: 接管申请
    • handled: 已解决申请
    • requests: 客户端申请
  • Reading: 以后所有连贯中正在读取申请Header的数量
  • Writing: 以后所有连贯中正在返回数据的数量
  • Waiting: 以后期待申请的闲暇客户端连接数

参考浏览

Module ngx_http_stub_status_module