I'm trying to concatenate some metrics based on a parent label value in grafana.
I'm export some metrics for hypervisor like below :
vmware_host_num_cpu{cluster_name="cluster1",dc_name="datacenter1",host_name="node1"} 4.0
vmware_host_num_cpu{cluster_name="cluster1",dc_name="datacenter1",host_name="node2"} 2.0
vmware_host_num_cpu{cluster_name="cluster2",dc_name="datacenter1",host_name="node3"} 8.0
vmware_host_num_cpu{cluster_name="cluster3",dc_name="datacenter2",host_name="node4"} 2.0
In my example node1 and node2 are in the cluster1, node3 in the cluster2 and node4 in the cluster3. I have also some specifics metrics for cluster :
vmware_cluster_currentFailoverLevel{cluster_name="cluster1",dc_name="datacenter1",region="region1"} 1.0
vmware_cluster_currentFailoverLevel{cluster_name="cluster2",dc_name="datacenter1",region="region1"} 0.0
vmware_cluster_currentFailoverLevel{cluster_name="cluster3",dc_name="datacenter2",region="region2"} 0.0
In my example, cluster1 and cluster2 are in the region1 and cluster3 in the region2. Each hypervisor have a cluster_name label value. Each cluster have a region label value.
I would like get the sum value of vmware_host_num_cpu for all clusters in the same region based on the cluster_name of each hypervisor and the region label of cluster.
In my example, result should be :
Total num_cpu for region1 = 14.0
Total num_cpu for region2 = 2.0
Do you have an idea on how do that ? Thanks
sum by (region) (
vmware_host_num_cpu
+ on(cluster_name) group_left(region)
vmware_cluster_currentFailoverLevel * 0
)
It'd be cleaner if there was an info metric to do the join on.