[TOC]
我们知道,通过NodeExporter的metrics地址可以看到如下的内容
```
# HELP node_cpu_seconds_total Seconds the cpus spent in each mode.
# TYPE node_cpu_seconds_total counter
node_cpu_seconds_total{cpu="0",mode="idle"} 927490.95
node_cpu_seconds_total{cpu="0",mode="iowait"} 27.74
node_cpu_seconds_total{cpu="0",mode="irq"} 0
node_cpu_seconds_total{cpu="0",mode="nice"} 58.66
node_cpu_seconds_total{cpu="0",mode="softirq"} 2914.37
node_cpu_seconds_total{cpu="0",mode="steal"} 0
node_cpu_seconds_total{cpu="0",mode="system"} 24042.78
node_cpu_seconds_total{cpu="0",mode="user"} 20314.27
node_cpu_seconds_total{cpu="1",mode="idle"} 933276.67
node_cpu_seconds_total{cpu="1",mode="iowait"} 76.62
node_cpu_seconds_total{cpu="1",mode="irq"} 0
node_cpu_seconds_total{cpu="1",mode="nice"} 58.88
node_cpu_seconds_total{cpu="1",mode="softirq"} 2381.89
node_cpu_seconds_total{cpu="1",mode="steal"} 0
node_cpu_seconds_total{cpu="1",mode="system"} 23292.49
node_cpu_seconds_total{cpu="1",mode="user"} 20425.59
```
那么Prometheus采集上面的数据后,是如何保存在自已的时序数据库中的呢?如果有两个NodeExporter,在Prometheus的数据库中,如何区分node1和node2的`node_cpu_seconds_total{cpu="0",mode="idle"}`呢?
其实,在Prometheus中,数据的存储逻辑如下。X轴代表采样时间,每一行代表一个时间序列(time-series),**每一个时间序列由指标名称和一组标签共同标识**,如下:
```
^
|* * * * * * * * * * ...
|* * * * * * * * * * node_cpu_seconds_total{cpu="0",mode="idle",instance="peng01",job="node_exporter"}
|* * * * * * * * * * node_cpu_seconds_total{cpu="0",mode="user",instance="peng01",job="node_exporter"}
|* * * * * * * * * * node_cpu_seconds_total{cpu="1",mode="idle",instance="peng02",job="node_exporter"}
|* * * * * * * * * * node_cpu_seconds_total{cpu="1",mode="user",instance="peng02",job="node_exporter"}
---------- 时间 --------->
```
为了让Prometheus在存储数据时,能够区分不同主机的NodeExporter的`node_cpu_seconds_total{cpu="0",mode="idle"}`,在Prometheus的配置中,在`labels`区域可以手动添加标签(如下),这样,在Prometheus的数据库中,就可以区分不同NodeExporter的相同指标。
```
scrape_configs:
- job_name: 'node_exporter'
static_configs:
- targets: ['192.168.2.101:9100']
labels:
instance: peng01
```
- (一)快速开始
- 安装Prometheus
- 使用NodeExporter采集数据
- AlertManager进行告警
- Grafana数据可视化
- (二)探索PromQL
- 理解时间序列
- Metrics类型
- 初识PromQL
- PromQL操作符
- PromQL内置函数
- rate和irate
- 常见指标的PromQL
- 主机CPU使用率
- 主机内存使用率
- 主机磁盘使用率
- 主机磁盘IO
- 主机网络IO
- API的响应时间
- (三)Promtheus告警处理
- 自定义告警规则
- 示例-对主机进行监控告警
- 部署AlertManager
- 告警的路由与分组
- 使用Receiver接收告警信息
- 集成邮件系统
- 屏蔽告警通知
- 扩展阅读
- AlertManager的API
- Prometheus发送告警机制
- 实践:接收Prometheus的告警
- 实践:AlertManager
- (四)监控Kubernetes集群
- 部署Prometheus
- Kubernetes下的服务发现
- 监控Kubernetes集群
- 监控Kubelet的运行状态
- 监控Pod的资源(cadvisor)
- 监控K8s主机的资源
- KubeStateMetrics
- K8S及ETCD常见监控指标
- ETCD监控指标
- Kube-apiserver监控指标
- (五)其他
- Prometheus的relabel-config
- Target的Endpoint
- Prometheus的其他配置
- (六)BlackboxExporter
- 安装
- BlackboxExporter的应用场景
- 在Promtheus中使用BlackboxExporter
- 参考