Przeglądaj źródła

Merge pull request #142 from PetzJohannes/fix-gauge-caching

#141 unregistr gauge 'container_uptime_seconds'
Ajay Tripathy 6 lat temu
rodzic
commit
a09186d3d0
1 zmienionych plików z 8 dodań i 0 usunięć
  1. 8 0
      main.go

+ 8 - 0
main.go

@@ -322,6 +322,7 @@ func (a *Accesses) recordPrices() {
 			prometheus.Unregister(a.RAMAllocationRecorder)
 			prometheus.Unregister(a.CPUAllocationRecorder)
 			prometheus.Unregister(a.GPUAllocationRecorder)
+			prometheus.Unregister(a.ContainerUptimeRecorder)
 
 			// zero out the allocation gauges since we want to reset them based on the kubernetes API
 			RAMAllocation := prometheus.NewGaugeVec(prometheus.GaugeOpts{
@@ -339,13 +340,20 @@ func (a *Accesses) recordPrices() {
 				Help: "container_gpu_allocation GPU used",
 			}, []string{"namespace", "pod", "container", "instance", "node"})
 
+	                ContainerUptime := prometheus.NewGaugeVec(prometheus.GaugeOpts{
+                                Name: "container_uptime_seconds",
+                                Help: "container_uptime_seconds Seconds a container has been running",
+	                }, []string{"namespace", "pod", "container"})
+
 			prometheus.MustRegister(RAMAllocation)
 			prometheus.MustRegister(CPUAllocation)
 			prometheus.MustRegister(GPUAllocation)
+			prometheus.MustRegister(ContainerUptime)
 
 			a.RAMAllocationRecorder = RAMAllocation
 			a.CPUAllocationRecorder = CPUAllocation
 			a.GPUAllocationRecorder = GPUAllocation
+			a.ContainerUptimeRecorder = ContainerUptime
 
 			klog.V(4).Info("Recording prices...")
 			data, err := costModel.ComputeCostData(a.PrometheusClient, a.KubeClientSet, a.Cloud, "2m", "", "")