Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/cadvisor/common.go
5332 views
1
package cadvisor
2
3
import (
4
"time"
5
6
"github.com/go-kit/log"
7
"github.com/grafana/agent/pkg/integrations"
8
integrations_v2 "github.com/grafana/agent/pkg/integrations/v2"
9
"github.com/grafana/agent/pkg/integrations/v2/metricsutils"
10
)
11
12
const name = "cadvisor"
13
14
// DefaultConfig holds the default settings for the cadvisor integration
15
var DefaultConfig = Config{
16
// Common cadvisor config defaults
17
StoreContainerLabels: true,
18
ResctrlInterval: 0,
19
20
StorageDuration: 2 * time.Minute,
21
22
// Containerd config defaults
23
Containerd: "/run/containerd/containerd.sock",
24
ContainerdNamespace: "k8s.io",
25
26
// Docker config defaults
27
Docker: "unix:///var/run/docker.sock",
28
DockerTLS: false,
29
DockerTLSCert: "cert.pem",
30
DockerTLSKey: "key.pem",
31
DockerTLSCA: "ca.pem",
32
33
// Raw config defaults
34
DockerOnly: false,
35
}
36
37
// Config controls cadvisor
38
type Config struct {
39
// Common cadvisor config options
40
// StoreContainerLabels converts container labels and environment variables into labels on prometheus metrics for each container. If false, then only metrics exported are container name, first alias, and image name.
41
StoreContainerLabels bool `yaml:"store_container_labels,omitempty"`
42
43
// AllowlistedContainerLabels list of container labels to be converted to labels on prometheus metrics for each container. store_container_labels must be set to false for this to take effect.
44
AllowlistedContainerLabels []string `yaml:"allowlisted_container_labels,omitempty"`
45
46
// EnvMetadataAllowlist list of environment variable keys matched with specified prefix that needs to be collected for containers, only support containerd and docker runtime for now.
47
EnvMetadataAllowlist []string `yaml:"env_metadata_allowlist,omitempty"`
48
49
// RawCgroupPrefixAllowlist list of cgroup path prefix that needs to be collected even when -docker_only is specified.
50
RawCgroupPrefixAllowlist []string `yaml:"raw_cgroup_prefix_allowlist,omitempty"`
51
52
// PerfEventsConfig path to a JSON file containing configuration of perf events to measure. Empty value disabled perf events measuring.
53
PerfEventsConfig string `yaml:"perf_events_config,omitempty"`
54
55
// ResctrlInterval resctrl mon groups updating interval. Zero value disables updating mon groups.
56
ResctrlInterval int `yaml:"resctrl_interval,omitempty"`
57
58
// DisableMetrics list of `metrics` to be disabled.
59
DisabledMetrics []string `yaml:"disabled_metrics,omitempty"`
60
61
// EnableMetrics list of `metrics` to be enabled. If set, overrides 'disable_metrics'.
62
EnabledMetrics []string `yaml:"enabled_metrics,omitempty"`
63
64
// StorageDuration length of time to keep data stored in memory (Default: 2m)
65
StorageDuration time.Duration `yaml:"storage_duration,omitempty"`
66
67
// Containerd config options
68
// Containerd containerd endpoint
69
Containerd string `yaml:"containerd,omitempty"`
70
71
// ContainerdNamespace containerd namespace
72
ContainerdNamespace string `yaml:"containerd_namespace,omitempty"`
73
74
// Docker config options
75
// Docker docker endpoint
76
Docker string `yaml:"docker,omitempty"`
77
78
// DockerTLS use TLS to connect to docker
79
DockerTLS bool `yaml:"docker_tls,omitempty"`
80
81
// DockerTLSCert path to client certificate
82
DockerTLSCert string `yaml:"docker_tls_cert,omitempty"`
83
84
// DockerTLSKey path to private key
85
DockerTLSKey string `yaml:"docker_tls_key,omitempty"`
86
87
// DockerTLSCA path to trusted CA
88
DockerTLSCA string `yaml:"docker_tls_ca,omitempty"`
89
90
// Raw config options
91
// DockerOnly only report docker containers in addition to root stats
92
DockerOnly bool `yaml:"docker_only,omitempty"`
93
94
// Hold on to the logger passed to config.NewIntegration, to be passed to klog, as yet another unsafe global that needs to be set.
95
logger log.Logger //nolint:unused,structcheck // logger is only used on linux
96
}
97
98
// UnmarshalYAML implements yaml.Unmarshaler for Config
99
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
100
*c = DefaultConfig
101
102
type plain Config
103
err := unmarshal((*plain)(c))
104
if err != nil {
105
return err
106
}
107
108
// In the cadvisor cmd, these are passed as CSVs, and turned into slices using strings.split. As a result the
109
// default values are always a slice with 1 or more elements.
110
// See: https://github.com/google/cadvisor/blob/v0.43.0/cmd/cadvisor.go#L136
111
if len(c.AllowlistedContainerLabels) == 0 {
112
c.AllowlistedContainerLabels = []string{""}
113
}
114
if len(c.RawCgroupPrefixAllowlist) == 0 {
115
c.RawCgroupPrefixAllowlist = []string{""}
116
}
117
if len(c.EnvMetadataAllowlist) == 0 {
118
c.EnvMetadataAllowlist = []string{""}
119
}
120
return nil
121
}
122
123
// Name returns the name of the integration that this config represents.
124
func (c *Config) Name() string {
125
return name
126
}
127
128
// InstanceKey returns the agentKey
129
func (c *Config) InstanceKey(agentKey string) (string, error) {
130
return agentKey, nil
131
}
132
133
func init() {
134
integrations.RegisterIntegration(&Config{})
135
integrations_v2.RegisterLegacy(&Config{}, integrations_v2.TypeSingleton, metricsutils.Shim)
136
}
137
138