zoukankan      html  css  js  c++  java
  • 运用Filebeat module分析nginx日志

    在同一台主机上事先安装好filebeat,elasticsearch和kibana

    filebeat配置

    安装完Filebeat后,可以看到在Filebeat的安装目录下有一个叫做filebeat.yml的配置文件,还有一个叫做modules.d的文件夹。在filebeat.yml中,我们做如下的修改:

    setup.kibana:
      host: "localhost:5601"
     
    output.elasticsearch:
      hosts: ["localhost:9200"]
    

    注意:filebeat.yml文件中的其他配置不需要修改

    拓展:
    显示Filebeat支持的模块:./filebeat modules list
    启动某一个模块:./filebeat modules enable 模块名
    关闭某一个模块:./filebeat modules disenable 模块名

    启动nginx模块:./filebeat modules enable nginx

    查看在modules.d目录下的文件变化,可以看到nginx.yml文件的最后没有“disabled”字样,表明它已经被启动成功。我们进一步编辑这个nginx.yml文件:

    # Module: nginx
    # Docs: https://www.elastic.co/guide/en/beats/filebeat/7.3/filebeat-module-nginx.html
     
    - module: nginx
      # Access logs
      access:
        enabled: true
     
        # Set custom paths for the log files. If left empty,
        # Filebeat will choose the paths depending on your OS.
        var.paths: ["/usr/local/src/nginx_log_file/nginx.log"] # 根据nginx日志所在路径实际修改
     
      # Error logs
      error:
        enabled: true
     
        # Set custom paths for the log files. If left empty,
        # Filebeat will choose the paths depending on your OS.
        #var.paths: ["/var/log/nginx/error.log"]
    

    为了能够使得我们的nginx模块能够正确地被Kibana显示,我们必须运行如下的命令:

    [root@bogon filebeat-7.5.0-linux-x86_64]# ./filebeat setup
    Index setup finished.
    Loading dashboards (Kibana must be running and reachable)
    Loaded dashboards
    Loaded machine learning job configurations
    Loaded Ingest pipelines
    

    注意:在安装或升级Filebeat时,或在启用新模块后,必须执行setup命令

    运行:./filebeat -e

    已经通过./filebeat setup命令,把针对nginx的模块仪表盘导入到Kibana中了。就可以使用标准的dashboard来对nginx数据进行展示及分析。

    这里的filebeat-7.5.0是一个alias,它指向我们刚被创建的一个index,比如filebeat-7.5.0-2020.05.08-000001。

    在这里显示的数据是10,000,其实这不是一个真实的文档的数目。
    这里要注意的一件事是响应中的hits.total。 它具有10,000和“ relation” =“ gte”的值。 索引中实际上有984,887个文档,我们已经创建了全部。 在7.0版发布之前,hits.total始终用于表示符合查询条件的文档的实际数量。 在Elasticsearch 7.0版中,如果匹配数大于10,000,则不会计算hits.total。 这是为了避免为给定查询计算精确匹配文档的不必要开销。 我们可以通过将track_total_hits = true作为请求参数来强制进行精确匹配的计算。

  • 相关阅读:
    asp.net 中的viewstate用法?
    .net中 过滤 指定 字符串
    js中replace的用法
    restart
    外部函数
    JQuery实现Ajax 根据商品名称自动显示价格
    ListView中命令行按钮应用;
    GridView中获取行数和列数
    全局应用程序类Global
    如何获取gridview中模板列中控件的值?
  • 原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/12849236.html
Copyright © 2011-2022 走看看