我有以下数据:ip标识的每个服务实例的计数器。
ribbon_rule_count_total{way="round_robin",service="order_server",ip="101.141.108.119"} 109056
ribbon_rule_count_total{way="round_robin",service="order_server",ip="101.141.108.120"} 109057
ribbon_rule_count_total{way="round_robin",service="order_server",ip="101.141.108.121"} 109056
ribbon_rule_count_total{way="round_robin",service="user_server",ip="101.136.34.198"} 109056
ribbon_rule_count_total{way="round_robin",service="user_server",ip="101.136.34.197"} 109056
我要显示每个IP相对于服务的指标的比例,如下所示。
order_server-101.141.108.119 33%
order_server-101.141.108.120 33%
order_server-101.141.108.121 33%
user_server-101.136.34.198 50%
user_server-101.136.34.197 50%
答案 0 :(得分:0)
为了计算服务上每个ip指标的百分比,您需要:
sum忽略ip的指标
sum(ribbon_rule_count_total) without(ip)
这将为您提供指标:
ribbon_rule_count_total{way="round_robin",service="order_server"} 318269
ribbon_rule_count_total{way="round_robin",service="user_server"} 218112
能够使用one to many个匹配表达式来划分每个指标
ribbon_rule_count_total / ignoring(ip) group_left sum(ribbon_rule_count_total) without(ip)
这应该给您您所期望的问题-加上百分比值。
100 * ribbon_rule_count_total / ignoring(ip) group_left sum(ribbon_rule_count_total) without(ip)
对于计算而言,这应该足够了。如果您确实想要一个类似于您的示例的显示,可以join the labels:
avg(label_join(<precedent expression>, name, "-", service, ip)) by (name)