-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
telemetry.go
63 lines (52 loc) · 2.24 KB
/
telemetry.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2022-present Datadog, Inc.
package ratelimit
import (
tlm "github.com/DataDog/datadog-agent/pkg/telemetry"
)
type telemetry interface {
incWait()
incNoWait()
incHighLimit()
incLowLimit()
incLowLimitFreeOSMemory()
setMemoryUsageRate(rate float64)
}
type memBasedRateLimiterTelemetry struct {
wait tlm.Counter
noWait tlm.Counter
highLimit tlm.Counter
lowLimit tlm.Counter
lowLimitFreeOSMem tlm.Counter
memoryUsageRate tlm.Gauge
}
func newMemBasedRateLimiterTelemetry() *memBasedRateLimiterTelemetry {
return &memBasedRateLimiterTelemetry{
wait: tlm.NewCounter("dogstatsd", "mem_based_rate_limiter_wait", []string{}, "The number of times the rate limiter wait"),
noWait: tlm.NewCounter("dogstatsd", "mem_based_rate_limiter_no_wait", []string{}, "The number of times the rate limiter doesn't wait"),
highLimit: tlm.NewCounter("dogstatsd", "mem_based_rate_limiter_high_limit", []string{}, "The number of times the high limit is reached"),
lowLimit: tlm.NewCounter("dogstatsd", "mem_based_rate_limiter_low_limit", []string{}, "The number of times the soft limit is reached"),
lowLimitFreeOSMem: tlm.NewCounter("dogstatsd", "mem_based_rate_limiter_low_limit_freeos_mem", []string{}, "The number of times FreeOSMemory is called when the soft limit is reached"),
memoryUsageRate: tlm.NewGauge("dogstatsd", "mem_based_rate_limiter_mem_rate", []string{}, "The memory usage rate based on cgroup memory limit if it exists, otherwise based on the memory available"),
}
}
func (t *memBasedRateLimiterTelemetry) incWait() {
t.wait.Inc()
}
func (t *memBasedRateLimiterTelemetry) incNoWait() {
t.noWait.Inc()
}
func (t *memBasedRateLimiterTelemetry) incHighLimit() {
t.highLimit.Inc()
}
func (t *memBasedRateLimiterTelemetry) incLowLimit() {
t.lowLimit.Inc()
}
func (t *memBasedRateLimiterTelemetry) incLowLimitFreeOSMemory() {
t.lowLimitFreeOSMem.Inc()
}
func (t *memBasedRateLimiterTelemetry) setMemoryUsageRate(rate float64) {
t.memoryUsageRate.Set(rate)
}