此解决方案利用开源工具如ClickHouse、Neo4j、VectorDB、PromQL、LogQL、OpenTracing、Prometheus、Grafana、AlertManager和DeepFlow。这个开源的可观察性平台解决方案通过GitHub Actions自动交付,以创建服务。
在完成平台安装和部署后(有关详细信息,请参阅先前的文章:https://cloud.tencent.com/developer/article/2363793),登录到控制台。以 onwalk.net 域配置为例:
例如, 在 https://grafana.onwalk.net 上以管理员身份登录,然后转到数据源 -> 添加新数据源。
Grafana Explore与Prometheus数据源集成,允许用户快速识别和解决问题。要通过Explore查看Prometheus数据,请按照以下步骤操作:
在Grafana中添加Prometheus数据源,输入Prometheus的地址和访问凭据。打开Grafana Explore,选择Prometheus数据源,并输入查询。
Grafana Explore与Loki数据源集成,用于快速解决问题。要通过Explore查看Loki日志,请按照以下步骤操作:在Grafana中添加Loki数据源,输入地址和访问凭据。打开Grafana Explore,选择Loki数据源,并输入查询。
例如,使用https://github.com/svc-design/ObservabilityServer/tree/main/example/dashboard上提供的示例仪表板JSON模板文件:
选择仪表板JSON模板文件,选择相应的数据源。导入仪表板后,从Prometheus数据源显示的可视化图表可见,包括Node Exporter和kube-state-metrics的图表。
Grafana社区提供许多仪表板,可根据需要选择,网址为https://grafana.com/grafana/dashboards/?pg=hp&plcmt=lt-box-dashboards。
在Kubernetes(k8s)集群中,部署了Prometheus,并将告警规则的配置文件存储在Kubernetes ConfigMaps中。要更改告警规则,请参考以下命令:
recording_rules用于定义新时间序列数据的配置。它们可以从现有时间序列数据计算新的指标,并将它们存储为新的时间序列数据。录制规则配置文件包含以下信息:
要修改 recording_rules 执行以下命令:
kubectl get cm observability-server-prometheus-server -n monitoring下面是用于监视主机负载、CPU使用率、内存使用率和磁盘使用率的Prometheus 告警规则的基本示例。
data:
recording_rules.yml: |
groups:
- name: host-monitoring
rules:
- record: node_load1
expr: node_load1
- record: node_cpu_usage
expr: 100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
- record: node_memory_usage
expr: (node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Buffers_bytes - node_memory_Cached_bytes) / node_memory_MemTotal_bytes * 100
- record: node_disk_usage
expr: 100 - (avg by (instance) (node_filesystem_avail_bytes{fstype="ext4"} / node_filesystem_size_bytes{fstype="ext4"}) * 100)配置说明:
此示例定义了一个名为“host-monitoring”的规则组,其中包含四个用于计算主机负载、CPU使用率、内存使用率和磁盘使用率的录制规则。
触发告警的条件,例如超过CPU使用率的阈值、磁盘空间不足等。
告警级别和标签,例如警告、严重、紧急等级,以及指示告警来源和目标的标签。
告警通知的方法,例如发送电子邮件、短信、Slack通知等。
以下是配置用于监视主机负载、CPU使用率、内存使用率和磁盘使用率的告警规则的示例:
要修改告警规则,执行以下命令:
kubectl get cm observability-server-prometheus-server -n monitoring此命令获取位于“monitoring”命名空间中的名为“observability-server-prometheus-server”的ConfigMap,其中包含告警规则的配置。
此示例定义了一个名为“host-monitoring”的告警规则组,其中包含一个告警规则。
data:
alerting_rules.yml: |
groups:
- name: host-monitoring
rules:
- alert: HighCpuUsage
expr: 100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 90 for: 5m
labels:
severity: critical
annotations:
summary: High CPU usage on {{ $labels.instance }}
description: "CPU usage is {{ $value }}%"配置说明:
此示例定义了一个名为“host-monitoring”的告警规则组,其中包含一个告警规则。
data:
alerting_rules.yml: |
groups:
- name: host-monitoring
rules:
- alert: HighMemoryUsage
expr: (node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Buffers_bytes - node_memory_Cached_bytes) / node_memory_MemTotal_bytes * 100 > 90
for: 5m
labels:
severity: warning
annotations:
summary: High memory usage on {{ $labels.instance }}
description: "Memory usage is {{ $value }}%"此示例定义了一个名为“host-monitoring”的告警规则组,其中包含1个告警规则。
HighMemoryUsage: 当主机的内存使用率超过90%时触发告警。
告警规则定义包括以下信息:告警名称、触发条件、持续时间、标签和注释。
告警规则的名称是“HighMemoryUsage”。
触发条件为“HighMemoryUsage > 90%”,如果条件持续5分钟,则触发告警。
标签“severity”设置为“warning”,表示告警严重程度为警告。
注释“summary”设置为“主机 {{ $labels.instance }} 上的高内存使用率”,提供了告警摘要。
描述提供了有关告警的附加信息,说明“内存使用率为{{ $value }}%”。
data:
alerting_rules.yml: |
groups:
- name: host-monitoring
rules:
- alert: HighDiskUsage
expr: node_filesystem_avail_bytes{fstype="ext4"} / node_filesystem_size_bytes{fstype="ext4"} * 100 < 10
for: 5m
labels:
severity: critical
annotations:
summary: High disk usage on {{ $labels.instance }}
description: "Disk usage is {{ $value }}%"配置说明:
此示例定义了一个名为“host-monitoring”的告警规则组,其中包含1个告警规则。
Alertmanager是Prometheus生态系统中的一个独立组件,用于处理和路由告警通知。Alertmanager可以与Prometheus一起工作,将告警通知发送到各种接收者,如电子邮件、Slack、PagerDuty,并支持高级功能,如抑制、分组和静音告警。
Prometheus的告警和记录规则与Alertmanager关联,您需要在Prometheus配置文件中指定Alertmanager的地址和端口。您还需要在告警规则中设置alertmanager_config字段,以确保告警通知被正确路由到Alertmanager。
在Prometheus中,您可以检查当前活动的告警规则及其状态,这些信息可以在专用页面上查看。在此页面上,您可以查看每个告警规则的信息,包括其名称、状态、标签、摘要等。您还可以使用搜索框查找特定的告警规则。通过查看此页面,您可以确认Prometheus告警规则是否正常工作,以及哪些告警规则当前处于活动状态。
以下是在Prometheus配置文件中指定Alertmanager地址和端口以将告警通知发送到alertmanager.onwalk.net的示例:
alerting:
alertmanagers:
follow_redirects: true
enable_http2: true
scheme: http
timeout: 10s
api_version: v2
static_configs:
- targets:
- alertmanager.onwalk.netAlertmanager与Prometheus之间的通信是通过HTTP完成的。当Prometheus检测到新的告警时,它会发送HTTP POST请求到Alertmanager,将告警信息转发过去。Alertmanager会处理接收到的告警通知,并根据配置文件将其发送到适当的接收者。以下是Alertmanager的参考配置:
route:
receiver: default-receiver
continue: false
group_wait: 10s
group_interval: 5m
repeat_interval: 1h
receivers:
- name: default-receiver
email_configs:
- to: 'admin@example.com'
from: 'alertmanager@example.com'
smarthost: smtp.gmail.com:587
auth_username: 'alertmanager@example.com'
auth_identity: 'alertmanager@example.com'
auth_password: 'password'确保Prometheus和Alertmanager正在运行,并且告警规则和路由规则已经正确配置。当Prometheus触发告警时,Alertmanager将接收到告警通知并将其转发到指定的接收者。Alertmanager还可以配置使用第三方插件,以用于其他类型的接收者,例如WeChat、DingTalk、AWS SNS等。根据需要进行配置,并指定如何将告警通知路由到不同的接收者在您的路由规则中。
1 Grafana 文档:https://grafana.com/docs/grafana/latest/
2 Prometheus 文档:https://prometheus.io/docs/
3 deepflow 文档:https://deepflow.io/docs/zh/
4 Loki 文档:https://grafana.com/docs/loki/latest/
5 ClickHouse 文档:https://clickhouse.tech/docs/en/
6 Qryn 文档:https://qryn.metrico.in/#/introduction
7 Alertmanager 文档:https://prometheus.io/docs/alerting/alertmanager/
8 ObservabilityServer:https://github.com/svc-design/ObservabilityServer
9 ObservabilityAgent: https://github.com/svc-design/ObservabilityAgent
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。