简体   繁体   English

logql 中 splunk eval 的替代品是什么?

[英]what is the substitute of splunk eval in logql?

I have this expression in my splunk query eval A = A + '/' + B where A is the new variable (column name) to which I am assigning the values of A and B from my log line and I need to replace the same expression in loki grafana using logql.我在我的 splunk 查询 eval A = A + '/' + B 中有这个表达式,其中 A 是我从日志行中分配 A 和 B 的值的新变量(列名),我需要替换相同使用 logql 在 loki grafana 中表达。 Right now I am just getting two columns Time and {}.现在我只得到两列时间和{}。 I want to replaace TIme column with eval expression.我想用 eval 表达式替换 TIME 列。 Can someone please help me on this?有人可以帮我吗?

The equivalent of variables in LogQL are labels. LogQL 中的变量等价物是标签。

Thus, you can use label_format to achieve what you want.因此,您可以使用label_format来实现您想要的。

Here is an example of how to use label_format to perform a string concatenation of two labels, named var_a and var_b :这是一个如何使用label_format执行两个标签的字符串连接的示例,名为var_avar_b

Input:输入:

{"var_a": "a", "var_b": "b", "message": "hello there!"}

LogQL query : LogQL 查询

{service="my-awesome-app"}
  | json # or logfmt, depending on your log format
  | label_format var_a=`{{.var_a}}/{{.var_b}}` # this reassigns var_a based on the given template

Output: Output:

{"var_a": "a/b", "var_b": "b", "message": "hello there!"}

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

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