Vector
本文档基于 Vector v0.49.0 版本编写。 以下的所有示例配置均基于此版本。对于各个 sink 的 host 和 port 配置请根据自己 GreptimeDB 实例的实际情况进行调整。 下文中的所有 port 值均为默认值。
Vector 是高性能的可观测数据管道。 它原生支持 GreptimeDB 指标数据接收端。 通过 Vector,你可以从各种来源接收指标数据,包括 Prometheus、OpenTelemetry、StatsD 等。 GreptimeDB 可以作为 Vector 的 Sink 组件来接收指标数据。
写入指标数据
GreptimeDB 支持多种指标数据写入方式,包括:
- 使用
greptimedb_metricssink - 使用 InfluxDB 行协议格式将指标数据写入 GreptimeDB
- 使用 Prometheus Remote Write 协议将指标数据写入 GreptimeDB
使用 greptimedb_metrics sink
示例
以下是一个使用 greptimedb_metrics sink 写入宿主机指标的示例配置:
# sample.toml
[sources.in]
type = "host_metrics"
[sinks.my_sink_id]
inputs = ["in"]
type = "greptimedb_metrics"
endpoint = "<host>:4001"
dbname = "<dbname>"
username = "<username>"
password = "<password>"
new_naming = true
Vector 使用 gRPC 与 GreptimeDB 进行通信,因此 Vector sink 的默认端口是 4001。
如果你在使用 自定义配置 启动 GreptimeDB 时更改了默认的 gRPC 端口,请使用你自己的端口。
如有更多需求请前往 Vector GreptimeDB Configuration 查看更多配置项。
数据模型
我们使用这样的规则将 Vector 指标存入 GreptimeDB:
- 使用
<metric namespace>_<metric name>作为 GreptimeDB 的表名,例如host_cpu_seconds_total; - 将指标中的时间戳作为 GreptimeDB 的时间索引,默认列名
ts; - 指标所关联的 tag 列将被作为 GreptimeDB 的 tag 字段;
- Vector 的指标,和其他指标类似,有多种子类型:
- Counter 和 Gauge 类型的指标,数值直接被存入
val列; - Set 类型,我们将集合的数据个数存入
val列; - Distribution 类型,各个百分位数值点分别存入
pxx列,其中 xx 是 quantile 数值,此外我们还会记录min/max/avg/sum/count列; - AggregatedHistoragm 类型,每个 bucket 的数值将被存入
bxx列,其中 xx 是 bucket 数值的上限,此外我们还会记录sum/count列; - AggregatedSummary 类型,各个百分位数值点分别存入
pxx列,其中 xx 是 quantile 数值,此外我们还会记录sum/count列; - Sketch 类型,各个百分位数值点分别存入
pxx列,其中 xx 是 quantile 数值,此外我们还会记录min/max/avg/sum列;
- Counter 和 Gauge 类型的指标,数值直接被存入
使用 InfluxDB 行协议格式
可以使用 influx sink 来写入指标数据。我们推荐使用 v2 版本的 InfluxDB 行协议格式。
以下是一个使用 influx sink 写入宿主机指标的示例配置:
# sample.toml
[sources.my_source_id]
type = "internal_metrics"
[sinks.my_sink_id]
type = "influxdb_metrics"
inputs = [ "my_source_id" ]
bucket = "public"
endpoint = "http://<host>:4000/v1/influxdb"
org = ""
token = ""
上述配置使用的是 InfluxDB 行协议的 v2 版本。Vector 会根据 TOML 配置中的的字段来判断 InfluxDB 协议的版本,所以请务必确保配置中存在 bucket、org 和 token 字段。具体字段的解释如下:
type: InfluxDB 行协议的值为influxdb_metrics.bucket: GreptimeDB 中的 database 名称。org: GreptimeDB 中的组织名称(需置空)。token: 用于身份验证的令牌(需置空)。由于 Influx 行协议的 token 有特殊形式,必须以Token开头。这和 GreptimeDB 的鉴权方式有所不同,且目前不兼容。如果使用的是含有鉴权的 GreptimeDB 实例,请使用greptimedb_metrics。
更多细节请参考 InfluxDB Line Protocol 文档 了解如何使用 InfluxDB Line Protocol 将数据写入到 GreptimeDB。
使用 Prometheus Remote Write 协议
以下是一个使用 Prometheus Remote Write 协议写入宿主机指标的示例配置:
# sample.toml
[sources.my_source_id]
type = "internal_metrics"
[sinks.prometheus_remote_write]
type = "prometheus_remote_write"
inputs = [ "my_source_id" ]
endpoint = "http://<host>:4000/v1/prometheus/write?db=<dbname>"
compression = "snappy"
auth = { strategy = "basic", username = "<username>", password = "<password>" }
写入日志数据
GreptimeDB 支持多种日志数据写入方式,包括:
- 使用
greptimedb_logssink 将日志数据写入 GreptimeDB。 - 使用 Loki 协议将日志数据写入 GreptimeDB。
我们强烈建议所有的用户使用 greptimedb_logs sink 来写入日志数据,因为它是为 GreptimeDB 优化的,能够更好地支持 GreptimeDB 的特性。
并且推荐开启各种协议的压缩功能,以提高数据传输效率。