-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathmethods.go
More file actions
291 lines (247 loc) · 9.58 KB
/
methods.go
File metadata and controls
291 lines (247 loc) · 9.58 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
package stats
import (
"strings"
"time"
"github.com/internetarchive/Zeno/internal/pkg/config"
)
/////////////////////////
// URLsCrawled //
/////////////////////////
// URLsCrawledIncr increments the URLsCrawled counter by 1.
func URLsCrawledIncr() {
globalStats.URLsCrawled.incr(1)
if globalPromStats != nil {
globalPromStats.urlCrawled.WithLabelValues(config.Get().JobPrometheus, hostname, version).Inc()
}
}
/////////////////////////
// SeedsFinished //
/////////////////////////
// SeedsFinishedIncr increments the SeedsFinished counter by 1.
func SeedsFinishedIncr() {
globalStats.SeedsFinished.incr(1)
if globalPromStats != nil {
globalPromStats.finishedSeeds.WithLabelValues(config.Get().JobPrometheus, hostname, version).Inc()
}
}
//////////////////////////
// PreprocessorRoutines //
//////////////////////////
// PreprocessorRoutinesIncr increments the PreprocessorRoutines counter by 1.
func PreprocessorRoutinesIncr() {
globalStats.PreprocessorRoutines.incr(1)
if globalPromStats != nil {
globalPromStats.preprocessorRoutines.WithLabelValues(config.Get().JobPrometheus, hostname, version).Inc()
}
}
// PreprocessorRoutinesDecr decrements the PreprocessorRoutines counter by 1.
func PreprocessorRoutinesDecr() {
globalStats.PreprocessorRoutines.decr(1)
if globalPromStats != nil {
globalPromStats.preprocessorRoutines.WithLabelValues(config.Get().JobPrometheus, hostname, version).Dec()
}
}
//////////////////////////
// ArchiverRoutines //
//////////////////////////
// ArchiverRoutinesIncr increments the ArchiverRoutines counter by 1.
func ArchiverRoutinesIncr() {
globalStats.ArchiverRoutines.incr(1)
if globalPromStats != nil {
globalPromStats.archiverRoutines.WithLabelValues(config.Get().JobPrometheus, hostname, version).Inc()
}
}
// ArchiverRoutinesDecr decrements the ArchiverRoutines counter by 1.
func ArchiverRoutinesDecr() {
globalStats.ArchiverRoutines.decr(1)
if globalPromStats != nil {
globalPromStats.archiverRoutines.WithLabelValues(config.Get().JobPrometheus, hostname, version).Dec()
}
}
//////////////////////////
// PostprocessorRoutines //
//////////////////////////
// PostprocessorRoutinesIncr increments the PostprocessorRoutines counter by 1.
func PostprocessorRoutinesIncr() {
globalStats.PostprocessorRoutines.incr(1)
if globalPromStats != nil {
globalPromStats.postprocessorRoutines.WithLabelValues(config.Get().JobPrometheus, hostname, version).Inc()
}
}
// PostprocessorRoutinesDecr decrements the PostprocessorRoutines counter by 1.
func PostprocessorRoutinesDecr() {
globalStats.PostprocessorRoutines.decr(1)
if globalPromStats != nil {
globalPromStats.postprocessorRoutines.WithLabelValues(config.Get().JobPrometheus, hostname, version).Dec()
}
}
//////////////////////////
// FinisherRoutines //
//////////////////////////
// FinisherRoutinesIncr increments the FinisherRoutines counter by 1.
func FinisherRoutinesIncr() {
globalStats.FinisherRoutines.incr(1)
if globalPromStats != nil {
globalPromStats.finisherRoutines.WithLabelValues(config.Get().JobPrometheus, hostname, version).Inc()
}
}
// FinisherRoutinesDecr decrements the FinisherRoutines counter by 1.
func FinisherRoutinesDecr() {
globalStats.FinisherRoutines.decr(1)
if globalPromStats != nil {
globalPromStats.finisherRoutines.WithLabelValues(config.Get().JobPrometheus, hostname, version).Dec()
}
}
//////////////////////////
// Paused //
//////////////////////////
// PausedSet sets the Paused flag to true.
func PausedSet() {
swapped := globalStats.Paused.CompareAndSwap(false, true)
if swapped {
if globalPromStats != nil {
globalPromStats.paused.WithLabelValues(config.Get().JobPrometheus, hostname, version).Set(1)
}
}
}
// PausedUnset sets the Paused flag to false.
func PausedUnset() {
swapped := globalStats.Paused.CompareAndSwap(true, false)
if swapped {
if globalPromStats != nil {
globalPromStats.paused.WithLabelValues(config.Get().JobPrometheus, hostname, version).Set(0)
}
}
}
// PausedReset resets the Paused flag to false.
func PausedReset() { globalStats.Paused.Store(false) }
//////////////////////////
// HTTPReturnCodes //
//////////////////////////
// HTTPReturnCodesIncr increments the HTTPReturnCodes counter for the given key by 1.
func HTTPReturnCodesIncr(key string) {
globalStats.HTTPReturnCodes.incr(key, 1)
if globalPromStats != nil {
switch {
case strings.HasPrefix(key, "2"):
globalPromStats.http2xx.WithLabelValues(config.Get().JobPrometheus, hostname, version).Inc()
case strings.HasPrefix(key, "3"):
globalPromStats.http3xx.WithLabelValues(config.Get().JobPrometheus, hostname, version).Inc()
case strings.HasPrefix(key, "4"):
globalPromStats.http4xx.WithLabelValues(config.Get().JobPrometheus, hostname, version).Inc()
case strings.HasPrefix(key, "5"):
globalPromStats.http5xx.WithLabelValues(config.Get().JobPrometheus, hostname, version).Inc()
}
}
}
//////////////////////////
// WarcWritingQueueSize //
//////////////////////////
// WarcWritingQueueSizeSet sets the WarcWritingQueueSize to the given value.
func WarcWritingQueueSizeSet(value int64) {
globalStats.WARCWritingQueueSize.Store(value)
if globalPromStats != nil {
globalPromStats.warcWritingQueueSize.WithLabelValues(config.Get().JobPrometheus, hostname, version).Set(float64(value))
}
}
//////////////////////////
// MeanHTTPRespTime //
//////////////////////////
// MeanHTTPRespTimeAdd adds the given value to the MeanHTTPRespTime.
func MeanHTTPRespTimeAdd(value time.Duration) {
globalStats.MeanHTTPResponseTime.add(uint64(value.Milliseconds()))
if globalPromStats != nil {
globalPromStats.meanHTTPRespTime.WithLabelValues(config.Get().JobPrometheus, hostname, version).Observe(float64(value))
}
}
//////////////////////////
// MeanProcessBodyTime //
//////////////////////////
// MeanProcessBodyTimeAdd adds the given value to the MeanProcessBodyTime.
func MeanProcessBodyTimeAdd(value time.Duration) {
globalStats.MeanProcessBodyTime.add(uint64(value.Milliseconds()))
if globalPromStats != nil {
globalPromStats.meanProcessBodyTime.WithLabelValues(config.Get().JobPrometheus, hostname, version).Observe(float64(value))
}
}
////////////////////////////
// MeanWaitOnFeedbackTime //
////////////////////////////
// MeanWaitOnFeedbackTimeAdd adds the given value to the MeanWaitOnFeedbackTime.
func MeanWaitOnFeedbackTimeAdd(value time.Duration) {
globalStats.MeanWaitOnFeedbackTime.add(uint64(value.Milliseconds()))
if globalPromStats != nil {
globalPromStats.meanWaitOnFeedbackTime.WithLabelValues(config.Get().JobPrometheus, hostname, version).Observe(float64(value))
}
}
////////////////////////////
// WARC Data Metrics //
////////////////////////////
// WARCDataTotalBytesSet sets the WARC data total bytes metric.
func WARCDataTotalBytesSet(value int64) {
globalStats.WARCDataTotalBytes.Store(value)
if globalPromStats != nil {
globalPromStats.dataTotalBytes.WithLabelValues(config.Get().JobPrometheus, hostname, version).Set(float64(value))
}
}
// WARCCDXDedupeTotalBytesSet sets the WARC CDX dedupe total bytes metric.
func WARCCDXDedupeTotalBytesSet(value int64) {
globalStats.WARCCDXDedupeTotalBytes.Store(value)
if globalPromStats != nil {
globalPromStats.cdxDedupeTotalBytes.WithLabelValues(config.Get().JobPrometheus, hostname, version).Set(float64(value))
}
}
// WARCDoppelgangerDedupeTotalBytesSet sets the WARC Doppelganger dedupe total bytes metric.
func WARCDoppelgangerDedupeTotalBytesSet(value int64) {
globalStats.WARCDoppelgangerDedupeTotalBytes.Store(value)
if globalPromStats != nil {
globalPromStats.doppelgangerDedupeTotalBytes.WithLabelValues(config.Get().JobPrometheus, hostname, version).Set(float64(value))
}
}
// WARCLocalDedupeTotalBytesSet sets the WARC local dedupe total bytes metric.
func WARCLocalDedupeTotalBytesSet(value int64) {
globalStats.WARCLocalDedupeTotalBytes.Store(value)
if globalPromStats != nil {
globalPromStats.localDedupeTotalBytes.WithLabelValues(config.Get().JobPrometheus, hostname, version).Set(float64(value))
}
}
// WARCCDXDedupeTotalSet sets the WARC CDX dedupe total count metric.
func WARCCDXDedupeTotalSet(value int64) {
globalStats.WARCCDXDedupeTotal.Store(value)
if globalPromStats != nil {
globalPromStats.cdxDedupeTotal.WithLabelValues(config.Get().JobPrometheus, hostname, version).Set(float64(value))
}
}
// WARCDoppelgangerDedupeTotalSet sets the WARC Doppelganger dedupe total count metric.
func WARCDoppelgangerDedupeTotalSet(value int64) {
globalStats.WARCDoppelgangerDedupeTotal.Store(value)
if globalPromStats != nil {
globalPromStats.doppelgangerDedupeTotal.WithLabelValues(config.Get().JobPrometheus, hostname, version).Set(float64(value))
}
}
// WARCLocalDedupeTotalSet sets the WARC local dedupe total count metric.
func WARCLocalDedupeTotalSet(value int64) {
globalStats.WARCLocalDedupeTotal.Store(value)
if globalPromStats != nil {
globalPromStats.localDedupeTotal.WithLabelValues(config.Get().JobPrometheus, hostname, version).Set(float64(value))
}
}
// CFMitigatedIncr increments the CFMitigated counter by 1.
func CFMitigatedIncr() {
globalStats.cfMitigated.Add(1)
if globalPromStats != nil {
globalPromStats.cfMitigated.WithLabelValues(config.Get().JobPrometheus, hostname, version).Inc()
}
}
//////////////////////////
// ComponentQueueSizes //
//////////////////////////
// ComponentQueueSizesUpdate updates all component queue sizes in Prometheus metrics.
func ComponentQueueSizesUpdate() {
if globalPromStats != nil {
channelQueues := GetChannelQueueSizes()
for component, size := range channelQueues {
globalPromStats.componentQueueSizes.WithLabelValues(config.Get().JobPrometheus, hostname, version, component).Set(float64(size))
}
}
}