> For the complete documentation index, see [llms.txt](https://pshizhsysu.gitbook.io/prometheus/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pshizhsysu.gitbook.io/prometheus/4e8c29-tan-suo-promql/li-jie-shi-jian-xu-lie.md).

# 理解时间序列

我们知道，通过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
```
