kubernetes

package
v0.0.0-...-5655933 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 12 Imported by: 0

README

kubernetes

forked from telegraf/kubernetes. 这个插件的作用是通过kubelet提供的API获取监控数据,包括系统容器的监控数据、node的、pod数据卷的、pod网络的、pod容器的

Change

增加了一些控制开关:

gather_system_container_metrics = true

是否采集 system 容器(kubelet、runtime、misc、pods),比如 kubelet 一般就是静态容器,非业务容器

gather_node_metrics = true

是否采集 node 层面的指标,机器层面的指标其实 categraf 来采集了,这里理论上不需要再采集了,可以设置为 false,采集也没问题,也没多少数据

gather_pod_container_metrics = true

是否采集 Pod 中的容器的指标,这些 Pod 一般是业务容器

gather_pod_volume_metrics = true

是否采集 Pod 的数据卷的指标

gather_pod_network_metrics = true

是否采集 Pod 的网络监控数据

容器监控

通过这些开关可以看出,kubernetes 这个插件,采集的只是 pod、容器的监控指标,这些指标数据来自 kubelet 的 /stats/summary /pods 等接口。那么问题来了,容器监控到底是应该读取 /metrics/cadvisor 接口还是应该用这个 kubernetes 插件?有几个决策依据:

  1. /metrics/cadvisor 采集的数据没有业务自定义标签,kubernetes 这个插件会自动带上业务自定义标签。但是业务标签可能比较混乱,建议每个公司制定规范,比如要求业务只能打 project、region、env、service、app、job 等标签,其他标签都过滤掉,通过 kubernetes 插件的 label_include label_exclude 配置,可以做标签过滤。
  2. kubernetes 这个插件采集的数据比 /metrics/cadvisor 吐出的指标要少,不过常见的 cpu、mem、net、volume 相关的也都有。

kubelet 监控

kubelet 的监控更推荐的做法:使用 prometheus 插件采集其 /metrics 接口,针对这种方式采集的数据,我们提供了监控大盘,在本 README 的同级目录下:kubelet-metrics-dash.json,可以直接导入夜莺使用。请使用 Categraf v0.1.7 以上的版本。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CPUMetrics

type CPUMetrics struct {
	Time                 time.Time `json:"time"`
	UsageNanoCores       int64     `json:"usageNanoCores"`
	UsageCoreNanoSeconds int64     `json:"usageCoreNanoSeconds"`
}

CPUMetrics represents the cpu usage data of a pod or node

type ContainerMetrics

type ContainerMetrics struct {
	Name      string            `json:"name"`
	StartTime time.Time         `json:"startTime"`
	CPU       CPUMetrics        `json:"cpu"`
	Memory    MemoryMetrics     `json:"memory"`
	RootFS    FileSystemMetrics `json:"rootfs"`
	LogsFS    FileSystemMetrics `json:"logs"`
}

ContainerMetrics represents the metric data collect about a container from the kubelet

type FileSystemMetrics

type FileSystemMetrics struct {
	AvailableBytes int64 `json:"availableBytes"`
	CapacityBytes  int64 `json:"capacityBytes"`
	UsedBytes      int64 `json:"usedBytes"`
}

FileSystemMetrics represents disk usage metrics for a pod or node

type Instance

type Instance struct {
	config.InstanceConfig

	URL string

	// Bearer Token authorization file path
	BearerToken       string `toml:"bearer_token"`
	BearerTokenString string `toml:"bearer_token_string"`

	LabelInclude []string `toml:"label_include"`
	LabelExclude []string `toml:"label_exclude"`

	GatherSystemContainerMetrics bool `toml:"gather_system_container_metrics"`
	GatherNodeMetrics            bool `toml:"gather_node_metrics"`
	GatherPodContainerMetrics    bool `toml:"gather_pod_container_metrics"`
	GatherPodVolumeMetrics       bool `toml:"gather_pod_volume_metrics"`
	GatherPodNetworkMetrics      bool `toml:"gather_pod_network_metrics"`

	// HTTP Timeout specified as a string - 3s, 1m, 1h
	ResponseTimeout config.Duration

	tls.ClientConfig

	RoundTripper http.RoundTripper
	// contains filtered or unexported fields
}

func (*Instance) Gather

func (ins *Instance) Gather(slist *types.SampleList)

func (*Instance) Init

func (ins *Instance) Init() error

func (*Instance) LoadJSON

func (ins *Instance) LoadJSON(url string, v interface{}) error

type Item

type Item struct {
	Metadata Metadata `json:"metadata"`
}

type Kubernetes

type Kubernetes struct {
	config.PluginConfig
	Instances []*Instance `toml:"instances"`
}

func (*Kubernetes) Clone

func (k *Kubernetes) Clone() inputs.Input

func (*Kubernetes) GetInstances

func (k *Kubernetes) GetInstances() []inputs.Instance

func (*Kubernetes) Name

func (k *Kubernetes) Name() string

type MemoryMetrics

type MemoryMetrics struct {
	Time            time.Time `json:"time"`
	AvailableBytes  int64     `json:"availableBytes"`
	UsageBytes      int64     `json:"usageBytes"`
	WorkingSetBytes int64     `json:"workingSetBytes"`
	RSSBytes        int64     `json:"rssBytes"`
	PageFaults      int64     `json:"pageFaults"`
	MajorPageFaults int64     `json:"majorPageFaults"`
}

MemoryMetrics represents the memory metrics for a pod or node

type Metadata

type Metadata struct {
	Name      string            `json:"name"`
	Namespace string            `json:"namespace"`
	Labels    map[string]string `json:"labels"`
}

type NetworkMetrics

type NetworkMetrics struct {
	Time     time.Time `json:"time"`
	RXBytes  int64     `json:"rxBytes"`
	RXErrors int64     `json:"rxErrors"`
	TXBytes  int64     `json:"txBytes"`
	TXErrors int64     `json:"txErrors"`
}

NetworkMetrics represents network usage data for a pod or node

type NodeMetrics

type NodeMetrics struct {
	NodeName         string             `json:"nodeName"`
	SystemContainers []ContainerMetrics `json:"systemContainers"`
	StartTime        time.Time          `json:"startTime"`
	CPU              CPUMetrics         `json:"cpu"`
	Memory           MemoryMetrics      `json:"memory"`
	Network          NetworkMetrics     `json:"network"`
	FileSystem       FileSystemMetrics  `json:"fs"`
	Runtime          RuntimeMetrics     `json:"runtime"`
}

NodeMetrics represents detailed information about a node

type PodMetrics

type PodMetrics struct {
	PodRef     PodReference       `json:"podRef"`
	StartTime  *time.Time         `json:"startTime"`
	Containers []ContainerMetrics `json:"containers"`
	Network    NetworkMetrics     `json:"network"`
	Volumes    []VolumeMetrics    `json:"volume"`
}

PodMetrics contains metric data on a given pod

type PodReference

type PodReference struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
}

PodReference is how a pod is identified

type Pods

type Pods struct {
	Kind       string `json:"kind"`
	APIVersion string `json:"apiVersion"`
	Items      []Item `json:"items"`
}

type RuntimeMetrics

type RuntimeMetrics struct {
	ImageFileSystem FileSystemMetrics `json:"imageFs"`
}

RuntimeMetrics contains metric data on the runtime of the system

type SummaryMetrics

type SummaryMetrics struct {
	Node NodeMetrics  `json:"node"`
	Pods []PodMetrics `json:"pods"`
}

SummaryMetrics represents all the summary data about a particular node retrieved from a kubelet

type VolumeMetrics

type VolumeMetrics struct {
	Name           string `json:"name"`
	AvailableBytes int64  `json:"availableBytes"`
	CapacityBytes  int64  `json:"capacityBytes"`
	UsedBytes      int64  `json:"usedBytes"`
}

VolumeMetrics represents the disk usage data for a given volume

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL