关于nginx:nginx服务资源监控

依赖

一个内置的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:alpine

RUN 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.conf
server {
    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

【腾讯云】轻量 2核2G4M,首年65元

阿里云限时活动-云数据库 RDS MySQL  1核2G配置 1.88/月 速抢

本文由乐趣区整理发布,转载请注明出处,谢谢。

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据