-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
platform.go
45 lines (35 loc) · 1.32 KB
/
platform.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
// 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 kernel
import (
gopsutilhost "github.com/DataDog/gopsutil/host"
"github.com/DataDog/datadog-agent/pkg/util/funcs"
)
type platformInfo struct {
platform string
family string
version string
}
// Platform is the string describing the Linux distribution (ubuntu, debian, fedora, etc.)
var Platform = funcs.Memoize(func() (string, error) {
pi, err := platformInformation()
return pi.platform, err
})
// PlatformVersion is the string describing the platform version (`22.04` for Ubuntu jammy, etc.)
var PlatformVersion = funcs.Memoize(func() (string, error) {
pi, err := platformInformation()
return pi.version, err
})
// Family is the string describing the Linux distribution family (rhel, debian, etc.)
var Family = funcs.Memoize(func() (string, error) {
pi, err := platformInformation()
return pi.family, err
})
var platformInformation = funcs.Memoize(getPlatformInformation)
func getPlatformInformation() (platformInfo, error) {
platform, family, version, err := gopsutilhost.PlatformInformation()
return platformInfo{platform, family, version}, err
}