package cadvisor12import (3"time"45"github.com/go-kit/log"6"github.com/grafana/agent/pkg/integrations"7integrations_v2 "github.com/grafana/agent/pkg/integrations/v2"8"github.com/grafana/agent/pkg/integrations/v2/metricsutils"9)1011const name = "cadvisor"1213// DefaultConfig holds the default settings for the cadvisor integration14var DefaultConfig = Config{15// Common cadvisor config defaults16StoreContainerLabels: true,17ResctrlInterval: 0,1819StorageDuration: 2 * time.Minute,2021// Containerd config defaults22Containerd: "/run/containerd/containerd.sock",23ContainerdNamespace: "k8s.io",2425// Docker config defaults26Docker: "unix:///var/run/docker.sock",27DockerTLS: false,28DockerTLSCert: "cert.pem",29DockerTLSKey: "key.pem",30DockerTLSCA: "ca.pem",3132// Raw config defaults33DockerOnly: false,34}3536// Config controls cadvisor37type Config struct {38// Common cadvisor config options39// 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.40StoreContainerLabels bool `yaml:"store_container_labels,omitempty"`4142// 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.43AllowlistedContainerLabels []string `yaml:"allowlisted_container_labels,omitempty"`4445// 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.46EnvMetadataAllowlist []string `yaml:"env_metadata_allowlist,omitempty"`4748// RawCgroupPrefixAllowlist list of cgroup path prefix that needs to be collected even when -docker_only is specified.49RawCgroupPrefixAllowlist []string `yaml:"raw_cgroup_prefix_allowlist,omitempty"`5051// PerfEventsConfig path to a JSON file containing configuration of perf events to measure. Empty value disabled perf events measuring.52PerfEventsConfig string `yaml:"perf_events_config,omitempty"`5354// ResctrlInterval resctrl mon groups updating interval. Zero value disables updating mon groups.55ResctrlInterval int `yaml:"resctrl_interval,omitempty"`5657// DisableMetrics list of `metrics` to be disabled.58DisabledMetrics []string `yaml:"disabled_metrics,omitempty"`5960// EnableMetrics list of `metrics` to be enabled. If set, overrides 'disable_metrics'.61EnabledMetrics []string `yaml:"enabled_metrics,omitempty"`6263// StorageDuration length of time to keep data stored in memory (Default: 2m)64StorageDuration time.Duration `yaml:"storage_duration,omitempty"`6566// Containerd config options67// Containerd containerd endpoint68Containerd string `yaml:"containerd,omitempty"`6970// ContainerdNamespace containerd namespace71ContainerdNamespace string `yaml:"containerd_namespace,omitempty"`7273// Docker config options74// Docker docker endpoint75Docker string `yaml:"docker,omitempty"`7677// DockerTLS use TLS to connect to docker78DockerTLS bool `yaml:"docker_tls,omitempty"`7980// DockerTLSCert path to client certificate81DockerTLSCert string `yaml:"docker_tls_cert,omitempty"`8283// DockerTLSKey path to private key84DockerTLSKey string `yaml:"docker_tls_key,omitempty"`8586// DockerTLSCA path to trusted CA87DockerTLSCA string `yaml:"docker_tls_ca,omitempty"`8889// Raw config options90// DockerOnly only report docker containers in addition to root stats91DockerOnly bool `yaml:"docker_only,omitempty"`9293// Hold on to the logger passed to config.NewIntegration, to be passed to klog, as yet another unsafe global that needs to be set.94logger log.Logger //nolint:unused,structcheck // logger is only used on linux95}9697// UnmarshalYAML implements yaml.Unmarshaler for Config98func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {99*c = DefaultConfig100101type plain Config102err := unmarshal((*plain)(c))103if err != nil {104return err105}106107// In the cadvisor cmd, these are passed as CSVs, and turned into slices using strings.split. As a result the108// default values are always a slice with 1 or more elements.109// See: https://github.com/google/cadvisor/blob/v0.43.0/cmd/cadvisor.go#L136110if len(c.AllowlistedContainerLabels) == 0 {111c.AllowlistedContainerLabels = []string{""}112}113if len(c.RawCgroupPrefixAllowlist) == 0 {114c.RawCgroupPrefixAllowlist = []string{""}115}116if len(c.EnvMetadataAllowlist) == 0 {117c.EnvMetadataAllowlist = []string{""}118}119return nil120}121122// Name returns the name of the integration that this config represents.123func (c *Config) Name() string {124return name125}126127// InstanceKey returns the agentKey128func (c *Config) InstanceKey(agentKey string) (string, error) {129return agentKey, nil130}131132func init() {133integrations.RegisterIntegration(&Config{})134integrations_v2.RegisterLegacy(&Config{}, integrations_v2.TypeSingleton, metricsutils.Shim)135}136137138