docstr: SpillBuffer-specific metrics.
  
  Additionally, you can obtain derived metrics as follows:
  
  cache hit ratios:
    by keys  = spill_count.memory_read / (spill_count.memory_read + spill_count.disk_read)
    by bytes = spill_bytes.memory_read / (spill_bytes.memory_read + spill_bytes.disk_read)
  
  mean times per key:
    pickle   = spill_time.pickle     / spill_count.disk_write
    write    = spill_time.disk_write / spill_count.disk_write
    unpickle = spill_time.unpickle   / spill_count.disk_read
    read     = spill_time.disk_read  / spill_count.disk_read
  
  mean bytes per key:
    write    = spill_bytes.disk_write / spill_count.disk_write
    read     = spill_bytes.disk_read  / spill_count.disk_read
  
  mean bytes per second:
    write    = spill_bytes.disk_write / spill_time.disk_write
    read     = spill_bytes.disk_read  / spill_time.disk_read
docstr_tok: ["SpillBuffer-specific","metrics",".","Additionally",",","you","can","obtain","derived","metrics","as","follows",":","cache","hit","ratios",":","by","keys","=","spill_count.memory_read","\/","(","spill_count.memory_read","+","spill_count.disk_read",")","by","bytes","=","spill_bytes.memory_read","\/","(","spill_bytes.memory_read","+","spill_bytes.disk_read",")","mean","times","per","key",":","pickle","=","spill_time.pickle","\/","spill_count.disk_write","write","=","spill_time.disk_write","\/","spill_count.disk_write","unpickle","=","spill_time.unpickle","\/","spill_count.disk_read","read","=","spill_time.disk_read","\/","spill_count.disk_read","mean","bytes","per","key",":","write","=","spill_bytes.disk_write","\/","spill_count.disk_write","read","=","spill_bytes.disk_read","\/","spill_count.disk_read","mean","bytes","per","second",":","write","=","spill_bytes.disk_write","\/","spill_time.disk_write","read","=","spill_bytes.disk_read","\/","spill_time.disk_read"]
code: def collect_spillbuffer(self) -> Iterator[Metric]:
      """SpillBuffer-specific metrics.
  
      Additionally, you can obtain derived metrics as follows:
  
      cache hit ratios:
        by keys  = spill_count.memory_read / (spill_count.memory_read + spill_count.disk_read)
        by bytes = spill_bytes.memory_read / (spill_bytes.memory_read + spill_bytes.disk_read)
  
      mean times per key:
        pickle   = spill_time.pickle     / spill_count.disk_write
        write    = spill_time.disk_write / spill_count.disk_write
        unpickle = spill_time.unpickle   / spill_count.disk_read
        read     = spill_time.disk_read  / spill_count.disk_read
  
      mean bytes per key:
        write    = spill_bytes.disk_write / spill_count.disk_write
        read     = spill_bytes.disk_read  / spill_count.disk_read
  
      mean bytes per second:
        write    = spill_bytes.disk_write / spill_time.disk_write
        read     = spill_bytes.disk_read  / spill_time.disk_read
      """
      try:
          metrics = self.server.data.cumulative_metrics  # type: ignore
      except AttributeError:
          return  # spilling is disabled
  
      counters = {
          "bytes": CounterMetricFamily(
              self.build_name("spill_bytes"),
              "Total size of memory and disk accesses caused by managed data "
              "since the latest worker restart",
              labels=["activity"],
          ),
          "count": CounterMetricFamily(
              self.build_name("spill_count"),
              "Total number of memory and disk accesses caused by managed data "
              "since the latest worker restart",
              labels=["activity"],
          ),
          "seconds": CounterMetricFamily(
              self.build_name("spill_time"),
              "Total time spent spilling/unspilling since the latest worker restart",
              unit="seconds",
              labels=["activity"],
          ),
      }
  
      # Note: memory_read is used to calculate cache hit ratios (see docstring)
      for (label, unit), value in metrics.items():
          counters[unit].add_metric([label], value)
  
      yield from counters.values()
  
imports: from __future__ import annotations
  import logging
  from collections.abc import Iterator
  from time import time
  from typing import ClassVar
  import prometheus_client
  from prometheus_client.core import CounterMetricFamily, GaugeMetricFamily, Metric
  from distributed.http.prometheus import PrometheusCollector
  from distributed.http.utils import RequestHandler
  from distributed.worker import Worker
label_desc: Use image node_id 4 for calling the WorkerMetricCollector obj's underlying member method code with example usage: obj.collect_spillbuffer() without return types