当前位置:网站首页>Splunk中single value视图使用将数值替换为文字
Splunk中single value视图使用将数值替换为文字
2022-07-07 05:19:00 【QYHuiiQ】
在splunk的single value视图中,之前我们一直使用的是直接根据值来展示颜色,也就是single value中用的是什么值,那么颜色的设置就是根据这个值来显示的,换言之,这个展示的值必须是设置颜色规则的值。而有些情况下我们可能只想展示一个指标的名称,然后根据这个指标的值设置颜色,也就是说将原来展示值改为展示指标名称,不展示具体的值,但是依然以这个值来设置颜色。
对于这种案例,我们的实现思路就是还是按照值来展示,最后再将这个值替换为指标名称(文本)。
假设原来的情况是这样的,当grade值大于60时显示绿色,小于等于60时,显示红色,注意这楼里我们的视图中是根据grade的值设置颜色,并将grade的值展示出来:
| makeresults
| eval grade="37"
| table grade

而我们现在要实现的需求是,将这个展示的值变为指标名称/文本,颜色规则依然不变。
如果我们使用replace进行替换最终显示的值,那么使用"格式"里设置的颜色规则自然也会失效,因为"格式"中的规则是在spl执行结束后才生效的,可以看一下这个测试:
| makeresults
| eval grade="37"
| table grade
| replace "37" with "Student Grade" in grade
因为最终的值被替换为文本了,所以这个数值类型的规则设置就失效了,最终展示的是灰色。
因此,我们需要使用的方法是使用Splunk官方提供的一个rangemap的命令来帮助我们设置颜色,然后再replace文本,实现方法如下:
| makeresults
| eval grade="37"
| rangemap field=grade low=61-100 severe=0-60 default=gray
#这里low和severe分别对应的是绿色和红色,这是Splunk官方默认的配置,可以参考官方文档中的其他使用案例。
#如果你要设置的颜色规则是具体的某个数值而不是范围,那么你可以设置为-前后数值相同,都设置为你要定义的那个数值即可。如:| rangemap field=grade low=60-60 severe=100-100 default=gray
此时需要注意将"格式"中的颜色禁用掉,因为我们是通过spl里的rangemap来设置颜色的。

设置好颜色后,开始替换展示的值:
| makeresults
| eval grade="87"
| rangemap field=grade low=61-100 severe=0-60 default=gray
| replace "87" with "Student Grade" in grade
#replace后面的第一个参数是被替换的值,with后面是替换后的值,in后面的是替换哪个字段里的值

此时视图中展示的值就变成了一个自定义的文本,而与颜色设置背后的值无关,需要注意的是replace后面的值是只当grade字段的值为"87"时才会替换,否则不会替换。

这里我只是对值的替换做一个示例,但是实际应用中replace的值可能时多样的,所以需要具体再根据业务调整逻辑。
以上就是通过rangemap和replace实现single value中的展示值替换,更多使用案例可以参考官方文档:
边栏推荐
- Complex network modeling (II)
- What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
- It took "7" years to build the robot framework into a micro service
- UnityHub破解&Unity破解
- The reified keyword in kotlin is used for generics
- 拓维信息使用 Rainbond 的云原生落地实践
- The largest 3 same digits in the string of leetcode simple question
- 提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
- opencv学习笔记五——梯度计算/边缘检测
- JS cross browser parsing XML application
猜你喜欢

What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit

LeetCode简单题之判断一个数的数字计数是否等于数位的值

Vulnerability recurrence easy_ tornado
![[quick start of Digital IC Verification] 11. Introduction to Verilog testbench (VTB)](/img/c2/32a2c1ede493b778a6c44077d765d0.png)
[quick start of Digital IC Verification] 11. Introduction to Verilog testbench (VTB)

JS复制图片到剪切板 读取剪切板

OpenVSCode云端IDE加入Rainbond一体化开发体系

Rainbond 5.7.1 支持对接多家公有云和集群异常报警

Qinglong panel - today's headlines

JS cross browser parsing XML application

Interactive book delivery - signed version of Oracle DBA work notes
随机推荐
Recursive method to construct binary tree from preorder and inorder traversal sequence
复杂网络建模(一)
在 Rainbond 中一键安装高可用 Nacos 集群
【踩坑系列】uniapp之h5 跨域的问题
Blob 對象介紹
积分商城管理系统中应包含的四大项
opencv学习笔记五——梯度计算/边缘检测
Interactive book delivery - signed version of Oracle DBA work notes
Network learning (I) -- basic model learning
Offer harvester: add and sum two long string numbers (classic interview algorithm question)
电池、电机技术受到很大关注,反而电控技术却很少被提及?
Excel import function of jeesite form page
Niu Mei's mathematical problem --- combinatorial number
Recursive construction of maximum binary tree
CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
LeetCode简单题之字符串中最大的 3 位相同数字
Easy to understand SSO
青龙面板-今日头条
Complete linear regression manually based on pytoch framework
[quick start of Digital IC Verification] 14. Basic syntax of SystemVerilog learning 1 (array, queue, structure, enumeration, string... Including practical exercises)