func (rc *resourceMetricCollector) CollectWithStability(ch chan<- metrics.Metric) {
	var errorCount float64
	defer func() {
		ch <- metrics.NewLazyConstMetric(rc.errors, metrics.GaugeValue, errorCount)
	}()
	summary, err := rc.provider.GetCPUAndMemoryStats()
	if err != nil {
		errorCount = 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 <- metrics.NewLazyMetricWithTimestamp(timestamp,
				metrics.NewLazyConstMetric(metric.desc(), metrics.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 <- metrics.NewLazyMetricWithTimestamp(timestamp,
						metrics.NewLazyConstMetric(metric.desc(), metrics.GaugeValue, *value, container.Name, pod.PodRef.Name, pod.PodRef.Namespace))
				}
			}
		}
	}
}
// CollectWithStability implements metrics.StableCollector
// Since new containers are frequently created and removed, using the Gauge would
// leak metric collectors for containers or pods that no longer exist.  Instead, implement
// custom collector in a way that only collects metrics for active containers.
CollectWithStability implements metrics.StableCollector
Since new containers are frequently created and removed, using the Gauge would
leak metric collectors for containers or pods that no longer exist.  Instead, implement
custom collector in a way that only collects metrics for active containers.
// CollectWithStability implements metrics . StableCollector // Since new containers are frequently created and removed using the Gauge would // leak metric collectors for containers or pods that no longer exist . Instead implement // custom collector in a way that only collects metrics for active containers .
func (rc *resourceMetricCollector) CollectWithStability(ch chan<- metrics.Metric) {
	var errorCount float64
	defer func() {
		ch <- metrics.NewLazyConstMetric(rc.errors, metrics.GaugeValue, errorCount)
	}()
	summary, err := rc.provider.GetCPUAndMemoryStats()
	if err != nil {
		errorCount = 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 <- metrics.NewLazyMetricWithTimestamp(timestamp,
				metrics.NewLazyConstMetric(metric.desc(), metrics.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 <- metrics.NewLazyMetricWithTimestamp(timestamp,
						metrics.NewLazyConstMetric(metric.desc(), metrics.GaugeValue, *value, container.Name, pod.PodRef.Name, pod.PodRef.Namespace))
				}
			}
		}
	}
}
func ( rc * resourceMetricCollector ) CollectWithStability ( ch chan <- metrics . Metric ) { var errorCount float64 defer func ( ) { ch <- metrics . NewLazyConstMetric ( rc . errors , metrics . GaugeValue , errorCount ) } ( ) summary , err := rc . provider . GetCPUAndMemoryStats ( ) if err != nil { errorCount = 1 klog . Warningf ( " " , err ) return } for _ , metric := range rc . config . NodeMetrics { if value , timestamp := metric . ValueFn ( summary . Node ) ; value != nil { ch <- metrics . NewLazyMetricWithTimestamp ( timestamp , metrics . NewLazyConstMetric ( metric . desc ( ) , metrics . 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 <- metrics . NewLazyMetricWithTimestamp ( timestamp , metrics . NewLazyConstMetric ( metric . desc ( ) , metrics . GaugeValue , * value , container . Name , pod . PodRef . Name , pod . PodRef . Namespace ) ) } } } } }
CollectWithStability implements metrics.StableCollector
Since new containers are frequently created and removed, using the Gauge would
leak metric collectors for containers or pods that no longer exist.
CollectWithStability implements metrics . StableCollector Since new containers are frequently created and removed using the Gauge would leak metric collectors for containers or pods that no longer exist .