-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
system_info.go
54 lines (48 loc) · 1.4 KB
/
system_info.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
// 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 !windows && !darwin
package checks
import (
// waiting for upstream fix to platform collection in containerized environments
"github.com/DataDog/gopsutil/host"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/mem"
model "github.com/DataDog/agent-payload/v5/process"
)
// CollectSystemInfo collects a set of system-level information that will not
// change until a restart. This bit of information should be passed along with
// the process messages.
func CollectSystemInfo() (*model.SystemInfo, error) {
hi, err := host.Info()
if err != nil {
return nil, err
}
cpuInfo, err := cpu.Info()
if err != nil {
return nil, err
}
mi, err := mem.VirtualMemory()
if err != nil {
return nil, err
}
cpus := make([]*model.CPUInfo, 0, len(cpuInfo))
for _, c := range cpuInfo {
cpus = append(cpus, &model.CPUInfo{
Cores: c.Cores,
})
}
return &model.SystemInfo{
Uuid: hi.HostID,
Os: &model.OSInfo{
Name: hi.OS,
Platform: hi.Platform,
Family: hi.PlatformFamily,
Version: hi.PlatformVersion,
KernelVersion: hi.KernelVersion,
},
Cpus: cpus,
TotalMemory: int64(mi.Total),
}, nil
}