github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/metrics/metrics.go (about) 1 package metrics 2 3 import ( 4 "github.com/prometheus/client_golang/prometheus" 5 "github.com/prometheus/client_golang/prometheus/promauto" 6 ) 7 8 type metricsStruct struct { 9 gitClone *prometheus.CounterVec 10 crdFormat *prometheus.CounterVec 11 currentStateWrite *prometheus.CounterVec 12 currentStateRead *prometheus.CounterVec 13 reconcilingBundle *prometheus.CounterVec 14 reconcilingApplication *prometheus.CounterVec 15 gyrBoom prometheus.Gauge 16 gyrGit prometheus.Gauge 17 gyrCurrentStateWrite prometheus.Gauge 18 gyrCurrentStateRead prometheus.Gauge 19 gyrReconciling prometheus.Gauge 20 gyrFormat prometheus.Gauge 21 } 22 23 var ( 24 metrics = &metricsStruct{ 25 gitClone: newCounterVec("boom_git_clone", "Counter how many times git repositories were cloned", "result", "url"), 26 crdFormat: newCounterVec("boom_crd_format", "Counter how many failures there were with the crd unmarshalling", "result", "reason"), 27 currentStateWrite: newCounterVec("boom_current_state_write", "Counter how many times the current state was written", "result", "url"), 28 currentStateRead: newCounterVec("boom_current_state_read", "Counter how many times the current state was read", "result"), 29 reconcilingBundle: newCounterVec("boom_reconciling_bundle", "Counter how many times the bundle was reconciled", "result", "bundle"), 30 reconcilingApplication: newCounterVec("boom_reconciling_application", "Counter how many times a application was reconciled", "result", "application", "templator", "deploy"), 31 gyrBoom: newGauge("boom_gyr", "Status of Boom in GreenYellowRed"), 32 gyrGit: newGauge("boom_git_gyr", "Status of git connection in GreenYellowRed"), 33 gyrCurrentStateWrite: newGauge("boom_current_state_write_gyr", "Status of current state write in GreenYellowRed"), 34 gyrCurrentStateRead: newGauge("boom_current_state_read_gyr", "Status of current state read in GreenYellowRed"), 35 gyrReconciling: newGauge("boom_reconciling_gyr", "Status of reconciling in GreenYellowRed"), 36 gyrFormat: newGauge("boom_crd_format_gyr", "Status of format unmarshalin in GreenYellowRed"), 37 } 38 failed float64 = 0 39 success float64 = 1 40 ) 41 42 func newGauge(name, help string) prometheus.Gauge { 43 gauge := promauto.NewGauge(prometheus.GaugeOpts{ 44 Name: name, 45 Help: help, 46 }) 47 48 err := register(gauge) 49 if err != nil { 50 return nil 51 } 52 53 return gauge 54 } 55 56 func newCounterVec(name string, help string, labels ...string) *prometheus.CounterVec { 57 counterVec := promauto.NewCounterVec(prometheus.CounterOpts{ 58 Name: name, 59 Help: help, 60 }, 61 labels, 62 ) 63 64 err := register(counterVec) 65 if err != nil { 66 return nil 67 } 68 69 return counterVec 70 } 71 func register(collector prometheus.Collector) error { 72 err := prometheus.Register(collector) 73 _, ok := err.(prometheus.AlreadyRegisteredError) 74 if err != nil && !ok { 75 return err 76 } 77 78 return nil 79 }