Path: blob/main/pkg/flow/internal/controller/metrics.go
4095 views
package controller12import "github.com/prometheus/client_golang/prometheus"34// controllerMetrics contains the metrics for components controller5type controllerMetrics struct {6r prometheus.Registerer78controllerEvaluation prometheus.Gauge9componentEvaluationTime prometheus.Histogram10}1112// newControllerMetrics inits the metrics for the components controller13func newControllerMetrics(r prometheus.Registerer) *controllerMetrics {14cm := controllerMetrics{r: r}1516cm.controllerEvaluation = prometheus.NewGauge(prometheus.GaugeOpts{17Name: "agent_component_controller_evaluating",18Help: "Tracks if the controller is currently in the middle of a graph evaluation",19})2021cm.componentEvaluationTime = prometheus.NewHistogram(22prometheus.HistogramOpts{23Name: "agent_component_evaluation_seconds",24Help: "Time spent performing component evaluation",25},26)2728if r != nil {29r.MustRegister(30cm.controllerEvaluation,31cm.componentEvaluationTime,32)33}34return &cm35}3637type controllerCollector struct {38l *Loader39runningComponentsTotal *prometheus.Desc40}4142func newControllerCollector(l *Loader) prometheus.Collector {43return &controllerCollector{44l: l,45runningComponentsTotal: prometheus.NewDesc(46"agent_component_controller_running_components",47"Total number of running components.",48[]string{"health_type"},49nil,50),51}52}5354func (cc *controllerCollector) Collect(ch chan<- prometheus.Metric) {55componentsByHealth := make(map[string]int)5657for _, component := range cc.l.Components() {58health := component.CurrentHealth().Health.String()59componentsByHealth[health]++60component.register.Collect(ch)61}6263for health, count := range componentsByHealth {64ch <- prometheus.MustNewConstMetric(cc.runningComponentsTotal, prometheus.GaugeValue, float64(count), health)65}66}6768func (cc *controllerCollector) Describe(ch chan<- *prometheus.Desc) {69ch <- cc.runningComponentsTotal70}717273