code: def resources_by_state(info) -> dict:
      res = raw_metrics(info)
      if "ray_resources" in res:
          states = defaultdict(int)
          for sample in res["ray_resources"]:
              state = sample.labels["State"]
              name = sample.labels["Name"]
              states[(name, state)] += sample.value
              if states[(name, state)] == 0:
                  del states[(name, state)]
          print("Resources by state: {}".format(states))
          return states
      else:
          return {}
  
file_path: ray/python/ray/tests/test_resource_metrics.py
imports: from collections import defaultdict
  import os
  import pytest
  import ray
  from ray._private.test_utils import fetch_prometheus_metrics, run_string_as_driver_nonblocking, wait_for_condition
label_desc: Use image node_id 2 for calling a global function with example usage: resources_by_state(info) and returns: states, dict