Promethus之AlertManager介绍

简介: prometheus 告警组件 alertmanager 介绍,可以独立于prometheus使用,提供告警聚合,告警灵活配置功能。

总的流程图:

image2019_6_3_15_21_34

alerts:

alert概念
这里先简单介绍下AlertManager中对告警的概念和状态描述。告警对应一个告警事件,包括告警名称,告警时间,告警状态以及其他告警详细说明(自定义),其描述结构如下:

[
{
    "startsAt": "2019-06-03T03:32:20.859Z",
    "endsAt": "2019-06-03T03:32:20.859Z",
    "annotations":
    {
        "additionalProp1": "string",
        "additionalProp2": "string",
        "additionalProp3": "string"
    },
    "labels":
    {
        "additionalProp1": "string",
        "additionalProp2": "string",
        "additionalProp3": "string"
    },
    "generatorURL": "string"
}
]

告警唯一标识:
唯一标识为labels所有项组合起来计算得到的一个指纹信息,所以可以认为labels组就是一个唯一标识。他来进行告警合并和更新告警状态。

参考代码如下:

// Fingerprint returns a unique hash for the alert. It is equivalent to
// the fingerprint of the alert's label set.
func (a *Alert) Fingerprint() Fingerprint {
    return a.Labels.Fingerprint()
}
// labelSetToFingerprint works exactly as LabelsToSignature but takes a LabelSet as
// parameter (rather than a label map) and returns a Fingerprint.
func labelSetToFingerprint(ls LabelSet) Fingerprint {
    if len(ls) == 0 {
        return Fingerprint(emptyLabelSignature)
    }
 
 
    labelNames := make(LabelNames, 0, len(ls))
    for labelName := range ls {
        labelNames = append(labelNames, labelName)
    }
    sort.Sort(labelNames)
 
    sum := hashNew()
    for _, labelName := range labelNames {
        sum = hashAdd(sum, string(labelName))
        sum = hashAddByte(sum, SeparatorByte)
        sum = hashAdd(sum, string(ls[labelName]))
        sum = hashAddByte(sum, SeparatorByte)
    }
    return Fingerprint(sum)
}

告警状态:
firing和resolved,这个值是manager根据收到了alert结构来自行判断并赋值的,manager是怎么判断firing呢?

firing: endsAt为空,或者当前时间小于等于endsAt时为告警。

resolved:endsAt不为空且大于当前时间

参考代码如下:

// Resolved returns true iff the activity interval ended in the past.
func (a *Alert) Resolved() bool {
    return a.ResolvedAt(time.Now())
}
 
 
// ResolvedAt returns true off the activity interval ended before
// the given timestamp.
func (a *Alert) ResolvedAt(ts time.Time) bool {
    if a.EndsAt.IsZero() {
        return false
    }
    return !a.EndsAt.After(ts)
}

router

路由可以是一个树形结构,通过这个结构可以灵活的配置一个告警的流转路径。

根节点:router,根节点。父节点所有属性可以被子节点继承,所以根节点的属性相当于全局默认属性。

子节点:routers,子节点可以是0个或多个,子节点可以单独配置属性以覆盖父节点的属性。

每个router可以包含以下属性

流程控制:

  • match,match_re 是匹配规则,这个是每个router选择的依据。前者是等于匹配,后者是正则匹配。
  • continue,告警是否继续向下路由,如果是否则终止于此节点不再向下路由。
  • group规则:告警聚合规则

receiver:指定接收端,可以理解为处理方式。

group

分组操作主要是应用于将同一类告警归集为一个告警通知中,

一个特别典型的应用场景:当某核心服务或组件故障,可能引发成百上千的同类型告警,此时这个分组聚合,就会使告警通知有效减少,使告警通知保持清晰,有效。

分组有三个参数:

group by:指定分组依据哪个label,可以是多个以逗号隔开。

group_wait:分组聚合时间窗口,当第一个新分组开始到发送告警的等待时间,系统会将这段时间的同组告警合并为一条。

group_interval :同一分组的告警发送间隔,如果分组1已经成功发送了,后来的告警也还属于分组1,则等待这个间隔时间后再发送。

storage

不支持历史存储,只存储告警快照

(1)告警状态快照,未恢复的告警。存储周期可以配置,默认120小时

     结构:map,key GroupKey:r.GroupName,/r.Integration,/r.Idx   value:MeshEntry

具体结构如下:


type MeshEntry struct {
 // The original raw notify log entry.
 Entry *Entry `protobuf:"bytes,1,opt,name=entry,proto3" json:"entry,omitempty"`
 // A timestamp indicating when the mesh peer should evict
 // the log entry from its state.
 ExpiresAt time.Time `protobuf:"bytes,2,opt,name=expires_at,json=expiresAt,proto3,stdtime" json:"expires_at"`
 XXX_NoUnkeyedLiteral struct{} `json:"-"`
 XXX_unrecognized []byte `json:"-"`
 XXX_sizecache int32 `json:"-"`
}
type Entry struct {
 // The key identifying the dispatching group.
 GroupKey []byte `protobuf:"bytes,1,opt,name=group_key,json=groupKey,proto3" json:"group_key,omitempty"`
 // The receiver that was notified.
 Receiver *Receiver `protobuf:"bytes,2,opt,name=receiver,proto3" json:"receiver,omitempty"`
 // Hash over the state of the group at notification time.
 // Deprecated in favor of FiringAlerts field, but kept for compatibility.
 GroupHash []byte `protobuf:"bytes,3,opt,name=group_hash,json=groupHash,proto3" json:"group_hash,omitempty"`
 // Whether the notification was about a resolved alert.
 // Deprecated in favor of ResolvedAlerts field, but kept for compatibility.
 Resolved bool `protobuf:"varint,4,opt,name=resolved,proto3" json:"resolved,omitempty"`
 // Timestamp of the succeeding notification.
 Timestamp time.Time `protobuf:"bytes,5,opt,name=timestamp,proto3,stdtime" json:"timestamp"`
 // FiringAlerts list of hashes of firing alerts at the last notification time.
 FiringAlerts []uint64 `protobuf:"varint,6,rep,packed,name=firing_alerts,json=firingAlerts,proto3" json:"firing_alerts,omitempty"`
 // ResolvedAlerts list of hashes of resolved alerts at the last notification time.
 ResolvedAlerts []uint64 `protobuf:"varint,7,rep,packed,name=resolved_alerts,json=resolvedAlerts,proto3" json:"resolved_alerts,omitempty"`
 XXX_NoUnkeyedLiteral struct{} `json:"-"`
 XXX_unrecognized []byte `json:"-"`
 XXX_sizecache int32 `json:"-"`
}

(2)告警静音状态。

存储周期由静音规则配置。

目录
相关文章
|
JavaScript 安全 API
告别 Vuex?Pinia:轻量高效的状态管理新选择
告别 Vuex?Pinia:轻量高效的状态管理新选择
682 84
|
SQL 存储 运维
数据库生态工具&架构方案| 学习笔记(一)
快速学习数据库生态工具&架构方案
1306 0
数据库生态工具&架构方案| 学习笔记(一)
|
测试技术 数据安全/隐私保护 Python
刷视频脚本,抖音快手小红书,自动看广告刷视频【python】
这个代码示例展示了如何使用Selenium和PyAutoGUI模拟视频观看行为,包括登录、观看视频
|
Prometheus Kubernetes 监控
Kubernetes监控:Prometheus与AlertManager结合,配置邮件告警。
完成这些步骤之后,您就拥有了一个可以用邮件通知你的Kubernetes监控解决方案了。当然,所有的这些配置都需要相互照应,还要对你的Kubernetes集群状况有深入的了解。希望这份指南能帮助你创建出适合自己场景的监控系统,让你在首次发现问题时就能做出响应。
931 22
|
运维 Prometheus 监控
🎉 WatchAlert - 开源多数据源告警引擎【运维研发必备能力】
WatchAlert 是一个开源的多数据源告警引擎,支持从 Prometheus、Elasticsearch、Kubernetes 等多种数据源获取监控数据,并根据预定义的告警规则触发告警。它具备多数据源支持、灵活的告警规则、多渠道告警通知、可扩展架构和高性能等核心特性,帮助团队更高效地监控和响应问题。项目地址:https://github.com/opsre/WatchAlert
2234 18
🎉 WatchAlert - 开源多数据源告警引擎【运维研发必备能力】
|
数据采集 Prometheus 监控
Prometheus的告警规则
Prometheus的告警规则
884 11
|
机器学习/深度学习 人工智能 分布式计算
【AI系统】分布式通信与 NVLink
进入大模型时代后,AI的核心转向大模型发展,训练这类模型需克服大量GPU资源及长时间的需求。面对单个GPU内存限制,跨多个GPU的分布式训练成为必要,这涉及到分布式通信和NVLink技术的应用。分布式通信允许多个节点协作完成任务,而NVLink则是一种高速、低延迟的通信技术,用于连接GPU或GPU与其它设备,以实现高性能计算。随着大模型的参数、数据规模扩大及算力需求增长,分布式并行策略,如数据并行和模型并行,变得至关重要。这些策略通过将模型或数据分割在多个GPU上处理,提高了训练效率。此外,NVLink和NVSwitch技术的持续演进,为GPU间的高效通信提供了更强的支持,推动了大模型训练的快
802 0
|
存储 Prometheus 监控
Alertmanager配置概述及告警规则
Alertmanager配置概述及告警规则
|
存储 Prometheus Cloud Native
prometheus学习笔记之PromQL
prometheus学习笔记之PromQL
1378 3
|
Prometheus Cloud Native 数据挖掘
搭建数据分析系统 Grafana 详细指南
搭建Grafana数据分析系统涉及安装Docker和拉取Grafana容器,然后配置Prometheus数据源,创建仪表盘和面板,以及设置告警规则。利用Grafana的可视化功能,可以将数据直观展示并进行监控。系统还支持导入导出仪表盘,便于协作和管理。