exporter 是 Prometheus 监控体系中的数据采集组件,collector 是 exporter 内部的模块化组件
- exporter 由多个不同 collector 组成,可以自行配置启用和禁用;collector 负责采集特定类型或来源的指标数据,再转换为 metrics 格式(OpenMetrics)供 Prometheus server 抓取
部分 collector 默认禁用原因及其启用判断的建议
- 禁用原因
- 高基数(High Cardinality): 可能产生大量时间序列
- 采集时间过长: 可能超过 Prometheus 的 scrape_interval 或 scrape_timeout
- 资源消耗大: 对主机资源要求较高
- 启用判断的建议
- 逐个启用: 一次只启用一个 collector,先在非生产环境测试
- 监控采集时间: 观察
scrape_duration_seconds指标,确保采集完成且不超时 - 关注基数变化: 监控
scrape_samples_post_metric_relabeling指标,观察基数变化
一些常用 exporter
blackbox-exporter 允许对通过 HTTP, HTTPS, DNS, TCP, ICMP, gRPC 的端点进行探测
参考资料
blackbox-exporter 配置文档
- 参考文档和样例
基本语法
prober字段可用http,tcp,unix socket,dns,icmp,grpc
除 icmp 和 grpc 外的 prober 都有的高级功能:结果的正则匹配
http- fail_if_body_json_matches_cel
- fail_if_body_json_not_matches_cel
- fail_if_body_matches_regexp
- fail_if_body_not_matches_regexp
- fail_if_header_matches
- fail_if_header_not_matches
tcp,unix socket- query_response
- expect
dnsvalidate_answer_rrs,validate_authority_rrs,validate_additional_rrs- fail_if_matches_regexp
- fail_if_all_match_regexp
- fail_if_not_matches_regexp
- fail_if_none_matches_regexp
http probe 可用字段
http_header_match_spec 可用字段
tcp probe 可用字段
unix socket probe 可用字段
dns probe 可用字段
icmp probe 可用字段
grpc probe 可用字段
helm 安装 prometheus-blackbox-exporter
- 添加 prometheus 官方 repo
helm repo add prometheus https://prometheus-community.github.io/helm-charts
配置 blackbox-exporter values
helm search repo blackbox
helm search repo prometheus/prometheus-blackbox-exporter --versions- 显示所有可用版本
- v0.28.0 日志输出有问题,这里用 v0.27.0
helm show values prometheus/prometheus-blackbox-exporter --version 11.5.0 > values.default-11.5.0.yaml
cp values.default-11.5.0.yaml values-11.5.0.yaml
vim values-11.5.0.yaml
- 启用了 serviceMonitor,labels 根据 Prometheus Operator 自行设置
helm 安装 blackbox-exporter
helm upgrade --install blackbox-exporter prometheus/prometheus-blackbox-exporter \ -n monitor --version 11.5.0 \ -f values-11.5.0.yaml
可选:kustomize 配置安装 blackbox-exporter
mkdir -p base prod
vim base/kustomization.yaml
vim prod/kustomization.yaml
kubectl kustomize --enable-helm ./base --load-restrictor=LoadRestrictionsNone > charts-11.5.0.yaml- 查看渲染后的 yaml
- 确认无误后
kubectl apply -f kubectl kustomize --enable-helm ./base --load-restrictor=LoadRestrictionsNone | kubectl apply -f -
可选:创建到 blackbox-exporter 的 traefik 路由
vim blackbox-ingressroute.yaml
kubectl apply -f blackbox-ingressroute.yaml
curl -vk https://blackbox.traefik.cluster.local/metrics
blackbox-exporter 搭配 Probe 对象动态配置抓取对象
需要安装 Prometheus Operator 或者 helm 的 kube-stack-prometheus
kube-stack-prometheus 需要启用 Prometheus Operator 且配置 ProbeSelector
probeSelectorNilUsesHelmValues默认为true会导致 probeSelector 为空时 Prometheus Operator 自动使用release: <prometheus-name>的 probeSelector
kubectl get crd probes.monitoring.coreos.com- 检查是否有 Probe CRD
Probe 通过 selector 匹配要监控的 ingress 或者静态 target
- Prometheus CRD 配置
probeSelector字段来确定使用哪些 Probe
- 还需要一个 prober 来负责具体实现监控目标并提供指标供 Prometheus 抓取
- 通常由 blackbox-export 实现
创建并应用 Probe 资源
vim probe.yaml
- https 会包含证书信息
- tcp 探测器也能获取 SSL 但没有证书信息
kubectl apply -f probe.yaml
一些其他可用的 module
icmp
http-cert
http-mta-sts
tcp
tcp-imap, smtp
dns
可选:手动执行 target 检测
https://blackbox.traefik.cluster.local/probe?target=google.com&module=http_2xxtarget=google.com修改为对应目标地址module=http_2xx为使用模块,如 TCP, HTTP
node-exporter 导出由 NIX 内核公开的硬件和操作系统指标
跨平台默认启用的 collector
- boottime: 系统启动时间
- cpu: CPU 统计
- diskstats: 磁盘 I/O 统计
- exec: 执行统计(Dragonfly, FreeBSD)
- filesystem: 文件系统统计
- loadavg: 系统负载
- meminfo: 内存统计
- netdev: 网络接口统计
- netisr: netisr 统计(FreeBSD)
- os: 操作系统版本信息
- thermal: 热管理统计(Darwin)
- time: 当前系统时间
- uname: 系统信息
Linux 系统默认启用的 collector
Collector | 描述 |
arp | ARP 统计信息(/proc/net/arp) |
bcache | bcache 统计信息(/sys/fs/bcache/) |
bonding | Linux bonding 接口的从设备数量 |
btrfs | Btrfs 文件系统统计 |
conntrack | 连接跟踪统计 |
cpu | CPU 统计 |
cpufreq | CPU 频率统计 |
diskstats | 磁盘 I/O 统计 |
dmi | 桌面管理接口信息(/sys/class/dmi/id/) |
edac | 错误检测和纠正统计 |
entropy | 可用熵 |
fibrechannel | 光纤通道信息(/sys/class/fc_host/) |
filefd | 文件描述符统计(/proc/sys/fs/file-nr) |
filesystem | 文件系统统计(磁盘空间等) |
hwmon | 硬件监控和传感器数据(/sys/class/hwmon/) |
infiniband | InfiniBand 网络统计 |
ipvs | IPVS 状态统计 |
loadavg | 系统负载 |
mdadm | RAID 设备统计(/proc/mdstat) |
meminfo | 内存统计 |
netclass | 网络接口信息(/sys/class/net/) |
netdev | 网络接口统计 |
netstat | 网络统计(/proc/net/netstat) |
nfs | NFS 客户端统计 |
nfsd | NFS 内核服务器统计 |
nvme | NVMe 设备信息 |
os | 操作系统版本信息 |
powersupplyclass | 电源统计(/sys/class/power_supply) |
pressure | 压力停顿统计(/proc/pressure/) |
rapl | 功耗统计(/sys/class/powercap) |
schedstat | 任务调度统计(/proc/schedstat) |
selinux | SELinux 统计 |
sockstat | 套接字统计(/proc/net/sockstat) |
softnet | 软中断统计(/proc/net/softnet_stat) |
stat | 系统统计(/proc/stat) |
tapestats | 磁带统计(/sys/class/scsi_tape) |
textfile | 本地磁盘文本文件统计 |
thermal | 热管理统计 |
thermal_zone | 热区统计(/sys/class/thermal) |
time | 当前系统时间 |
timex | adjtimex(2) 系统调用统计 |
udp_queues | UDP 队列统计 |
uname | 系统信息(uname 系统调用) |
vmstat | 虚拟内存统计(/proc/vmstat) |
watchdog | 看门狗统计 |
xfs | XFS 运行时统计 |
zfs | ZFS 性能统计 |
Linux 系统默认禁用的 collector
Collector | 描述 | 注意事项 |
buddyinfo | 内存碎片统计(/proc/buddyinfo) | ㅤ |
cgroups | cgroup 数量统计 | ㅤ |
cpu_vulnerabilities | CPU 漏洞信息(sysfs) | ㅤ |
drm | GPU 指标(DRM,amdgpu) | 仅 amdgpu 驱动支持 |
drbd | DRBD 分布式复制块设备统计 | 仅支持版本 8.4 |
ethtool | 网络接口和驱动统计 | 类似 ethtool |
interrupts | 详细中断统计 | ㅤ |
kernel_hung | 被检测为挂起的任务数 | ㅤ |
ksmd | KSM 合并统计(/sys/kernel/mm/ksm) | ㅤ |
lnstat | 网络统计(/proc/net/stat/) | ㅤ |
logind | 会话计数(logind) | ㅤ |
meminfo_numa | NUMA 内存统计 | ㅤ |
mountstats | NFS 客户端详细统计(/proc/self/mountstats) | ㅤ |
network_route | 路由表指标 | 高基数 |
pcidevice | PCI 设备信息 | ㅤ |
perf | 基于 perf 的指标 | 依赖内核配置 |
processes | 进程聚合统计 | ㅤ |
qdisc | 队列 discipline 统计 | ㅤ |
slabinfo | slab 分配器统计(/proc/slabinfo) | 需要权限 |
softirqs | 软中断详细统计(/proc/softirqs) | ㅤ |
sysctl | sysctl 值(/proc/sys) | ㅤ |
swap | 交换空间信息(/proc/swaps) | ㅤ |
systemd | systemd 服务和系统状态 | ㅤ |
tcpstat | TCP 连接状态统计 | 高负载下可能有性能问题 |
wifi | WiFi 设备和站点统计 | ㅤ |
xfrm | IPsec 统计(/proc/net/xfrm_stat) | ㅤ |
zoneinfo | NUMA 内存区域指标 | ㅤ |
其他系统默认禁用的 collector
Collector | 平台 | 描述 |
devstat | Dragonfly, FreeBSD | 设备统计 |
cAdvisor 导出运行容器资源使用指标
参考资料
启用/禁用特定指标组
--enable-metrics=cpu,memory- 仅启用 cpu,memory 组指标
--disable-metrics=diskIO,network
指标组列表
指标组 | 描述 | 包含指标数 |
- | 无参数指标(基本规范配置) | 9 |
cpu | CPU 使用相关 | 6 |
cpuLoad | CPU 负载相关 | 2 |
cpuset | CPU 集合相关 | 1 |
cpu_topology | CPU 拓扑相关(硬件指标) | 5 |
sched | 调度器相关 | 3 |
disk | 磁盘使用相关 | 4 |
diskIO | 磁盘 I/O 相关 | 14 |
memory | 内存使用相关 | 9 |
oom_event | OOM 事件相关 | 1 |
memory_numa | NUMA 内存相关 | 1 |
referenced_memory | 引用内存相关 | 1 |
hugetlb | 大页相关 | 3 |
process | 进程/线程相关 | 6 |
network | 网络流量相关 | 8 |
tcp | TCP 连接相关 | 2 |
advtcp | TCP 高级统计 | 1 |
udp | UDP 连接相关 | 2 |
perf_event | Perf 事件相关 | 4 |
resctrl | RDT 资源控制相关 | 3 |
容器指标(可能会变动,以最新官方文档为准)
无参数指标
指标名称 | 类型 | 描述 | 单位 |
container_health_state | Gauge | 健康检查探针状态 | ㅤ |
container_last_seen | Gauge | 容器上次被 Exporter 发现的时间 | 时间戳 |
container_spec_cpu_period | Gauge | 容器的 CPU 周期 | ㅤ |
container_spec_cpu_quota | Gauge | 容器的 CPU 配额 | ㅤ |
container_spec_cpu_shares | Gauge | 容器的 CPU 份额 | ㅤ |
container_spec_memory_limit_bytes | Gauge | 容器的内存限制 | 字节 |
container_spec_memory_reservation_limit_bytes | Gauge | 容器的内存预留限制 | 字节 |
container_spec_memory_swap_limit_bytes | Gauge | 容器的内存交换限制 | 字节 |
container_start_time_seconds | Gauge | 容器的启动时间(自 Unix 纪元起) | 秒 |
CPU 相关指标
指标名称 | 类型 | 描述 | 单位 |
container_cpu_cfs_periods_total | Counter | 已执行的 CFS 周期间隔数 | ㅤ |
container_cpu_cfs_throttled_periods_total | Counter | 被限流的周期间隔数 | ㅤ |
container_cpu_cfs_throttled_seconds_total | Counter | 容器被限流的总时间时长 | 秒 |
container_cpu_system_seconds_total | Counter | 累计系统 CPU 时间消耗 | 秒 |
container_cpu_usage_seconds_total | Counter | 累计 CPU 时间消耗 | 秒 |
container_cpu_user_seconds_total | Counter | 累计用户 CPU 时间消耗 | 秒 |
CPU 负载相关指标
指标名称 | 类型 | 描述 | 单位 |
container_cpu_load_average_10s | Gauge | 容器在过去 10 秒的 CPU 平均负载 | ㅤ |
container_tasks_state | Gauge | 处于给定状态的任务数(sleeping, running, stopped, uninterruptible, ioawaiting) | ㅤ |
CPU 调度器相关指标
指标名称 | 类型 | 描述 | 单位 |
container_cpu_schedstat_run_periods_total | Counter | cgroup 中的进程在 CPU 上运行的次数 | ㅤ |
container_cpu_schedstat_runqueue_seconds_total | Counter | 容器进程在运行队列中等待的时间 | 秒 |
container_cpu_schedstat_run_seconds_total | Counter | 容器进程在 CPU 上运行的时间 | 秒 |
内存相关指标
指标名称 | 类型 | 描述 | 单位 |
container_memory_cache | Gauge | 总页缓存内存 | 字节 |
container_memory_failcnt | Counter | 内存使用达到限制的次数 | ㅤ |
container_memory_failures_total | Counter | 内存分配失败的累计次数 | ㅤ |
container_memory_mapped_file | Gauge | 内存映射文件大小 | 字节 |
container_memory_max_usage_bytes | Gauge | 记录的最大内存使用量 | 字节 |
container_memory_rss | Gauge | RSS 大小 | 字节 |
container_memory_swap | Gauge | 容器交换空间使用量 | 字节 |
container_memory_usage_bytes | Gauge | 当前内存使用量,包括所有内存(无论何时访问) | 字节 |
container_memory_working_set_bytes | Gauge | 当前工作集 | 字节 |
container_memory_numa_pages | Gauge | 每个 NUMA 节点使用的页面数 | ㅤ |
container_memory_migrate | Gauge | 内存迁移状态 | ㅤ |
container_oom_events_total | Counter | 观察到的容器内存不足事件次数 | ㅤ |
container_referenced_bytes | Gauge | 容器在上次测量周期中引用的字节数,基于 /proc/smaps 文件中的 Referenced 字段 | 字节 |
内存大页相关指标
指标名称 | 类型 | 描述 | 单位 |
container_hugetlb_failcnt | Counter | 大页使用达到限制的次数 | ㅤ |
container_hugetlb_max_usage_bytes | Gauge | 记录的最大大页使用量 | 字节 |
container_hugetlb_usage_bytes | Gauge | 当前大页使用量 | 字节 |
进程相关指标
指标名称 | 类型 | 描述 | 单位 |
container_file_descriptors | Gauge | 容器打开的文件描述符数量 | ㅤ |
container_processes | Gauge | 容器内运行的进程数 | ㅤ |
container_sockets | Gauge | 容器打开的套接字数 | ㅤ |
container_threads | Gauge | 容器内运行的线程数 | ㅤ |
container_threads_max | Gauge | 容器内允许的最大线程数 | ㅤ |
container_ulimits_soft | Gauge | 容器根进程的软 ulimit 值(-1 表示无限制,priority 和 nice 除外) | ㅤ |
磁盘使用相关指标
指标名称 | 类型 | 描述 | 单位 |
container_fs_inodes_free | Gauge | 可用的 Inode 数量 | ㅤ |
container_fs_inodes_total | Gauge | Inode 总数 | ㅤ |
container_fs_limit_bytes | Gauge | 容器在该文件系统上可消耗的字节数 | 字节 |
container_fs_usage_bytes | Gauge | 容器在该文件系统上消耗的字节数 | 字节 |
磁盘 I/O 使用相关指标
指标名称 | 类型 | 描述 | 单位 |
container_blkio_device_usage_total | Counter | Blkio 设备字节使用量 | 字节 |
container_fs_io_current | Gauge | 当前进行中的 I/O 数量 | ㅤ |
container_fs_io_time_seconds_total | Counter | 累计 I/O 操作秒数 | 秒 |
container_fs_io_time_weighted_seconds_total | Counter | 累计加权 I/O 时间 | 秒 |
container_fs_reads_bytes_total | Counter | 累计读取字节数 | 字节 |
container_fs_read_seconds_total | Counter | 累计读取秒数 | ㅤ |
container_fs_reads_merged_total | Counter | 累计读取合并次数 | ㅤ |
container_fs_reads_total | Counter | 累计完成读取次数 | ㅤ |
container_fs_sector_reads_total | Counter | 累计完成扇区读取次数 | ㅤ |
container_fs_sector_writes_total | Counter | 累计完成扇区写入次数 | ㅤ |
container_fs_writes_bytes_total | Counter | 累计写入字节数 | 字节 |
container_fs_write_seconds_total | Counter | 累计写入秒数 | 秒 |
container_fs_writes_merged_total | Counter | 累计写入合并次数 | ㅤ |
container_fs_writes_total | Counter | 累计完成写入次数 | ㅤ |
网络相关指标
指标名称 | 类型 | 描述 | 单位 |
container_network_receive_bytes_total | Counter | 累计接收字节数 | 字节 |
container_network_receive_errors_total | Counter | 接收过程中遇到的错误累计次数 | ㅤ |
container_network_receive_packets_dropped_total | Counter | 接收过程中丢弃的数据包累计次数 | ㅤ |
container_network_receive_packets_total | Counter | 累计接收数据包数 | ㅤ |
container_network_transmit_bytes_total | Counter | 累计发送字节数 | 字节 |
container_network_transmit_errors_total | Counter | 发送过程中遇到的错误累计次数 | ㅤ |
container_network_transmit_packets_dropped_total | Counter | 发送过程中丢弃的数据包累计次数 | ㅤ |
container_network_transmit_packets_total | Counter | 累计发送数据包数 | ㅤ |
TCP/UDP 连接相关指标
指标名称 | 类型 | 描述 | 单位 |
container_network_tcp6_usage_total | Gauge | 容器的 TCP6 连接使用统计 | ㅤ |
container_network_tcp_usage_total | Gauge | 容器的 TCP 连接使用统计 | ㅤ |
container_network_advance_tcp_stats_total | Gauge | 容器的 TCP 连接高级统计 | ㅤ |
container_network_udp6_usage_total | Gauge | 容器的 UDP6 连接使用统计 | ㅤ |
container_network_udp_usage_total | Gauge | 容器的 UDP 连接使用统计 | ㅤ |
Perf 事件相关指标
需要额外的编译 Flag
编译标志 | 指标 | 说明 |
libpfm | container_perf_events_* | 需要 libpfm 库支持 perf 事件采集 |
指标名称 | 类型 | 描述 | 单位 |
container_perf_events_scaling_ratio | Gauge | perf 事件计数器的缩放比例(事件可通过事件标签识别,cpu 表示测量事件的 CPU 核心) | ㅤ |
container_perf_events_total | Counter | perf 核心事件的缩放计数器(事件可通过事件标签识别,cpu 表示测量事件的 CPU 核心) | ㅤ |
container_perf_uncore_events_scaling_ratio | Gauge | perf 非核心事件计数器的缩放比例(事件可通过事件标签、pmu 和 socket 标签识别) | ㅤ |
container_perf_uncore_events_total | Counter | perf 非核心事件的缩放计数器(事件可通过事件标签、pmu 和 socket 标签识别) | ㅤ |
RDT 资源控制相关指标
指标名称 | 类型 | 描述 | 单位 |
container_llc_occupancy_bytes | Gauge | 容器的最后一级缓存(LLC)使用统计,通过 RDT 内存带宽监控(MBM)计算 | 字节 |
container_memory_bandwidth_bytes | Gauge | 容器的总内存带宽使用统计,通过 RDT 内存带宽监控(MBM)计算 | 字节 |
container_memory_bandwidth_local_bytes | Gauge | 容器的本地内存带宽使用统计,通过 RDT 内存带宽监控(MBM)计算 | 字节 |
硬件指标
无参数指标
需要额外的编译 Flag
编译标志 | 指标 | 说明 |
libipmctl | machine_nvm_* | 需要 libipmctl 库支持 NVM(Intel Optane)监控 |
指标名称 | 类型 | 描述 | 单位 |
machine_cpu_cores | Gauge | 逻辑 CPU 核心数 | ㅤ |
machine_cpu_physical_cores | Gauge | 物理 CPU 核心数 | ㅤ |
machine_cpu_sockets | Gauge | CPU 插槽数 | ㅤ |
machine_dimm_capacity_bytes | Gauge | RAM DIMM 总容量(所有类型内存模块),按内存类型标记 | 字节 |
machine_dimm_count | Gauge | RAM DIMM 数量(所有类型内存模块),按内存类型标记 | ㅤ |
machine_memory_bytes | Gauge | 机器安装的内存量 | 字节 |
machine_swap_bytes | Gauge | 机器上可用的交换空间量 | 字节 |
machine_nvm_avg_power_budget_watts | Gauge | NVM 电源预算 | 瓦特 |
machine_nvm_capacity | Gauge | NVM 容量值,按 NVM 模式标记(内存模式或 app direct 模式) | 字节 |
CPU 拓扑相关指标
指标名称 | 类型 | 描述 | 单位 |
machine_cpu_cache_capacity_bytes | Gauge | 分配给 NUMA 节点和 CPU 核心的缓存大小 | 字节 |
machine_node_distance | Gauge | NUMA 节点之间的距离 | ㅤ |
machine_node_hugepages_count | Gauge | 分配给 NUMA 节点的大页数量 | ㅤ |
machine_node_memory_capacity_bytes | Gauge | 分配给 NUMA 节点的内存量 | 字节 |
machine_thread_siblings_count | Gauge | CPU 线程兄弟数 | ㅤ |
kube-state-metrics 导出 kubernetes 集群相关指标
参考资料
启用/禁用特定指标组和标签
--metric-allowlist,--metric-denylist- 指定只暴露哪些指标或者不暴露哪些指标
--metric-labels-allowlist,--metric-annotations-allowlist- 指定暴露哪些 Kubernetes 资源标签和注解
--metric-opt-in-list- 指定启用默认不开启的可选指标
指标组列表
默认资源
集群
资源类型 | 说明 | 指标文档 |
Node | 节点指标 | |
Namespace | 命名空间指标 | |
Lease | 租约指标 |
工作负载
资源类型 | 指标文档 |
Pod | |
ReplicaSet | |
Deployment | |
DaemonSet | |
StatefulSet | |
Job | |
CronJob | |
ReplicationController | |
Horizontal Pod Autoscaler |
存储
资源类型 | 指标文档 |
PersistentVolume | |
PersistentVolumeClaim | |
StorageClass | |
VolumeAttachment | |
ConfigMap | |
Secret |
服务
资源类型 | 说明 | 指标文档 |
Service | 服务指标 | |
Endpoint | 端点指标 | |
Ingress | 入口指标 |
策略
资源类型 | 指标文档 |
LimitRange | |
NetworkPolicy | |
Pod Disruption Budget | |
ResourceQuota |
其他
资源类型 | 指标文档 |
CertificateSigningRequest | |
MutatingWebhookConfiguration | |
ValidatingWebhookConfiguration |
可选资源
服务
资源类型 | 指标文档 |
EndpointSlice | |
IngressClass |
RBAC
资源类型 | 指标文档 |
ClusterRole | |
ClusterRoleBinding | |
Role | |
RoleBinding | |
ServiceAccount |
- 指标详见对应文档
Statefulset 监控 PromQL 样例
- 检查 StatefulSet 部署状态(最新副本百分比)
(kube_statefulset_status_replicas_updated / kube_statefulset_replicas) * 100
- 监控不可用的副本
kube_statefulset_replicas - kube_statefulset_status_replicas_available
- 查找包含过时副本的 StatefulSet
kube_statefulset_status_replicas_current != kube_statefulset_status_replicas_updated
- StatefulSet 在部署过程中卡住
kube_statefulset_status_observed_generation < kube_statefulset_metadata_generation
- 存在扩展问题的 StatefulSet
kube_statefulset_status_replicas_current != kube_statefulset_replicas
critical 预警规则
warning 预警规则
- Author:白鸟3
- URL:https://blog.kun2peng.top/operation/prometheus_exporter
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
