github.com/secure-build/gitlab-runner@v12.5.0+incompatible/executors/docker/machine/collector.go (about)

     1  package machine
     2  
     3  import (
     4  	"github.com/prometheus/client_golang/prometheus"
     5  )
     6  
     7  func (m *machineProvider) collectDetails() (data machinesData) {
     8  	m.lock.RLock()
     9  	defer m.lock.RUnlock()
    10  
    11  	for _, details := range m.details {
    12  		if !details.isDead() {
    13  			data.Add(details)
    14  		}
    15  	}
    16  	return
    17  }
    18  
    19  // Describe implements prometheus.Collector.
    20  func (m *machineProvider) Describe(ch chan<- *prometheus.Desc) {
    21  	m.totalActions.Describe(ch)
    22  	m.creationHistogram.Describe(ch)
    23  	ch <- m.currentStatesDesc
    24  }
    25  
    26  // Collect implements prometheus.Collector.
    27  func (m *machineProvider) Collect(ch chan<- prometheus.Metric) {
    28  	data := m.collectDetails()
    29  	ch <- prometheus.MustNewConstMetric(m.currentStatesDesc, prometheus.GaugeValue, float64(data.Acquired), "acquired")
    30  	ch <- prometheus.MustNewConstMetric(m.currentStatesDesc, prometheus.GaugeValue, float64(data.Creating), "creating")
    31  	ch <- prometheus.MustNewConstMetric(m.currentStatesDesc, prometheus.GaugeValue, float64(data.Idle), "idle")
    32  	ch <- prometheus.MustNewConstMetric(m.currentStatesDesc, prometheus.GaugeValue, float64(data.Used), "used")
    33  	ch <- prometheus.MustNewConstMetric(m.currentStatesDesc, prometheus.GaugeValue, float64(data.Removing), "removing")
    34  	ch <- prometheus.MustNewConstMetric(m.currentStatesDesc, prometheus.GaugeValue, float64(data.StuckOnRemoving), "stuck-on-removing")
    35  
    36  	m.totalActions.Collect(ch)
    37  	m.creationHistogram.Collect(ch)
    38  }