简体   繁体   English

Grafana 在 Elasticsearch 数据源中使用两个字段相减

[英]Grafana to use substraction of two fields in Elasticsearch data source

  1. I have two fields, called 'status_codes' and requests我有两个字段,称为“status_codes”和请求
  2. I want to get number of failed requests.我想获取失败请求的数量。
  3. My equation is [requests - no of success requests]我的等式是 [请求 - 没有成功请求]
  4. In the script i wrote something like this _value - doc['@status_codes.200'].value在脚本中,我写了这样的 _value - doc['@status_codes.200'].value

BUT the value return in the graph is 'N/A'但图中的返回值是“N/A”

I'm using elasticsearch(7.6.0) and Grafana(6.6.2).我正在使用 elasticsearch(7.6.0) 和 Grafana(6.6.2)。

Following is the out file which i'm sending to elasticsearch以下是我发送到elasticsearch的输出文件

{   "latencies":{
      "total":3981710268690,
      "mean":43876078,
      "50th":916913,
      "90th":2217744,
      "95th":5162430,
      "99th":60233348,
      "max":60000209373,
      "min":43652

},
   "@version":"1",
   "latest":"2020-03-05T16:14:44.23387091Z",
   "path":"test23.json",
   "duration":61163899322,
   "wait":552109,
   "status_codes":{
      "0":90624,
      "200":125

},
   "earliest":"2020-03-05T16:13:43.069971588Z",
   "rate":1483.702004057131,
   "throughput":2.0436707446156577,
   "@timestamp":"2020-03-05T16:14:44.453Z",
   "errors":[
      "Post http://www: dial tcp 0.0.0.0:0->10.133.9.87:8688: socket: too many open files",
      "Post http://www: dial tcp: lookup internal-netty-load-balancer-937469711.us-east-1.elb.amazonaws.com on 10.20.30.30: dial udp 10.20.30:45: socket: too many open files"

],
   "bytes_in":{
      "mean":70.90298515686123,
      "total":6434375

},
   "requests":90749,
   "Report_Title":"test23",
   "host":"ABS",
   "success":0.0013774256465635985,
   "end":"2020-03-05T16:14:44.234423019Z",
   "bytes_out":{
      "mean":70.90298515686123,
      "total":6434375

}
}

Also I have used Singlestat plugin as @yash mentioned, but still i could resolve the issue.我也像@yash 提到的那样使用了 Singlestat 插件,但我仍然可以解决这个问题。 Query section查询部分

Visualization section可视化部分

Can someone help me有人能帮我吗

This is a fairly easy task.这是一项相当容易的任务。 You just need to use either of the 'Singlestat Math' or 'Metaqueries' plugin for that.您只需要为此使用“Singlestat Math”或“Metaqueries”插件。 What you need to do is, use the count metric in two queries in the same panel, one for getting the count of successful status codes, and other for unsuccessful status codes.您需要做的是,在同一个面板中的两个查询中使用计数指标,一个用于获取成功状态代码的计数,另一个用于获取不成功的状态代码。 Then you can use either of the plugin to subtract the value of result of query one query from another.然后,您可以使用任一插件从另一个查询中减去查询结果的值。

https://grafana.com/grafana/plugins/blackmirror1-singlestat-math-panel https://grafana.com/grafana/plugins/goshposh-metaqueries-datasource https://grafana.com/grafana/plugins/blackmirror1-singlestat-math-panel https://grafana.com/grafana/plugins/goshposh-metaqueries-datasource

I suggest you go with the singlestat math plugin, it would be easier to work with, from my experience.我建议你使用 singlestat 数学插件,根据我的经验,它会更容易使用。 Note: The calculation (AB) is done in the visualization section and not in query section, in the singlestat math plugin.注意:计算 (AB) 在可视化部分完成,而不是在查询部分,在 singlestat 数学插件中。

PS singlestat-math plugin actually adds a new panel in the visualization section. PS singlestat-math 插件实际上在可视化部分添加了一个新面板。 It's a different panel than the default singlestat panel.它与默认的 singlestat 面板不同。

Finally I found the the solution as follow,最后我找到了解决方案如下,

solution解决方案

Thanks everyone.谢谢大家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM