写点什么

开源可观测数据采集工具 Vector 已内置 GreptimeDB 支持

作者:Greptime
  • 2023-09-01
    北京
  • 本文字数:2125 字

    阅读完需:约 7 分钟

开源可观测数据采集工具 Vector 已内置 GreptimeDB 支持

上个月,我们在 Vector 项目中提交的 GreptimeDB sink 已被成功合并。Vector 于近日发布了 0.32 版本,正式支持将 GreptimeDB 作为 metrics data sink。至此,用户可以通过 Vector 将各类数据源写入 GreptimeDB ,这也意味着 GreptimeDB 在可观测生态的一个重要里程碑落地。

什么是 Vector

Vector 是一个使用 Rust 编写的“可观测数据管道”,用于在各种数据源和数据目的地之间搬运可观测数据。Vector 中主要支持两种可观测数据类型:日志 Logs 和指标 Metrics ,覆盖了日常使用的绝大多数场景。


Vector 的抽象中定义了三大类模块:

  • Sources 数据源

  • Transforms 转换器

  • Sinks 数据目的地

在一套 Vector 拓扑中,用户可以通过配置文件指定任意多个数据源、转换器和目的地,并定义他们之间的数据流向,从而实现从源头到目的地的数据搬运和处理。Vector 中支持包括文件、队列等 40 多种数据源,和 50 多种—包括 GreptimeDB—数据目的地。变换器也是 Vector 的特色之一,它允许用户在搬运数据的过程中,对数据进行修改(remap)、聚合、过滤、降采样、限流等操作,也可以在这个环节实现 metrics 和 logs 的互转。


在内部,Vector 不是简单地将各类数据源和目的地的客户端集成起来,它对数据搬运这项工作做了抽象和建模,提供了统一的基础设施来支持批量操作、重试、TLS 加密、流量管理等等。只要遵从其设计的标准,就可以构建出可靠的扩展实现。

GreptimeDB 作为一个 Vector 数据目的地

目前我们可以将 GreptimeDB 作为 Vector 指标类型的数据目的地,当然,借助 Vector 的转换器也可以将源头的日志类型按照业务需要转换成指标存入 GreptimeDB。

将 Vector 指标存入 GreptimeDB 时,我们使用这样的规则:

  • 将指标的 namespace 和指标名称用下划线连接作为 GreptimeDB 的表名;

  • 将指标中的时间戳作为 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 列

一个实际的例子

首先确保你有一个运行中的 GreptimeDB 实例,它既可以是开源版本,也可以是 GreptimeCloud 上开通的实例。

下载 Vector 0.32 版本,编写一个配置文件,这里我们以 Vector 的 host_metrics 数据源为例:

[sources.in]type = "host_metrics"scrape_interval_secs = 30
[sinks.local]inputs = ["in"]type = "greptimedb"endpoint = "localhost:4001"
[sinks.cloud]inputs = ["in"]type = "greptimedb"endpoint = "7x5hdjl32d17f.us-west-2.aws.greptime.cloud:4001"dbname = "..."username = "..."password = "..."
复制代码

这里在一个配置文件中同时使用了本地 GreptimeDB 和 GreptimeCloud 上的 serverless 实例。只需要将 endpoint 配置到实例的 4001 端口,并设置数据库名称和用户名密码等即可。

将配置文件保存为 sample.toml ,启动 Vector 即可实现写入:

vector -c sample.toml
复制代码

通过 MySQL 协议访问数据:

MySQL [etox4eivxxv2respective_expansion-public]> select * from host_load1 order by ts desc limit 5;+-------------------------+-----------+----------+---------------+| ts                      | collector | host     | val           |+-------------------------+-----------+----------+---------------+| 2023-08-23 06:25:32.295 | load      | thinkneo |    0.88671875 || 2023-08-23 06:25:02.295 | load      | thinkneo | 1.35302734375 || 2023-08-23 06:24:32.295 | load      | thinkneo | 1.32763671875 || 2023-08-23 06:24:02.295 | load      | thinkneo |  1.5029296875 || 2023-08-23 06:23:32.295 | load      | thinkneo | 1.65966796875 |+-------------------------+-----------+----------+---------------+5 rows in set (0.198 sec)
复制代码

在 GreptimeCloud 上进行可视化展示:

总结

与 Vector 的结合帮助 GreptimeDB 扩展了可观测领域的使用场景,感谢 Vector 开发团队在集成过程中提供的帮助。我们后续还会提供更多的自定义选项,欢迎通过 Vector 的 Issue trackerGreptimeDB 的 Slack 社区反馈你的使用需求。现在就注册 GreptimeCloud 开始体验吧。


引用:

[1] https://github.com/vectordotdev/vector/pull/17198

[2] https://vector.dev/releases/0.32.0/

[3] https://vector.dev/download/

[4] https://github.com/vectordotdev/vector/issues

[5] https://greptimedbcommunity.slack.com/join/shared_invite/zt-1jeggrthh-UDISaSqdYUZTtf8wbGxgFg

[6] https://console.greptime.cloud/login

用户头像

Greptime

关注

专注于 Infra 技术分享 2022-09-23 加入

分布式、高性能、存储计算分离的开源云原生时序数据库

评论

发布
暂无评论
开源可观测数据采集工具 Vector 已内置 GreptimeDB 支持_数据库_Greptime_InfoQ写作社区