如何使用logql对字符串进行切片?
我的 grafana loki 日志中有类似于此
数据的值 1234-02-01,12:30,1 data 1234-03-02,11:30,12
我可以使用 trunc 对这些值进行切片并从中分离日期和时间,但我似乎不会对最后一个值执行此操作,因为它可以是一位数或两位数。
我用过这个:-
date= {{.data | trunc 10 }} 时间= {{.data |截断-10 |截断 8}} val= {{.data | trunc -1}}
这给了我
日期 1234-03-02 、 1234-02-01
时间 12:30 、 11:30
val 1 , 2
最后一个 val 总是给出最后一位数字,所以如果我想获取 12 它只会给我 2 。我该怎么做才能获取时间和逗号后的整个数字。因此,如果是个位数,则需要 1;如果是两位数,则需要 12;如果是三位数,则需要 123,依此类推。我希望这是有道理的。有人可以帮我吗?
I have values in my logs in grafana loki something like this
data 1234-02-01,12:30,1
data 1234-03-02,11:30,12
I am able to slice these values and separate date and time from this using trunc but I don't seem to do for the last value because it could be either single digit or double digit.
I used this:-
date= {{.data | trunc 10 }} time= {{.data | trunc -10 | trunc 8}} val= {{.data | trunc -1}}
this gives me
date 1234-03-02 , 1234-02-01
time 12:30 , 11:30
val 1 , 2
last val always give the last digit, so if I want to fetch 12 it will only give me 2 . What can I do to fetch the entire digit after time and comma. So I want 1 if its a single digit and 12 if its a double digit and 123 if its a three digit and so on. I hope this makes sense. Can someone please help me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 模式解析器
这行:
data 1234-02-01,12:30,1
,查询可能如下所示:try to use patter parser
for this line:
data 1234-02-01,12:30,1
, the query might look like: