-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
check.go
73 lines (63 loc) · 2.08 KB
/
check.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
// 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
//nolint:revive // TODO(PROC) Fix revive linter
package net
import (
"encoding/json"
"fmt"
"io"
"net/http"
sysconfig "github.com/DataDog/datadog-agent/cmd/system-probe/config"
sysconfigtypes "github.com/DataDog/datadog-agent/cmd/system-probe/config/types"
ebpfcheck "github.com/DataDog/datadog-agent/pkg/collector/corechecks/ebpf/probe/ebpfcheck/model"
oomkill "github.com/DataDog/datadog-agent/pkg/collector/corechecks/ebpf/probe/oomkill/model"
tcpqueuelength "github.com/DataDog/datadog-agent/pkg/collector/corechecks/ebpf/probe/tcpqueuelength/model"
)
const (
checksURL = "http://unix/%s/check"
)
// GetCheck returns the check output of the specified module
func (r *RemoteSysProbeUtil) GetCheck(module sysconfigtypes.ModuleName) (interface{}, error) {
req, err := http.NewRequest("GET", fmt.Sprintf(checksURL, module), nil)
if err != nil {
return nil, err
}
resp, err := r.httpClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("conn request failed: socket %s, url %s, status code: %d", r.path, fmt.Sprintf(checksURL, module), resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if module == sysconfig.TCPQueueLengthTracerModule {
var stats tcpqueuelength.TCPQueueLengthStats
err = json.Unmarshal(body, &stats)
if err != nil {
return nil, err
}
return stats, nil
} else if module == sysconfig.OOMKillProbeModule {
var stats []oomkill.OOMKillStats
err = json.Unmarshal(body, &stats)
if err != nil {
return nil, err
}
return stats, nil
} else if module == sysconfig.EBPFModule {
var stats ebpfcheck.EBPFStats
err = json.Unmarshal(body, &stats)
if err != nil {
return nil, err
}
return stats, nil
}
return nil, fmt.Errorf("invalid check name: %s", module)
}