带有 Elasticsearch 的 Grafana - 设置按平均值分组时不显示数据
Grafana with Elasticsearch - Does not show data when setting Group By Average
使用 Grafana 7.2 和 Elasticsearch 7.5.1。
一切正常,运行 在 Openshift 中。 Elasticsearch 数据源已正确配置并创建了一个非常简单的仪表板。
在 Openshift 中也从 Springboot 服务 运行 我正在使用 Fluentd 将日志发送到 Elasticsearch。
Elasticsearch中存储的文档是这样的(取自Grafana“Logs”结果面板):
已编辑:按照@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 文档,这是我想要作为仪表板基础的文档。
此时请注意两件事:
- 红色标注的字段:executionTime.
- _source 字段只有一个 [object Object] 值。
问题 1:
我需要做的(但我没有得到)是棘手的部分:我需要得到一个直方图,显示每个时间间隔的 executionTime 字段值的平均值。
根据官方文档,特别是 this official video from Grafana,我应该能够将 de Group By 字段更改为 Average 并从字段 selector 更改为 select @value。不幸的是,@value 值并没有出现在那里(_source = [object Object]
字段可能有事要做吗?)
问题 2:
另一个疑问是查询字段在该格式下是否有效,或者访问消息中的executionTime字段的方式是什么 Elasticsearch 文档中的字段。在某种层次结构中 message -> onpay -> executionTime
.
Fluentd 配置文件:
<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 作为消息字段中的字符串。因此 Elastic 无法对其应用任何数学运算。您需要做的是使用 fluentd 将日志行解析为 json 因此在 Elastic 文档中 json 中的每个字段(如记录器和级别)都是弹性文档的一部分。
一旦你有了 Elastic,大多数情况下会自动将 executionTime 解释为数字,并使其可用于聚合。之后,您将在 Grafana 下拉列表中看到该字段。
Here你可以在_source字段上了解更多。
将您的原始日志行也添加到问题中,我认为这可能有助于理解您想要摄取的内容,因此可以就可能的 fluentd 配置提出建议。
根据提供的附加信息更新了答案
为简单起见,我使用 docker 设置 运行 并解析问题中提供的日志模式。
流畅配置
我使用了 HTTP 输入,所以它允许我卷曲,但你可以切换回转发器。
我已经删除了过滤器,因为我假设您的来源已经是 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 的一个节点。我已经有了这个设置 运行ning.
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 -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/
弹性搜索结果
一旦您像这样获取了所有 json 键,Elastic 将 auto-map 大多数字段并允许根据字段类型进行搜索、聚合等。如果需要,您可以从 kibana 索引管理更改字段类型和格式。
使用 Grafana 7.2 和 Elasticsearch 7.5.1。
一切正常,运行 在 Openshift 中。 Elasticsearch 数据源已正确配置并创建了一个非常简单的仪表板。
在 Openshift 中也从 Springboot 服务 运行 我正在使用 Fluentd 将日志发送到 Elasticsearch。
Elasticsearch中存储的文档是这样的(取自Grafana“Logs”结果面板):
已编辑:按照@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 文档,这是我想要作为仪表板基础的文档。 此时请注意两件事:
- 红色标注的字段:executionTime.
- _source 字段只有一个 [object Object] 值。
问题 1:
我需要做的(但我没有得到)是棘手的部分:我需要得到一个直方图,显示每个时间间隔的 executionTime 字段值的平均值。
根据官方文档,特别是 this official video from Grafana,我应该能够将 de Group By 字段更改为 Average 并从字段 selector 更改为 select @value。不幸的是,@value 值并没有出现在那里(_source = [object Object]
字段可能有事要做吗?)
问题 2:
另一个疑问是查询字段在该格式下是否有效,或者访问消息中的executionTime字段的方式是什么 Elasticsearch 文档中的字段。在某种层次结构中 message -> onpay -> executionTime
.
Fluentd 配置文件:
<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 作为消息字段中的字符串。因此 Elastic 无法对其应用任何数学运算。您需要做的是使用 fluentd 将日志行解析为 json 因此在 Elastic 文档中 json 中的每个字段(如记录器和级别)都是弹性文档的一部分。 一旦你有了 Elastic,大多数情况下会自动将 executionTime 解释为数字,并使其可用于聚合。之后,您将在 Grafana 下拉列表中看到该字段。
Here你可以在_source字段上了解更多。
将您的原始日志行也添加到问题中,我认为这可能有助于理解您想要摄取的内容,因此可以就可能的 fluentd 配置提出建议。
根据提供的附加信息更新了答案
为简单起见,我使用 docker 设置 运行 并解析问题中提供的日志模式。
流畅配置
我使用了 HTTP 输入,所以它允许我卷曲,但你可以切换回转发器。 我已经删除了过滤器,因为我假设您的来源已经是 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 的一个节点。我已经有了这个设置 运行ning.
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 -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/
弹性搜索结果
一旦您像这样获取了所有 json 键,Elastic 将 auto-map 大多数字段并允许根据字段类型进行搜索、聚合等。如果需要,您可以从 kibana 索引管理更改字段类型和格式。