elasticsearch - Grafana与Elasticsearch-设置按平均值分组时不显示数据

标签 elasticsearch logstash grafana fluentd

使用Grafana 7.2和Elasticsearch 7.5.1。
一切都已在Openshift中启动并运行。 Elasticsearch数据源已正确配置,并创建了一个非常简单的仪表板。
通过也在Openshift中运行的Springboot服务,我正在使用Fluentd将日志发送到Elasticsearch。
存储在Elasticsearch中的文档是这样的(取自Grafana“日志”结果面板):
enter image description here
编辑:按照@karan shah的建议,我添加了通过Fluentd发送到Elastichsearch的原始日志:

{
   "onpay":{
      "traceId":"9999",
      "inout":"OUT",
      "startTime":"2020-10-01T10:13:43.806+0200",
      "finishTime":"2020-10-01T10:13:43.827+0200",
      "executionTime":21.0,
      "entrySize":124.0,
      "exitSize":124.0,
      "differenceSize":0.0,
      "user":"pgallello",
      "methodPath":"http://localhost:8083/api/serviceEntryPoint",
      "errorMessage":null,
      "className":"com.myorganization.mypackage.MyController",
      "methodName":"serviceTemplateEntryPoint"
   }
}
这是一个Elasticsearch文档,其中包含“消息”字段,这是我要在其仪表板中建立的文档。
此时注意两件事:
  • 用红色标记的字段: executeTime
  • 字段_source仅具有[object Object]值。

  • 问题一:
    我需要做的(但我没有得到)是棘手的部分:我需要获得一个直方图,该直方图显示每个时间间隔的executeTime字段的平均值。
    按照官方文档,尤其是this official video from Grafana,我应该能够将de Group By字段更改为Average并从字段选择器中选择@value。不幸的是,该@value值未出现在其中(可以在_source = [object Object]字段中做些事吗?)
    enter image description here
    问题2:
    另一个疑问是“查询”字段在该格式下是否有效,或者以什么方式访问位于Elasticsearch文档内消息字段内的executionTime 字段。在一种层次结构message -> onpay -> executionTime中。
    流利的配置文件:
      <source>
        @type forward
        port 24224
        bind "0.0.0.0"
      </source>
      <filter onpayapp.**>
        @type parser
        key_name "onpayapp"
        reserve_data true
        <parse>
          @type "json"
        </parse>
      </filter>
      <match onpay.**>
        @type copy
        <store>
          @type "elasticsearch"
          host "elasticdb"
          port 9200
          logstash_format true
          logstash_prefix "applogs"
          logstash_dateformat "%Y%m%d"
          include_tag_key true
          type_name "app_log"
          tag_key "@log_name"
          flush_interval 1s
          <parse>
            @type json
          </parse>
          <buffer>
            flush_interval 1s
          </buffer>
        </store>
        <store>
          @type "stdout"
        </store>
      </match>
    

    最佳答案

    当前,您所拥有的是整个json,作为message字段中的字符串。因此,Elastic将无法对其应用任何数学运算。您需要做的是使用fluentd将日志行解析为json,因此在Elastic文档中,该json中的每个字段(例如logger和level)都是Elastic文档的一部分。
    一旦有了 flex ,Elastic就会自动将执行时间解释为数字并将其用于聚合。之后,您将在Grafana下拉列表中看到该字段。
    Here您可以在_source字段上了解更多信息。
    将原始日志行也添加到问题中,我认为这可能有助于了解您要摄取的内容,因此可以对可能的流利配置提出建议。
    根据提供的其他信息更新了答案
    为简单起见,我使用docker setup运行并解析问题中提供的日志模式。
    Fluentd配置
    我使用了HTTP输入,因此可以 curl ,但可以切换回转发器。
    我已删除过滤器,因为我假设您的源已经是JSON,因此您无需将其解析为JSON。
    如果您通过管道处理了多种类型的数据,则可以重新添加匹配模式。

     <source>
        @type http
        port 9880
        bind 0.0.0.0
      </source>
      <match *>
        @type copy
        <store>
          @type "elasticsearch"
          host "es01"
          port 9200
          logstash_format true
          logstash_prefix "applogs"
          logstash_dateformat "%Y%m%d"
          include_tag_key true
          type_name "app_log"
          tag_key "@log_name"
          flush_interval 1s
          <parse>
            @type json
          </parse>
          <buffer>
            flush_interval 1s
          </buffer>
        </store>
        <store>
          @type "stdout"
        </store>
      </match>
    
    流利的Docker镜像
    # fluentd/Dockerfile
    FROM fluent/fluentd:v1.11-debian-1
    
    USER root
    
    RUN touch ~/.gemrc
    RUN echo ':ssl_verify_mode: 0' >> ~/.gemrc
    
    RUN buildDeps="sudo make gcc g++ libc-dev" \
     && apt-get update \
     && apt-get install -y --no-install-recommends $buildDeps \
     && sudo gem install fluent-plugin-elasticsearch \
     && sudo gem sources --clear-all \
     && SUDO_FORCE_REMOVE=yes \
        apt-get purge -y --auto-remove \
                      -o APT::AutoRemove::RecommendsImportant=false \
                      $buildDeps \
     && rm -rf /var/lib/apt/lists/* \
     && rm -rf /tmp/* /var/tmp/* /usr/lib/ruby/gems/*/cache/*.gem
    
    
    USER fluent
    
    Docker撰写
    您可以选择仅运行elasticsearch的一个节点。我已经在运行此设置。
    services:
      es01:
        image: docker.elastic.co/elasticsearch/elasticsearch:7.8.0
        container_name: es01
        environment:
          - node.name=es01
          - cluster.name=es-docker-cluster
          - discovery.seed_hosts=es02,es03
          - cluster.initial_master_nodes=es01,es02,es03
          - bootstrap.memory_lock=true
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - data01:/usr/share/elasticsearch/data
        ports:
          - 9200:9200
        networks:
          - elastic
        healthcheck:
          interval: 20s
          retries: 10
          test: curl -s http://localhost:9200/_cluster/health | grep -vq '"status":"red"'
    
      es02:
        image: docker.elastic.co/elasticsearch/elasticsearch:7.8.0
        container_name: es02
        environment:
          - node.name=es02
          - cluster.name=es-docker-cluster
          - discovery.seed_hosts=es01,es03
          - cluster.initial_master_nodes=es01,es02,es03
          - bootstrap.memory_lock=true
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - data02:/usr/share/elasticsearch/data
        ports:
          - 9201:9200
        networks:
          - elastic
        healthcheck:
          interval: 20s
          retries: 10
          test: curl -s http://localhost:9201/_cluster/health | grep -vq '"status":"red"'
    
      es03:
        image: docker.elastic.co/elasticsearch/elasticsearch:7.8.0
        container_name: es03
        environment:
          - node.name=es03
          - cluster.name=es-docker-cluster
          - discovery.seed_hosts=es01,es02
          - cluster.initial_master_nodes=es01,es02,es03
          - bootstrap.memory_lock=true
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - data03:/usr/share/elasticsearch/data
        ports:
          - 9202:9200
        networks:
          - elastic
        healthcheck:
          interval: 20s
          retries: 10
          test: curl -s http://localhost:9202/_cluster/health | grep -vq '"status":"red"'
    
      kib01:
        image: docker.elastic.co/kibana/kibana:7.8.0
        container_name: kib01
        ports:
          - 5601:5601
        environment:
          ELASTICSEARCH_URL: http://es01:9200
          ELASTICSEARCH_HOSTS: http://es01:9200
        networks:
          - elastic
        healthcheck:
          interval: 10s
          retries: 20
          test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:5601/api/status
      
      fluentd:
        build: ./fluentd
        volumes:
          - "./fluentd/conf/:/fluentd/etc/:ro"
        networks:
          - elastic
        ports:
          - "9880:9880"
    
    volumes:
      data01:
        driver: local
      data02:
        driver: local
      data03:
        driver: local
    
    networks:
      elastic:
        driver: bridge
    
    测试用的 curl
    curl -X POST -d 'json={    "onpay": {        "traceId": "9999",        "inout": "OUT",        "startTime": "2020-10-01T10:13:43.806+0200",        "finishTime": "2020-10-01T10:13:43.827+0200",        "executionTime": 21.0,        "entrySize": 124.0,        "exitSize": 124.0,        "differenceSize": 0.0,        "user": "pgallello",        "methodPath": "http://localhost:8083/api/serviceEntryPoint",        "errorMessage": null,        "className": "com.myorganization.mypackage.MyController",        "methodName": "serviceTemplateEntryPoint"    }}' http://localhost:9880/
    
    flex 搜索的结果
    ElasticSearch
    一旦您像这样摄取了所有的json键,Elastic将自动映射大多数字段,并允许根据字段类型进行搜索,聚合等。您可以根据需要从kibana索引管理中更改字段类型和格式。

    关于elasticsearch - Grafana与Elasticsearch-设置按平均值分组时不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64155317/

    相关文章:

    laravel - 字段 [_id] 是元数据字段,不能添加到文档中。使用索引 API 请求参数

    elasticsearch - 如何在从 API 返回之前过滤 _source?

    elasticsearch - 将Zabbix事件读取到Elastic Search

    linux - Docker容器无法从主机访问映射目录

    apache-spark - Spark Elasticsearch基本调整

    elasticsearch - 用于标记退回邮件的 Logstash grok 过滤器

    elasticsearch - 如何使用Logstash中要在Kibana中使用的JDBC输入插件将纬度和经度值映射到转换数据库的geo_point中?

    json - 如何为远程日志记录的异常错误配置 rsyslog 模板?

    histogram - 将 Grafana 直方图与 Prometheus Bucket 结合使用

    excel - 将 Azure Blob 存储连接到 Grafana