-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
tcp_queue_tracer.go
66 lines (54 loc) · 1.79 KB
/
tcp_queue_tracer.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
// 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 2016-present Datadog, Inc.
//go:build linux
package modules
import (
"fmt"
"net/http"
"time"
"go.uber.org/atomic"
"github.com/DataDog/datadog-agent/cmd/system-probe/api/module"
"github.com/DataDog/datadog-agent/cmd/system-probe/config"
sysconfigtypes "github.com/DataDog/datadog-agent/cmd/system-probe/config/types"
"github.com/DataDog/datadog-agent/cmd/system-probe/utils"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/ebpf/probe/tcpqueuelength"
"github.com/DataDog/datadog-agent/pkg/ebpf"
)
// TCPQueueLength Factory
var TCPQueueLength = module.Factory{
Name: config.TCPQueueLengthTracerModule,
ConfigNamespaces: []string{},
Fn: func(_ *sysconfigtypes.Config, _ module.FactoryDependencies) (module.Module, error) {
t, err := tcpqueuelength.NewTracer(ebpf.NewConfig())
if err != nil {
return nil, fmt.Errorf("unable to start the TCP queue length tracer: %w", err)
}
return &tcpQueueLengthModule{
Tracer: t,
lastCheck: atomic.NewInt64(0),
}, nil
},
NeedsEBPF: func() bool {
return true
},
}
var _ module.Module = &tcpQueueLengthModule{}
type tcpQueueLengthModule struct {
*tcpqueuelength.Tracer
lastCheck *atomic.Int64
}
func (t *tcpQueueLengthModule) Register(httpMux *module.Router) error {
httpMux.HandleFunc("/check", func(w http.ResponseWriter, _ *http.Request) {
t.lastCheck.Store(time.Now().Unix())
stats := t.Tracer.GetAndFlush()
utils.WriteAsJSON(w, stats)
})
return nil
}
func (t *tcpQueueLengthModule) GetStats() map[string]interface{} {
return map[string]interface{}{
"last_check": t.lastCheck.Load(),
}
}