package metrics import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/collectors" "github.com/prometheus/client_golang/prometheus/promauto" "edge-infra.dev/pkg/lib/runtime/metrics" ) func init() { metrics.Registry.MustRegister( BslReconciles, BslErrors, BslOrganizationsProcessed, BslNewOrganizations, // expose process metrics like CPU, Memory, file descriptor usage etc. collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}), // expose Go runtime metrics like GC stats, memory stats etc. collectors.NewGoCollector(), ) } var ( // Variables that are to be registered with prometheus. // promauto automactically registers the variable with prometheus. If promauto is not used variable needs to be registered using prometheus.register // The following variables are of type Gauge metric. BslReconciles = promauto.NewCounter(prometheus.CounterOpts{ Name: "bsl_reconciles_counter", Help: "number of reconciles", }) BslErrors = promauto.NewCounterVec( prometheus.CounterOpts{ Name: "bsl_errors_info", Help: "errors message", }, []string{"error_type", "org_name", "error_message"}) BslOrganizationsProcessed = promauto.NewCounterVec(prometheus.CounterOpts{ Name: "bsl_organization_processed", Help: "numnber of organizations processed", }, []string{"org_name"}) BslNewOrganizations = promauto.NewCounterVec(prometheus.CounterOpts{ Name: "bsl_new_organizations", Help: "name of new organizations", }, []string{"org_name"}) ) type Metrics struct { BslReconciles prometheus.Counter BslErrors *prometheus.CounterVec BslOrganizationsProcessed *prometheus.CounterVec BslNewOrganizations *prometheus.CounterVec } func NewMetrics() *Metrics { return &Metrics{ BslReconciles: BslReconciles, BslErrors: BslErrors, BslOrganizationsProcessed: BslOrganizationsProcessed, BslNewOrganizations: BslNewOrganizations, } } func (m *Metrics) InitMetrics() { BslReconciles.Add(0) BslErrors.WithLabelValues("", "init_metrics", "").Add(0) BslOrganizationsProcessed.WithLabelValues("init_metrics").Add(0) BslNewOrganizations.WithLabelValues("init_metrics").Add(0) } func (m *Metrics) ReconcileInc() { BslReconciles.Inc() } func (m *Metrics) OrgProcessedInc(orgName string) { var l = prometheus.Labels{ "org_name": orgName, } BslOrganizationsProcessed.With(l).Inc() } func (m *Metrics) NewOrgInc(orgName string) { var l = prometheus.Labels{ "org_name": orgName, } BslNewOrganizations.With(l).Inc() } func (m *Metrics) ErrorInc(errorType string, orgName string, errorMessage string) { var l = prometheus.Labels{ "error_type": errorType, "org_name": orgName, "error_message": errorMessage, } BslErrors.With(l).Inc() }