Prometheus 数据模型是一个多维度的时间序列数据模型,其中包含了以下四个基本元素:
- Metric:指标名称,用于标识一组相关的时间序列数据。Metric 通常由名称和可选的标签(Labels)组成。
例如 http_requests_total
是一个 Metric,表示 HTTP 请求总数;cpu_usage_seconds_total{mode="user",instance="localhost:9100"}
是另一个 Metric,表示 CPU 使用时间。
- Time series:指定 Metric 的特定实例,表示在给定时间范围内某一时刻 Metric 的值。Time series 由 Metric 和其对应的 Label 值以及时间戳组成。
例如 http_requests_total{method="GET", handler="/api/v1/users"}
是 http_requests_total 的一个 time series,表示获取用户信息 API 的 GET 请求总数;cpu_usage_seconds_total{mode="system",instance="localhost:9100"}
是 cpu_usage_seconds_total 的另一个 time series,表示系统态 CPU 使用时间。
- Sample:表示一对 (timestamp, value),即某个 Metric 在某个时间点上的值。每个样本都对应一个唯一的 time series。
例如 (1628478127, 125)
表示在 Unix 时间戳为 1628478127(2021年8月9日10点35分27秒)时 http_requests_total{method=“GET”, handler=“/api/v1/users”} 的值为125;(1628478135, 0.4)
表示在 Unix 时间戳为 1628478135 时 cpu_usage_seconds_total{mode=“system”,instance=“localhost:9100”} 的值为0.4。
- Label:用于区分不同 time series 实例的标签键值对,例如 “method” 和 “handler” 是 http_requests_total 中的两个 label。
例如 http_requests_total{method="GET", handler="/api/v1/users"}
中的 method 和 handler 就是 label,它们可以被用来过滤、聚合或者分类 time series 数据。