zoukankan      html  css  js  c++  java
  • elasticSearch插件metricbeat收集nginx的度量指标

    ngx_http_stub_status_module模块是Nginx中用来统计Nginx服务所接收和处理的请求数量,只要在编译安装Nginx的时候加上参数--with-http_stub_status_module就可以开启该功能,如果编译时没有加该参数的话可以重新编译安装一次,不会影响原有的配置文件。

    #重新编译nginx
    ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
    make
    make install
    ./nginx -V #查询版本信息
    nginx version: nginx/1.11.6
    built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
    configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module
    #配置nginx
    vim nginx.conf
    location /nginx-status {
    stub_status on;
    access_log off;
    }

    测试:

     结果说明:
    Active connections:正在处理的活动连接数
    server accepts handled requests
    第一个 server 表示Nginx启动到现在共处理了9个连接
    第二个 accepts 表示Nginx启动到现在共成功创建 9 次握手
    第三个 handled requests 表示总共处理了 21 次请求
    请求丢失数 = 握手数 - 连接数 ,可以看出目前为止没有丢失请求
    Reading: 0 Writing: 1 Waiting: 1
    ReadingNginx 读取到客户端的 Header 信息数
    WritingNginx 返回给客户端 Header 信息数
    WaitingNginx 已经处理完正在等候下一次请求指令的驻留链接(开启keep-alive的情况下,这个值等于
    Active - (Reading+Writing)

    2、部署与收集系统指标

    vim metricbeat.yml

    metricbeat.config.modules:
      # Glob pattern for configuration loading
      path: ${path.config}/modules.d/*.yml
    
      # Set to true to enable config reloading
      reload.enabled: false
    
      # Period on which files under path should be checked for changes
      #reload.period: 10s
    
    #==================== Elasticsearch template setting ==========================
    
    setup.template.settings:
      index.number_of_shards: 2
      index.codec: best_compression
      #_source.enabled: false
    
    
    setup.kibana:
    
    output.elasticsearch:
      # Array of hosts to connect to.
      hosts: ["127.0.0.1:9200","127.0.0.1:9201","127.0.0.1:9202"]
    
    
    
    processors:
      - add_host_metadata: ~
      - add_cloud_metadata: ~

    metricbeat默认会加载${path.config}/modules.d/*.yml下的modules模块来收集指标数据,默认只开启了收集system的cpu 内存等信息

    system module配置: 查看system.yml的信息

    # Module: system
    # Docs: https://www.elastic.co/guide/en/beats/metricbeat/6.5/metricbeat-module-system.html
    
    - module: system
      period: 10s
      metricsets:
        - cpu
        #- load
        - memory
        - network
        - process
        - process_summary
        #- core
        #- diskio
        #- socket
      process.include_top_n:
        by_cpu: 5      # include top 5 processes by CPU
        by_memory: 5   # include top 5 processes by memory
    
    - module: system
      period: 1m
      metricsets:
        - filesystem
        - fsstat
      processors:
      - drop_event.when.regexp:
          system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib)($|/)'
    
    - module: system
      period: 15m
      metricsets:
        - uptime
    
    #- module: system
    #  period: 5m
    #  metricsets:
    #    - raid
    #  raid.mount_point: '/'

     现在我们要收集nginx的指标信息需要开启对nginx的配置

    #启用redis module
    ./metricbeat modules enable nginx
    #修改redis module配置
    vim modules.d/nginx.yml
    # Module: nginx
    # Docs: https://www.elastic.co/guide/en/beats/metricbeat/6.5/metricbeat-modulenginx.html
    - module: nginx
    #metricsets:
    # - stubstatus
    period: 10s
    # Nginx hosts
    hosts: ["http://192.168.40.133"]
    # Path to server status. Default server-status
    server_status_path: "nginx-status"
    #username: "user"
    #password: "secret"

    开启nginx之后,我们可以使用命令metricbeat modules list 查看当前启用了哪些moudles

    接下来我们修改modules.d/nginx.yml

     内容如下

    # Module: nginx
    # Docs: https://www.elastic.co/guide/en/beats/metricbeat/6.5/metricbeat-module-nginx.html
    
    - module: nginx
      #metricsets:
      #  - stubstatus
      period: 10s
    
      # Nginx hosts
      hosts: ["http://127.0.0.1:8088"]
      server_status_path: "nginx-status"
    
      # Path to server status. Default server-status
      #server_status_path: "server-status"
    
      #username: "user"
      #password: "secret"

    接下来我们就可以启动metricbeat.exe收集nginx的指标了

    metricbeat -e -c metricbeat.yml

    2、让收集的度量信息在kibana上展示

    1、第一步需要修改metricbeat.yml配置

    metricbeat.config.modules:
      # Glob pattern for configuration loading
      path: ${path.config}/modules.d/*.yml
    
      # Set to true to enable config reloading
      reload.enabled: false
    
      # Period on which files under path should be checked for changes
      #reload.period: 10s
    
    #==================== Elasticsearch template setting ==========================
    
    setup.template.settings:
      index.number_of_shards: 2
      index.codec: best_compression
      #_source.enabled: false
    
    
    setup.kibana:
      host: "127.0.0.1:5601"
    
    output.elasticsearch:
      # Array of hosts to connect to.
      hosts: ["127.0.0.1:9200","127.0.0.1:9201","127.0.0.1:9202"]
    
    
    
    processors:
      - add_host_metadata: ~
      - add_cloud_metadata: ~

     1、在这里指定kibana的地址

    setup.kibana:
    host: "127.0.0.1:5601"

    2、文件配置好之后

    #安装仪表盘到Kibana 执行命令/metricbeat setup --dashboards,这里一定要保证kibana已经处于正常的启动状态


    安装成功之后我们在kibana上面就可以看到对于的仪表盘信息了

  • 相关阅读:
    mac sourceTree 每次操作提示需要密码
    docker-compose.yml开机启动
    详解Oracle 21c 中的只读Oracle主⽬录特性 (ROOH)
    使用kubeadm一键部署kubernetes集群
    Ubuntu18.04 开机自启动(需要 sudo 权限)
    nginx加载vue3 打包后的静态文件
    使用Docker搭建Nextcloud SSL站点
    Docker+Selenium+TestNG+Maven+Jenkins环境搭建
    Windows Server 2016安装AD并开启SSL
    Centos 环境配置内网 Yum 源
  • 原文地址:https://www.cnblogs.com/kebibuluan/p/12201029.html
Copyright © 2011-2022 走看看