code: def monitor_instances(app) -> None:
      driver: CloudDriver = app["driver"]
      inst_coll_manager = driver.inst_coll_manager
      resource_rates = driver.billing_manager.resource_rates
  
      for inst_coll in inst_coll_manager.name_inst_coll.values():
          total_free_schedulable_cores = 0.0
          total_free_cores = 0.0
          total_cores = 0.0
          total_cost_per_hour = 0.0
          total_revenue_per_hour = 0.0
          instances_by_state: Dict[str, int] = defaultdict(int)
  
          for instance in inst_coll.name_instance.values():
              if instance.state == "active":
                  total_free_schedulable_cores += (
                      instance.free_cores_mcpu_nonnegative / 1000
                  )
              if instance.state != "deleted":
                  total_free_cores += (
                      instance.free_cores_mcpu_nonnegative / 1000
                  )
                  total_cores += instance.cores_mcpu / 1000
                  total_cost_per_hour += instance.cost_per_hour(
                      resource_rates
                  )
                  total_revenue_per_hour += instance.revenue_per_hour(
                      resource_rates
                  )
                  INSTANCE_CORE_UTILIZATION.labels(
                      inst_coll=inst_coll.name
                  ).observe(instance.percent_cores_used)
  
              instances_by_state[instance.state] += 1
  
          FREE_CORES.labels(inst_coll=inst_coll.name).set(
              total_free_cores
          )
          FREE_SCHEDULABLE_CORES.labels(inst_coll=inst_coll.name).set(
              total_free_schedulable_cores
          )
          TOTAL_CORES.labels(inst_coll=inst_coll.name).set(total_cores)
          COST_PER_HOUR.labels(
              inst_coll=inst_coll.name, measure="actual"
          ).set(total_cost_per_hour)
          COST_PER_HOUR.labels(
              inst_coll=inst_coll.name, measure="billed"
          ).set(total_revenue_per_hour)
          for state, count in instances_by_state.items():
              INSTANCES.labels(
                  inst_coll=inst_coll.name, state=state
              ).set(count)
  
imports: import asyncio
  import copy
  import json
  import logging
  import os
  import re
  import signal
  import warnings
  from collections import defaultdict, namedtuple
  from contextlib import AsyncExitStack
  from functools import wraps
  from typing import Any, Awaitable, Callable, Dict, NoReturn, Set, Tuple
  import aiohttp_session
  import dictdiffer
  import kubernetes_asyncio.client
  import kubernetes_asyncio.config
  import pandas
  import plotly
  import plotly.graph_objects
  import prometheus_client
  import uvloop
  from aiohttp import web
  from plotly.subplots import make_subplots
  from prometheus_async.aio.web import server_stats
  from gear import AuthServiceAuthenticator, Database, K8sCache, Transaction, check_csrf_token, json_request, json_response, monitor_endpoints_middleware, setup_aiohttp_session, transaction
  from gear.auth import AIOHTTPHandler, UserData
  from gear.clients import get_cloud_async_fs
  from gear.profiling import install_profiler_if_requested
  from hailtop import aiotools, httpx
  from hailtop.config import get_deploy_config
  from hailtop.hail_logging import AccessLogger
  from hailtop.utils import AsyncWorkerPool, Notice, dump_all_stacktraces, flatten, periodically_call, time_msecs
  from web_common import render_template, set_message, setup_aiohttp_jinja2, setup_common_static_routes
  from ..batch import cancel_batch_in_db
  from ..batch_configuration import BATCH_STORAGE_URI, CLOUD, DEFAULT_NAMESPACE, MACHINE_NAME_PREFIX, REFRESH_INTERVAL_IN_SECONDS
  from ..cloud.driver import get_cloud_driver
  from ..cloud.resource_utils import local_ssd_size, possible_cores_from_worker_type, unreserved_worker_data_disk_size_gib
  from ..exceptions import BatchUserError
  from ..file_store import FileStore
  from ..globals import HTTP_CLIENT_MAX_SIZE
  from ..inst_coll_config import InstanceCollectionConfigs, PoolConfig
  from ..utils import add_metadata_to_request, authorization_token, json_to_value, query_billing_projects_with_cost
  from .canceller import Canceller
  from .driver import CloudDriver
  from .instance import Instance
  from .instance_collection import InstanceCollectionManager, JobPrivateInstanceManager, Pool
  from .job import mark_job_complete, mark_job_started
label_desc: Use image node_id 10 for calling a global function with example usage: monitor_instances(app) without return types