Alertmanger-深入理解告警原理
Alertmanger-深入理解告警原理AlertManager架构图
Alert Provider:API收到来自Prometheus的告警,存储到Alert Provider
原理是内置了Map
Dispatcher组件: 这是一个单独的goroutine,不断地通过订阅的方式从Alert Provider获取新的告警,并且根据YAML配置的Routing Tree将告警通过Label路由到不同的分组中,以实现告警信息的分组处理
Notification Pipeline组件:顾名思义,这是一个责任链模式的组件,它通过一系列逻辑(如抑制、静默、去重等)来优化告警质量。 在源码中,它是通过一个个实现Stage接口的具有不同功能的实例串联 起来得到的
Silence Provider组件:API层将来自Prometheus服务端的告警信息 存储到Silence Provider上,然后由这个组件实现去重逻辑处理。静默规 则用来关闭部分告警的通知
Notify Provider组件:它是Silence Provider组件的下游,会在本地记录日志,Peers的方式将日志广播 ...
K8s核心资源对象-Pod(创建流程)
K8s核心资源对象-Pod(创建流程)
基于1.25
如何创建Pod容器通过kubelet 创建
Ref:https://github.com/kubernetes/kubernetes/blob/88e994f6bf8fc88114c5b733e09afea339bea66d/pkg/kubelet/kuberuntime/kuberuntime_manager.go#L668
// SyncPod syncs the running pod into the desired pod by executing following steps://// 1. Compute sandbox and container changes.// 2. Kill pod sandbox if necessary.// 3. Kill any containers that should not be running.// 4. Create sandbox if necessary.// 5. Create ephemeral containers.// 6. Create ...
K8s核心资源对象-Pod(Container)
K8s核心资源对象-Pod(Container)
基于1.25
Container相关字段
Ref:https://github.com/kubernetes/kubernetes/blob/88e994f6bf8fc88114c5b733e09afea339bea66d/pkg/apis/core/types.go#L2167
// Container represents a single container that is expected to be run on the host.type Container struct { // Required: This must be a DNS_LABEL. Each container in a pod must // have a unique name. Name string // Required. Image string // Optional: The container image's entrypoint is used if this is not provided; cannot ...
K8s核心资源对象-Pod(PodSpec)
K8s核心资源对象-Pod(PodSpec)
基于1.25
什么是PodPod是K8s最小可部署的单元。一个Pod可以有多个容器
每一个Pod,预置了一个Pause容器,其命名空间、IPC、网络和存储资源被Pod中其他容器共享
Ref:https://github.com/kubernetes/api/blob/2be23f6c5a7184af9846ff458a11751765ea2bde/core/v1/types.go#L3721
type PodSpec struct { // List of volumes that can be mounted by containers belonging to the pod. // More info: https://kubernetes.io/docs/concepts/storage/volumes // +optional // +patchMergeKey=name // +patchStrategy=merge,retainKeys Volumes []Volume `json:"volume ...
K8s核心资源对象- 概述(元数据- metav1.ObjectMeta)
K8s核心资源对象- 概述(元数据- metav1.ObjectMeta)
基于1.25
K8s资源对象K8s中主要按照:工作负载(Workload)、发现和负载均衡(Discovery & LB)、配置和存储(Config & Storage)
下面介绍一下metav1.ObjectMeta的属性
NameName是资源对象的入门属性,但是资源对象不一定是客户端传入的Name
PodName
Ref:https://github.com/kubernetes/kubernetes/blob/88e994f6bf8fc88114c5b733e09afea339bea66d/pkg/kubelet/config/common.go#L52
// Generate a pod name that is unique among nodes by appending the nodeName.func generatePodName(name string, nodeName types.NodeName) string { return fmt.Spr ...
容器环境-GOMAXPROCS参数设置
容器环境-GOMAXPROCS参数设置
GOMAXPROCS通过设定 GOMAXPROCS,用户可以调整调度器中 Processor(简称P)的数量。由于每个系统线程,必须要绑定 P ,P 才能把G交给 M 执行。所以 P 的数量会很大程度上影响 Go Runtime 的并发表现。GOMAXPROCS 在版本 1.5后的默认值是机器的 CPU 核数 (runtime.NumCPU)
设置GOMAXPROCSpackage mainimport ( "fmt" "runtime")func main() { n := runtime.NumCPU() // 获取机器的CPU核心数 fmt.Printf("NumCPU: %d\n", n) if n > 0 { runtime.GOMAXPROCS(n) // 设置GOMAXPROCS为CPU核心数 }}
容器内运行输出的是宿主机的CPU核心数
解决方案
go get go.ub ...
Go-Options模式
Go-Options模式Options模式Options模式可以让具有多个可选参数的函数或者方法更整洁和好扩展,当一个函数具有五六个甚至十个以上的可选参数时使用这种模式的优势会体现的很明显
问题当我们发送一个Http请求,可能需要携带很多参数。比如:
func HttpRequest(method string, url string, body []byte, headers map[string]string, timeout time.Duration)
有的时候又可能有些参数是不需要的,所以可能变成了:
HttpRequest('GET', 'https://www.baidu.com', nil, nil, 2 * time.Second)
解决办法一:把配置全转换为结构体对象type HttpClientConfig struct { timeout time.Duration headers map[string]string body []byte}func HttpRequest(metho ...
Prometheus源码:存储指标
Prometheus源码:存储指标
基于release-3.0
存储指标结构// File Path: scrape/scrapetype scrapeCache struct { // 被缓存的批次数 iter uint64 // Current scrape iteration. // 上次成功时有多少序列和元数据条目。 // How many series and metadata entries there were at the last success. successfulCount int // Parsed string to an entry with information about the actual label set // and its storage reference. series map[string]*cacheEntry // Cache of dropped metric strings and their iteration. The iteration must // be a pointer so we c ...
Prometheus源码:指标采集
Prometheus源码:指标采集
基于release-3.0
指标采集的流程
构造ScrapeManager实例
加载配置
启动ScrapeManger实例
ScrapeManager负责维护scrapePool,并且管理scrape组件的生命周期。
ScrapeManager调用NewManager方法完成对ScrapeManager实例的创建:
// FILE PATH:scrape/manager.gotype Manager struct { opts *Options // 系统日志记录 logger log.Logger // 指标存储器 append storage.Appendable graceShut chan struct{} offsetSeed uint64 // Global offsetSeed seed is used to spread scrape workload across HA setup. // 同步访问控制锁(读写锁) ...
Prometheus源码:服务发现
Prometheus源码:服务发现服务发现的定义流程:
scrape发现服务进行统一管理,Prometheus对所支持的发 现服务都抽象出Discoverer接口,各scrape发现服务都必须实现该接 口并用于服务发现
Discover接口定义了Run()接口:
// FILE Path:prometheus/discovery/discoverytype Discoverer interface { // Run hands a channel to the discovery provider (Consul, DNS, etc.) through which // it can send updated target groups. It must return when the context is canceled. // It should not close the update channel on returning. Run(ctx context.Context, up chan<- []*targetgroup.Grou ...