grafana绘图之数字映射字符串
序言问题
我们大家都知道prometheus存储的值是int或者float类型的,那么由于监控展现的需要如何把这些数字类型类型的字符映射成字符串呢?
接下来我就以elasticsearch集群的监控状态为例给大家讲解,首先看一下效果图
绘图
首先是一个状态图singlestat
表达式metrics:
elasticsearch_cluster_health_status{cluster="gt-devops-es",color="red"}==1 or (elasticsearch_cluster_health_status{cluster="gt-devops-es",color="green"}==1)+4 or (elasticsearch_cluster_health_status{cluster="gt-devops-es",color="yellow"}==1)+2
说明:这个表达式是如果集群状态返回1是red状态、5是green状态、3是yellow状态
此表达式只返回一个值
此时可以思维打开一下3个值的监控如何在表达式中只展示一个值
值的映射
值的映射使用Value Mappings
1映射到red字符串、3映射到yellow字符串、5映射到green字符串