prometheus
  • Introduction
  • (一)快速开始
    • 安装Prometheus
    • 使用NodeExporter采集数据
    • AlertManager进行告警
    • Grafana数据可视化
  • (二)探索PromQL
    • 理解时间序列
    • Metrics类型
    • 初识PromQL
    • PromQL操作符
    • PromQL内置函数
    • PromQL聚合函数
  • (三)Prometheus告警处理
    • 自定义告警规则
    • 示例 - 对主机进行监控告警
    • 部署AlertManager
    • 告警的路由与分组
    • 使用Receiver接收告警信息
      • 集成邮件系统
    • 屏蔽告警通知
    • 扩展阅读
      • AlertManager的API
      • Prometheus发送告警机制
      • 实践:接收Prometheus的告警
      • 实践:AlertManager
  • Prometheus
    • PromQL
      • 内置函数
        • avg
        • rate与irate
      • 常见指标的PromQL
        • 主机CPU
    • 配置
      • 告警规则
Powered by GitBook
On this page

Was this helpful?

  1. (二)探索PromQL

理解时间序列

我们知道,通过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
Previous(二)探索PromQLNextMetrics类型

Last updated 4 years ago

Was this helpful?