Grafana学习(4)——Time series dimensions

发布时间 2023-11-22 12:36:31作者: 钱塘江畔
In Introduction to time series, the concept of labels, also called tags, is introduced:
       Another feature of a TSDB is the ability to filter measurements using tags. Each data point is labeled with a tag that adds context information, such as where the measurement was taken.

With time series data, the data often contain more than a single series, and is a set of multiple time series. Many Grafana data sources support this type of data.
The common case is issuing a single query for a measurement with one or more additional properties as dimensions. For example, querying a temperature measurement along with a location property. In this case, multiple series are returned back from that single query and each series has unique location as a dimension.
To identify unique series within a set of time series, Grafana stores dimensions in labels.

Introduction to time series中,引入了labels的概念,也称为tags:
TSDB的另一个功能是能够使用标签过滤测量结果。每个数据点都标记有一个标签,该标签添加了上下文信息,例如测量的位置。
对于时间序列数据,数据通常包含多个序列,并且是多个时间序列的集合。许多Grafana数据源都支持这种类型的数据。
常见的情况是为具有一个或多个附加属性作为维度的度量值发出单个查询。例如,查询温度测量值和位置特性。在这种情况下,从单个查询返回多个序列,并且每个序列都有唯一的位置作为维度。
为了识别一组时间序列中的唯一序列,Grafana将维度存储在标签中。

Labels
Each time series in Grafana optionally has labels. Labels are a set of key/value pairs for identifying dimensions. Example labels could be {location=us} or {country=us,state=ma,city=boston}. Within a set of time series, the combination of its name and labels identifies each series. For example, temperature {country=us,state=ma,city=boston} could identify the series of temperature values for the city of Boston in the US.
Different sources of time series data have dimensions stored natively, or common storage patterns that allow the data to be extracted into dimensions.
Time series databases (TSDBs) usually natively support dimensionality. Prometheus also stores dimensions in labels. In TSDBs such as Graphite or OpenTSDB the term tags is used instead.
In table databases such SQL, these dimensions are generally the GROUP BY parameters of a query.

标签
Grafana中的每个时间序列都有标签。标签是一组用于标识维度的键/值对。示例标签可以是{location=us}或{country=us,state=ma,city=boston}。在一组时间序列中,其名称和标签的组合标识每个序列。例如,温度{country=us,state=ma,city=boston}可以确定美国波士顿市的一系列温度值。
时间序列数据的不同来源具有本地存储的维度,或者允许将数据提取到维度中的通用存储模式。
时间序列数据库(TSDB)通常原生支持维度。Prometheus也将维度存储在标签中。在诸如Graphite或OpenTSDB之类的TSDB中,使用术语 tags作为维度。
在SQL这样的表数据库中,这些维度通常是查询的GROUP BY参数。

Multiple dimensions in table format
In SQL or SQL-like databases that return table responses, additional dimensions are usually represented as columns in the query response table.
Single dimension
For example, consider a query like: 
  SELECT BUCKET(StartTime, 1h), AVG(Temperature) AS Temp, Location   FROM T
    GROUP BY BUCKET(StartTime, 1h), Location
    ORDER BY time asc
This query would return a table with three columns with data types time, number, and string respectively:
The table format is a long formatted time series, also called tall. It has repeated time stamps, and repeated values in Location. In this case, we have two time series in the set that would be identified as Temp {Location=LGA} and Temp {Location=BOS}.
Individual time series from the set are extracted by using the time typed column StartTime as the time index of the time series, the numeric typed column Temp as the series name, and the name and values of the string typed Location column to build the labels, such as Location=LGA.

表格格式的多个维度
在返回表响应的SQL或类似SQL的数据库中,附加维度通常表示为查询响应表中的列。
表格格式是一个长格式的时间序列,也称为tall。它具有重复的时间戳和位置中的重复值。在这种情况下,我们在集合中有两个时间序列,它们将被标识为Temp{Location=LGA}和Temp{Locations=BOS}。
通过使用时间类型的列StartTime作为时间序列的时间索引,使用数字类型的列Temp作为序列名称,以及字符串类型的Location列的名称和值来提取集合中的各个时间序列,以构建标签,例如Location=LGA。

Multiple dimensions
If the query is updated to select and group by more than just one string column, for example, GROUP BY BUCKET(StartTime, 1h), Location, Sensor, then an additional dimension is added:
In this case the labels that represent the dimensions will have two keys based on the two string typed columns Location and Sensor. This data results four series: Temp {Location=LGA,Sensor=A}, Temp {Location=LGA,Sensor=B}, Temp {Location=BOS,Sensor=A}, and Temp {Location=BOS,Sensor=B}.
Note: Multiple dimensions are not supported in a way that maps to multiple alerts in Grafana, but rather they are treated as multiple conditions to a single alert. For more information, see the documentation on [creating alerts with multiple series][create-grafana-managed-rule].

多个维度
如果更新查询以选择并按多个字符串列分组,例如group by BUCKET(StartTime,1h)、Location、Sensor,则会添加一个附加维度:
在这种情况下,表示维度的标签将有两个基于两个字符串类型列Location和Sensor的键。该数据产生四个系列:温度{Location=LGA,传感器=A},温度{Locations=LGA、传感器=B},温度{Location=BOS,传感器=A}和温度{Location=BOS、传感器=B}。
注意:Grafana中不支持多个维度映射到多个警报,而是将它们视为单个警报的多个条件。有关更多信息,请参阅[使用多个系列创建警报][创建grafana托管规则]的文档。

Multiple values
In the case of SQL-like data sources, more than one numeric column can be selected, with or without additional string columns to be used as dimensions. For example, AVG(Temperature) AS AvgTemp, MAX(Temperature) AS MaxTemp. This, if combined with multiple dimensions, can result in a lot of series. Selecting multiple values is currently only designed to be used with visualization.

Additional technical information on tabular time series formats and how dimensions are extracted can be found in the developer documentation on data frames as time series.

多个值
在类似SQL的数据源的情况下,可以选择多个数字列,无论是否使用其他字符串列作为维度。例如,AVG(Temperature)AS AvgTemp、MAX(Temperation)AS MaxTemp。如果与多个维度相结合,可能会产生大量的系列。选择多个值目前仅设计用于可视化。
关于表格时间序列格式以及如何提取维度的其他技术信息,可以在作为时间序列的data frames的开发人员文档中找到。