Repository: ray-project/ray
File: python/ray/dashboard/modules/reporter/reporter_agent.py (Python)

Code before:
                        value=1,
                        tags=gpu_tags,
                    )
                    gpus_utilization_record = Record(
                        gauge=METRICS_GAUGES["node_gpus_utilization"],
                        value=gpus_utilization,
                        tags=gpu_tags,
                    )
                    gram_used_record = Record(
                        gauge=METRICS_GAUGES["node_gram_used"],
                        value=gram_used,
                        tags=gpu_tags,
                    )
                    gram_available_record = Record(
                        gauge=METRICS_GAUGES["node_gram_available"],
                        value=gram_available,
                        tags=gpu_tags,
                    )
                    gpu_records_to_add = [
                        gpus_available_record,
                        gpus_utilization_record,
                        gram_used_record,
                        gram_available_record,
                    ]
                    # Optional GPU power and temperature (e.g. NVIDIA, AMD)
                    if gpu.get("power_mw") is not None:
                        gpu_records_to_add.append(
                            Record(
                                gauge=METRICS_GAUGES["node_gpu_power_milliwatts"],
                                value=gpu["power_mw"],
                                tags=gpu_tags,
                            )
                        )
                    if gpu.get("temperature_c") is not None:
                        gpu_records_to_add.append(
                            Record(
                                gauge=METRICS_GAUGES["node_gpu_temperature_celsius"],
                                value=gpu["temperature_c"],
                                tags=gpu_tags,
                            )
                        )
                    records_reported.extend(gpu_records_to_add)

        # -- TPU per node --
        tpus = stats["tpus"]

        for tpu in tpus:
            tpu_index = tpu.get("index")
            tpu_name = tpu.get("name")
            tpu_type = tpu.get("tpu_type")
            tpu_topology = tpu.get("tpu_topology")

Review comment (suggestion):
I think it's better to follow the existing pattern to get the property first at line 1508 and then do the check and create `Record` if `power_mw` exists. 

Code after:
                    gpus_available_record = Record(
                        gauge=METRICS_GAUGES["node_gpus_available"],
                        value=1,
                        tags=gpu_tags,
                    )
                    gpus_utilization_record = Record(
                        gauge=METRICS_GAUGES["node_gpus_utilization"],
                        value=gpus_utilization,
                        tags=gpu_tags,
                    )
                    gram_used_record = Record(
                        gauge=METRICS_GAUGES["node_gram_used"],
                        value=gram_used,
                        tags=gpu_tags,
                    )
                    gram_available_record = Record(
                        gauge=METRICS_GAUGES["node_gram_available"],
                        value=gram_available,
                        tags=gpu_tags,
                    )
                    gpu_records_to_add = [
                        gpus_available_record,
                        gpus_utilization_record,
                        gram_used_record,
                        gram_available_record,
                    ]
                    # Optional GPU power and temperature (e.g. NVIDIA, AMD)
                    if gpu_power_mw is not None:
                        gpu_records_to_add.append(
                            Record(
                                gauge=METRICS_GAUGES["node_gpu_power_milliwatts"],
                                value=gpu_power_mw,
                                tags=gpu_tags,
                            )
                        )
                    if gpu_temperature_c is not None:
                        gpu_records_to_add.append(
                            Record(
                                gauge=METRICS_GAUGES["node_gpu_temperature_celsius"],
                                value=gpu_temperature_c,
                                tags=gpu_tags,
                            )
                        )
                    records_reported.extend(gpu_records_to_add)

        # -- TPU per node --
        tpus = stats["tpus"]

        for tpu in tpus:
            tpu_index = tpu.get("index")
            tpu_name = tpu.get("name")