-
Notifications
You must be signed in to change notification settings - Fork 1
/
metrics.go
161 lines (156 loc) · 3.72 KB
/
metrics.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
import p "github.com/prometheus/client_golang/prometheus"
/* Prometheus Metrics Declarations */
var (
promReqServed = p.NewCounterVec(
p.CounterOpts{
Name: "eldim_http_requests_served",
Help: "HTTP Requests Served by eldim, with corresponding types and status codes, per path",
},
[]string{
"method",
"path",
"status",
},
)
promMetricsAuth = p.NewCounterVec(
p.CounterOpts{
Name: "eldim_prometheus_metrics_scrape_auth",
Help: "HTTP Requests to the Prometheus Metrics Endpoint and their Authentication Status",
},
[]string{
"success",
"error",
},
)
promFileUpErrors = p.NewCounterVec(
p.CounterOpts{
Name: "eldim_file_upload_errors_occured",
Help: "Types of errors occured during file uploads",
},
[]string{
"error",
},
)
promReqServTimeHist = p.NewHistogram(
p.HistogramOpts{
Name: "eldim_file_upload_request_time",
Help: "Histogram of time of successful file uploads to eldim",
Buckets: p.LinearBuckets(0, 60, 120),
},
)
promClients = p.NewGaugeVec(
p.GaugeOpts{
Name: "eldim_loaded_clients",
Help: "Clients that are allowed to upload files to eldim",
},
[]string{
"type",
},
)
promIPs = p.NewGaugeVec(
p.GaugeOpts{
Name: "eldim_loaded_ip_addressess",
Help: "IP Addressess that are allowed to upload files to eldim",
},
[]string{
"version",
},
)
promBytesUploadedSuc = p.NewCounter(
p.CounterOpts{
Name: "eldim_files_uploaded_bytes_successful",
Help: "Amount of bytes of files uploaded to eldim successfully",
},
)
promBytesUploaded = p.NewCounterVec(
p.CounterOpts{
Name: "eldim_files_uploaded_bytes",
Help: "Amount of bytes of files uploaded from eldim per Backend",
},
[]string{
"backendtype",
},
)
promClientIDs = p.NewCounterVec(
p.CounterOpts{
Name: "eldim_client_id_type",
Help: "Type of Client Identification used (Password vs IP Address)",
},
[]string{
"type",
},
)
promHostAuths = p.NewCounterVec(
p.CounterOpts{
Name: "eldim_host_authentications",
Help: "Successful authentications to eldim by hostname",
},
[]string{
"hostname",
},
)
promHostUploads = p.NewCounterVec(
p.CounterOpts{
Name: "eldim_host_uploads",
Help: "Successful file uploads to eldim by hostname",
},
[]string{
"hostname",
},
)
promEldimVersion = p.NewGaugeVec(
p.GaugeOpts{
Name: "eldim_server_version",
Help: "Each eldim server returns '1', with the software version as a tag",
},
[]string{
"eldimversion",
},
)
)
/* Register Prometheus Metrics */
func registerPromMetrics() {
/* Initialize Prometheus */
p.MustRegister(promReqServed)
p.MustRegister(promMetricsAuth)
p.MustRegister(promFileUpErrors)
p.MustRegister(promReqServTimeHist)
p.MustRegister(promClients)
p.MustRegister(promIPs)
p.MustRegister(promBytesUploadedSuc)
p.MustRegister(promBytesUploaded)
p.MustRegister(promClientIDs)
p.MustRegister(promHostAuths)
p.MustRegister(promHostUploads)
p.MustRegister(promEldimVersion)
}
/* Update configuration-based Metrics */
func updateConfMetrics() {
/* Set Prometheus Loaded Clients Metric */
var v4 float64 = 0
var v6 float64 = 0
var pass float64 = 0
var v4a float64 = 0
var v6a float64 = 0
for _, c := range clients {
if len(c.IPv4()) >= 1 {
v4++
v4a += float64(len(c.IPv4()))
}
if len(c.IPv6()) >= 1 {
v6++
v6a += float64(len(c.IPv6()))
}
if c.Password != "" {
pass++
}
}
promClients.With(p.Labels{"type": "ipv6"}).Set(v6)
promClients.With(p.Labels{"type": "ipv4"}).Set(v4)
promClients.With(p.Labels{"type": "password"}).Set(pass)
promIPs.With(p.Labels{"version": "6"}).Set(v6a)
promIPs.With(p.Labels{"version": "4"}).Set(v4a)
/* Set eldim version */
promEldimVersion.With(p.Labels{"eldimversion": version}).Set(1)
}