Prometheus
给 Node Exporter 添加抓取凭证
· ☕ 1 分钟
1. 背景 Node Exporter 是 Prometheus 生态系统中用于收集主机指标的常用组件,但默认情况下不提供访问认证。本文介绍如何为 Kubernetes 环境中的 Node Exporter 添加基本认证,提高安全性。 2. Node Exporter 配置凭证 2.1 生成加密密码 使用 htpasswd 工具生成加密密码: 1 htpasswd -nBC 12 "" | tr -d ':\n' 这里需要输入密码,生成的输出将是一个

部署 smokeping-prober 探测网络质量
· ☕ 1 分钟
1. smokeping-prober 是什么 smokeping-prober 是一个用于探测网络质量的工具,它通过向目标节点发送 ICMP 请求来探测网络质量。 2. 部署 smokeping-prober 2.1 生成 smokeping-prober.yaml 配置文件 1 2 3 4 5 6 7 8 9 10 11 cat > smokeping_prober.yaml <<EOF --- targets: - hosts: - 1.2.3.4 interval: 1s # Duration, Default 1s. network: ip # One of ip, ip4, ip6. Default: ip (automatic IPv4/IPv6) protocol: icmp # One of icmp, udp. Default: icmp (Requires privileged operation) size: 56 # Packet data size in bytes. Default 56 (Range: 24 - 65535) tos:

使用集群内 Prometheus 采集 Etcd 指标
· ☕ 1 分钟
1. 跳过证书校验无法获取监控 如果指标抓取时,能跳过 TLS 认证是最便捷的。其 Prometheus 的 ConfigMap 配置如下: 1 2 3 4 5 6 7 8 9 - job_name: etcd metrics_path: /metrics scheme: https tls_config: insecure_skip_verify: true static_configs: - targets: ["1.1.1.1:2379"] - targets: ["2.2.2.2:2379"] - targets: ["3.3.3.3:2379"] 但 Prometheus Targets 报错 Get "https://3.3.3.3:2379/metrics": remote error: tls: bad certificate 在 targets 页面的报错如下图: 2. curl 验证抓取请求 跳过证书 1 2 3 curl https://1.1.1.1:2379/metrics -k curl: (35) error:1401E412:SSL routines:CONNECT_CR_FINISHED:sslv3 alert bad certificate 这

如何估算 Prometheus 的本地存储和内存消耗
· ☕ 2 分钟
1. 本地存储容量 所需磁盘大小(GB) = 数据保留时长 _ 每秒获取指标数量 _ 指标数据大小 / 1024 / 1024 / 1024 其中 每秒获取指标数量 rate(prometheus_tsdb_head_samples_appended_total[1d]) 一个小时内样本的平均大小 rate(prometheus_tsdb_compaction_chunk_size_bytes_sum[1d])/rate(prometheus_tsdb_compaction_chunk_samples_sum[1d]) 一天(86400 秒)的磁盘消耗,可以在 Prometheus 中直接查询: 86400 * (rate(prometheus_tsdb_head_samples_appended_total[1d]) * (rate(prometheus_tsdb_compaction_chunk_size_bytes_sum[1d]) / rate(prometheus_tsdb_compaction_chunk_samples_sum[1d]))) / 1024 /1024 / 1024 例如,返回 {instance="localhost:9090", job="prometheus"} 4.437

常用的各类资源 Prometheus 告警语句
· ☕ 4 分钟
主机 主机内存使用率超过阈值 1 - node_memory_MemAvailable_bytes{mode!="idle"} / node_memory_MemTotal_bytes 阈值:0.9 主机 CPU 使用率超过阈值 1 - avg(irate(node_cpu_seconds_total{mode="idle"}[5m])) by (host_name) 阈值:0.85 主机硬盘使用率超过阈值 1 - avg without (fstype)(node_filesystem_free_bytes{fstype!='rootfs',mountpoint!~'/(run|var|snap).*'} / node_filesystem_size_bytes{fstype!='rootfs',mountpoint!~'/(run|var|snap).*'}) 阈值:0.8 Windows Windows 主机内存使用率超过阈值 1 - 1 * windows_os_physical_memory_free_bytes{job="windows_exporter",mode!="idle"} / windows_cs_physical_memory_bytes 阈值:0.9 Windows 主机 CPU 使用率超过阈值 1 - (avg by (host_ip,host_name) (irate(windows_cpu_time_total{job="windows_exporter",mode="idle"}[1m]))) 阈值:0.85