...
1 package metrics
2
3 import (
4 "github.com/prometheus/client_golang/prometheus"
5 "github.com/prometheus/client_golang/prometheus/collectors"
6 "github.com/prometheus/client_golang/prometheus/promauto"
7
8 "edge-infra.dev/pkg/lib/runtime/metrics"
9 )
10
11 func init() {
12 metrics.Registry.MustRegister(
13 BslReconciles,
14 BslErrors,
15 BslOrganizationsProcessed,
16 BslNewOrganizations,
17
18 collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
19
20 collectors.NewGoCollector(),
21 )
22 }
23
24 var (
25
26
27
28 BslReconciles = promauto.NewCounter(prometheus.CounterOpts{
29 Name: "bsl_reconciles_counter",
30 Help: "number of reconciles",
31 })
32 BslErrors = promauto.NewCounterVec(
33 prometheus.CounterOpts{
34 Name: "bsl_errors_info",
35 Help: "errors message",
36 }, []string{"error_type", "org_name", "error_message"})
37
38 BslOrganizationsProcessed = promauto.NewCounterVec(prometheus.CounterOpts{
39 Name: "bsl_organization_processed",
40 Help: "numnber of organizations processed",
41 }, []string{"org_name"})
42
43 BslNewOrganizations = promauto.NewCounterVec(prometheus.CounterOpts{
44 Name: "bsl_new_organizations",
45 Help: "name of new organizations",
46 }, []string{"org_name"})
47 )
48
49 type Metrics struct {
50 BslReconciles prometheus.Counter
51 BslErrors *prometheus.CounterVec
52 BslOrganizationsProcessed *prometheus.CounterVec
53 BslNewOrganizations *prometheus.CounterVec
54 }
55
56 func NewMetrics() *Metrics {
57 return &Metrics{
58 BslReconciles: BslReconciles,
59 BslErrors: BslErrors,
60 BslOrganizationsProcessed: BslOrganizationsProcessed,
61 BslNewOrganizations: BslNewOrganizations,
62 }
63 }
64
65 func (m *Metrics) InitMetrics() {
66 BslReconciles.Add(0)
67 BslErrors.WithLabelValues("", "init_metrics", "").Add(0)
68 BslOrganizationsProcessed.WithLabelValues("init_metrics").Add(0)
69 BslNewOrganizations.WithLabelValues("init_metrics").Add(0)
70 }
71
72 func (m *Metrics) ReconcileInc() {
73 BslReconciles.Inc()
74 }
75
76 func (m *Metrics) OrgProcessedInc(orgName string) {
77 var l = prometheus.Labels{
78 "org_name": orgName,
79 }
80 BslOrganizationsProcessed.With(l).Inc()
81 }
82
83 func (m *Metrics) NewOrgInc(orgName string) {
84 var l = prometheus.Labels{
85 "org_name": orgName,
86 }
87 BslNewOrganizations.With(l).Inc()
88 }
89
90 func (m *Metrics) ErrorInc(errorType string, orgName string, errorMessage string) {
91 var l = prometheus.Labels{
92 "error_type": errorType,
93 "org_name": orgName,
94 "error_message": errorMessage,
95 }
96 BslErrors.With(l).Inc()
97 }
98
View as plain text