0

I have two queries:

max(pg_database_pg_database_size{instance=~"rds_db1"}) by (instance, kubernetes_namespace)
max(aws_rds_free_storage_space_average{dbinstance_identifier=~"rds_db1"}) by (dbinstance_identifier, kubernetes_namespace)

I want to add those queries together, but the name of the instance labels are different. How can I do it?

I am able to do it if I remove the labels:

max (aws_rds_free_storage_space_average{dbinstance_identifier=~"rds_db1"}) + max(pg_database_pg_database_size{instance=~"rds_db1"})

But I want one of the labels, either dbinstance_identifier or instance, and kubernetes_namespace, which is common to both queries.

Homer
  • 85
  • 7
  • You can use label_replace; see https://stackoverflow.com/a/54833182/13963086 – k314159 Sep 21 '21 at 11:23
  • @k314159 It works without adding. With max (label_replace(aws_rds_free_storage_space_average{dbinstance_identifier=~"rds_db1"},"instance","$1","dbinstance_identifier", "(.+)")) by (instance, kubernetes_namespace) The label gets replaced successfully. But when I try to do: max (label_replace(aws_rds_free_storage_space_average{dbinstance_identifier=~"rds_db1"},"instance","$1","dbinstance_identifier", "(.+)")) by (instance, kubernetes_namespace) + max(pg_database_pg_database_size{instance=~"rds_db1"}) by (instance, kubernetes_namespace) It shows empty query result. – Homer Sep 21 '21 at 11:52

0 Answers0