-
Notifications
You must be signed in to change notification settings - Fork 0
/
metric.go
105 lines (93 loc) · 5.55 KB
/
metric.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package login
import (
"strings"
"github.com/monologid/m9/instrument"
"github.com/monologid/m9/serviceprovider"
)
var prometheusModuleName = "login"
var (
PrometheusDefaultTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "default_total", "The total number of login using Default.")
PrometheusDefaultSuccessTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "default_success_total", "The total number of success login using Default.")
PrometheusDefaultFailedTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "default_failed_total", "The total number of failed login using Default.")
PrometheusRegisterDefaultTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "default_register_total", "The total number of account registration using Default.")
PrometheusRegisterDefaultSuccessTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "default_register_success_total", "The total number of success account registration using Default.")
PrometheusRegisterDefaultFailedTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "default_register_failed_total", "The total number of failed account registration using Default.")
PrometheusFacebookTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "facebook_total", "The total number of login using Facebook.")
PrometheusFacebookSuccessTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "facebook_success_total", "The total number of success login using Facebook.")
PrometheusFacebookFailedTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "facebook_failed_total", "The total number of failed login using Facebook.")
PrometheusRegisterFacebookTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "facebook_register_total", "The total number of account registration using Facebook.")
PrometheusRegisterFacebookSuccessTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "facebook_register_success_total", "The total number of success account registration using Facebook.")
PrometheusRegisterFacebookFailedTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "facebook_register_failed_total", "The total number of failed account registration using Facebook.")
PrometheusGoogleTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "google_total", "The total number of login using Google.")
PrometheusGoogleSuccessTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "google_success_total", "The total number of success login using Google.")
PrometheusGoogleFailedTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "google_failed_total", "The total number of failed login using Google.")
PrometheusRegisterGoogleTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "google_register_total", "The total number of account registration using Google.")
PrometheusRegisterGoogleSuccessTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "google_register_success_total", "The total number of success account registration using Google.")
PrometheusRegisterGoogleFailedTotal = instrument.NewPrometheus().NewCounter(prometheusModuleName, "google_register_failed_total", "The total number of failed account registration using Google.")
)
// MetricInitiateLogin increases the metric when iniate a login
func MetricInitiateLogin(provider string) {
switch strings.ToUpper(provider) {
case serviceprovider.FACEBOOK:
PrometheusFacebookTotal.Inc()
case serviceprovider.GOOGLE:
PrometheusGoogleTotal.Inc()
default:
PrometheusDefaultTotal.Inc()
}
}
// MetricLoginSuccess increases the metric when login is success
func MetricLoginSuccess(provider string) {
switch strings.ToUpper(provider) {
case serviceprovider.FACEBOOK:
PrometheusFacebookSuccessTotal.Inc()
case serviceprovider.GOOGLE:
PrometheusGoogleSuccessTotal.Inc()
default:
PrometheusDefaultSuccessTotal.Inc()
}
}
// MetricLoginFailed increases the metric when login is failed
func MetricLoginFailed(provider string) {
switch strings.ToUpper(provider) {
case serviceprovider.FACEBOOK:
PrometheusFacebookFailedTotal.Inc()
case serviceprovider.GOOGLE:
PrometheusGoogleFailedTotal.Inc()
default:
PrometheusDefaultFailedTotal.Inc()
}
}
// MetricInitiateAccountRegistration increases the metric when there's a new account registration
func MetricInitiateAccountRegistration(provider string) {
switch strings.ToUpper(provider) {
case serviceprovider.FACEBOOK:
PrometheusRegisterFacebookTotal.Inc()
case serviceprovider.GOOGLE:
PrometheusRegisterGoogleTotal.Inc()
default:
PrometheusRegisterDefaultTotal.Inc()
}
}
// MetricInitiateAccountRegistrationSuccess increases the metric when new account registration is success
func MetricInitiateAccountRegistrationSuccess(provider string) {
switch strings.ToUpper(provider) {
case serviceprovider.FACEBOOK:
PrometheusRegisterFacebookSuccessTotal.Inc()
case serviceprovider.GOOGLE:
PrometheusRegisterGoogleSuccessTotal.Inc()
default:
PrometheusRegisterDefaultSuccessTotal.Inc()
}
}
// MetricInitiateAccountRegistrationFailed increases the metric when new account registration is success
func MetricInitiateAccountRegistrationFailed(provider string) {
switch strings.ToUpper(provider) {
case serviceprovider.FACEBOOK:
PrometheusRegisterFacebookFailedTotal.Inc()
case serviceprovider.GOOGLE:
PrometheusRegisterGoogleFailedTotal.Inc()
default:
PrometheusRegisterDefaultFailedTotal.Inc()
}
}