code: func (rc *resourceMetricCollector) Collect(ch chan<- prometheus.Metric) {
  	rc.errors.Set(0)
  	defer rc.errors.Collect(ch)
  	summary, err := rc.provider.GetCPUAndMemoryStats()
  	if err != nil {
  		rc.errors.Set(1)
  		klog.Warningf("Error getting summary for resourceMetric prometheus endpoint: %v", err)
  		return
  	}
  
  	for _, metric := range rc.config.NodeMetrics {
  		if value, timestamp := metric.ValueFn(summary.Node); value != nil {
  			ch <- prometheus.NewMetricWithTimestamp(timestamp,
  				prometheus.MustNewConstMetric(metric.desc(), prometheus.GaugeValue, *value))
  		}
  	}
  
  	for _, pod := range summary.Pods {
  		for _, container := range pod.Containers {
  			for _, metric := range rc.config.ContainerMetrics {
  				if value, timestamp := metric.ValueFn(container); value != nil {
  					ch <- prometheus.NewMetricWithTimestamp(timestamp,
  						prometheus.MustNewConstMetric(metric.desc(), prometheus.GaugeValue, *value, container.Name, pod.PodRef.Name, pod.PodRef.Namespace))
  				}
  			}
  		}
  	}
  }
docs: // Collect implements prometheus.Collector
  // Since new containers are frequently created and removed, using the prometheus.Gauge Collector would
  // leak metric collectors for containers or pods that no longer exist.  Instead, implement
  // prometheus.Collector in a way that only collects metrics for active containers.