像许多开发人员一样,我们将这种方法应用到我们设计和构建的所有软件中。
常规的K8s指标监控方法
选择轻量化
Kubelet是什么?
深入Kubelet源码
你可以在这里找到一些指标定义
pkg/kubelet/server/server.go:
/metrics/cadvisor:该接口源自cadvisor,它提供了容器资源消耗的所有度量,例如:CPU、内存、文件系统、网络。
-
/metrics/resource:该接口列出容器资源(CPU,内存),和cadvisor接口类似,但也提供pod级和节点级资源使用情况。 -
/stats/summary:该接口以JSON格式提供聚合的资源消耗数据。默认情况下,它将描述所有资源(CPU、内存、文件系统和网络,就像cadvisor接口一样),但是你可以传递一个only_cpu_and_memory=true的标志作为请求参数,则只获得CPU和内存数据。
下面是接口的响应结构:
type Summary struct {
// Overall node stats.
Node NodeStats `json:"node"`
// Per-pod stats.
Pods []PodStats `json:"pods"`
}
// NodeStats holds node-level unprocessed sample stats.
type NodeStats struct {
// Reference to the measured Node.
NodeName string `json:"nodeName"`
// Stats of system daemons tracked as raw containers.
// The system containers are named according to the SystemContainer* constants.
SystemContainers []ContainerStats `json:"systemContainers,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
// The time at which data collection for the node-scoped (i.e. aggregate) stats was (re)started.
StartTime metav1.Time `json:"startTime"`
// Stats pertaining to CPU resources.
CPU *CPUStats `json:"cpu,omitempty"`
// Stats pertaining to memory (RAM) resources.
Memory *MemoryStats `json:"memory,omitempty"`
// Stats pertaining to network resources.
Network *NetworkStats `json:"network,omitempty"`
// Stats pertaining to total usage of filesystem resources on the rootfs used by node k8s components.
// NodeFs.Used is the total bytes used on the filesystem.
Fs *FsStats `json:"fs,omitempty"`
// Stats about the underlying container runtime.
Runtime *RuntimeStats `json:"runtime,omitempty"`
// Stats about the rlimit of system.
Rlimit *RlimitStats `json:"rlimit,omitempty"`
}
// PodStats holds pod-level unprocessed sample stats.
type PodStats struct {
// Reference to the measured Pod.
PodRef PodReference `json:"podRef"`
// The time at which data collection for the pod-scoped (e.g. network) stats was (re)started.
StartTime metav1.Time `json:"startTime"`
// Stats of containers in the measured pod.
Containers []ContainerStats `json:"containers" patchStrategy:"merge" patchMergeKey:"name"`
// Stats pertaining to CPU resources consumed by pod cgroup (which includes all containers' resource usage and pod overhead).
CPU *CPUStats `json:"cpu,omitempty"`
// Stats pertaining to memory (RAM) resources consumed by pod cgroup (which includes all co
-
/pods:该接口提供有关在节点上运行的pod的信息,以及完整的pod规格和状态。还可以使用K8s客户端的podLister接口获取该数据。虽然有用,但这个特定的数据与我们的资源度量监控无关。 -
/metrics:这个接口公开了与Kubelet自己的内部统计数据相关的指标。了解下就可以了,它不会用于我们的需求。
现在看看Murre项目
Murre利用3种不同的API来获取并提供这些指标所需的数据:
1、NodeList: 为了发现和维护所有可用节点的列表。
2、/metrics/cadvisor:获得容器实际的资源使用指标。如前所述,这个API用于每个节点。
3、PodList:用K8s对每个容器的资源请求和限制来丰富数据。
下面是Murre的处理流程:
项目地址:
https://github.com/groundcover-com/murre/blob/main/images/demo.gif
原文始发于微信公众号(LemonSec):Murre:一个轻量化的K8S监控工具
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论