zoukankan      html  css  js  c++  java
  • Grafana分析Nginx日志

    按日期对ES的index进行分割:

    logstash配置:

    input{
      file{
        path => "/home/hottopic/logs/trend-shotting-api/metric/*"
        type => "trend-shotting-api-metric"
        start_position => "beginning"
        codec => json {
                charset => "UTF-8"
            }
      }
    }
    
    output{
      if [type] == "trend-shotting-api-metric" {
        elasticsearch {
        hosts=> ["172.17.213.60:9200"]
        index=> "trend-shotting-api-metrick.%{+YYYY-MM}"
        }
      }
    }

    grafana源配置:(注意日期格式要统一,比如YYYY-MM或YYYY.MM)


    配置Groub by -Terms时报错,提示需要设置fielddata=true,报错内容大概如下: 

    "Fielddata is disabled on text fields by default ... "

    解决方法如下:

    https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html#_fielddata_is_disabled_on_literal_text_literal_fields_by_default

    curl -X PUT "localhost:9200/nginx/_mapping/doc" -H 'Content-Type: application/json' -d'
    {
      "properties": {
        "xforward": { 
          "type":     "text",
          "fielddata": true
        }
      }
    }
    '

    操作后仍然报错,于是

    curl -X PUT "localhost:9200/nginx/_mapping/doc?update_all_types" -H 'Content-Type: application/json' -d'         
    {
      "properties": {
        "xforward": { 
          "type":     "text",
          "fielddata": true
        }
      }
    }
    '

    以上nginx为index名称  xforward为字段名称。

    修改完后查看结果显示已修改成功

     返回到Grafana进行再一次设置

    修改成功后,可以正常出图。

  • 相关阅读:
    composer使用git作为仓储
    monolog记录日志
    lumen laravel response对象返回数据
    lumen中间件 Middleware
    AcWing 901. 滑雪
    leetcode 34. 在排序数组中查找元素的第一个和最后一个位置
    acwing 902. 最短编辑距离
    ACWING 844. 走迷宫
    leetcode 5199. 交换字符串中的元素
    AcWing 836. 合并集合
  • 原文地址:https://www.cnblogs.com/wjoyxt/p/9231063.html
Copyright © 2011-2022 走看看