使用 Prometheus 访问 TDengine ---

Prometheus 是一款流行的开源监控告警系统。Prometheus 于 2016 年加入了 Cloud Native Computing Foundation(云原生云计算基金会,简称 CNCF),成为继 Kubernetes 之后的第二个托管项目,该项目拥有非常活跃的开发人员和用户社区。

Prometheus 提供了 remote_writeremote_read 接口来利用其它数据库产品作为它的存储引擎。为了让 Prometheus 生态圈的用户能够利用 TDengine 的高效写入和查询,TDengine 也提供了对这两个接口的支持。

通过适当的配置,Prometheus 的数据可以通过 remote_write 接口存储到 TDengine 中,也可以通过 remote_read 接口来查询存储在 TDengine 中的数据,充分利用 TDengine 对时序数据的高效存储查询性能和集群处理能力。

前置条件

要将 Prometheus 数据写入 TDengine 需要以下几方面的准备工作。

  • TDengine 集群已经部署并正常运行
  • taosAdapter 已经安装并正常运行。具体细节请参考 taosAdapter 的使用手册
  • Prometheus 已经安装。安装 Prometheus 请参考 官方文档

配置步骤

配置 Prometheus 是通过编辑 Prometheus 配置文件 prometheus.yml(默认位置 /etc/prometheus/prometheus.yml)完成的。

配置第三方数据库地址

将其中的 remote_read url 和 remote_write url 指向运行 taosAdapter 服务的服务器域名或 IP 地址,REST 服务端口(taosAdapter 默认使用 6041),以及希望写入 TDengine 的数据库名称,并确保相应的 URL 形式如下:

  • remote_read url : http://<taosAdapter's host>:<REST service port>/prometheus/v1/remote_read/<database name>
  • remote_write url : http://<taosAdapter's host>:<REST service port>/prometheus/v1/remote_write/<database name>
配置 Basic 验证
  • username: <TDengine's username>
  • password: <TDengine's password>
prometheus.yml 文件中 remote_write 和 remote_read 相关部分配置示例
yaml 复制代码
remote_write:
  - url: "http://localhost:6041/prometheus/v1/remote_write/prometheus_data"
    basic_auth:
      username: root
      password: taosdata

remote_read:
  - url: "http://localhost:6041/prometheus/v1/remote_read/prometheus_data"
    basic_auth:
      username: root
      password: taosdata
    remote_timeout: 10s
    read_recent: true

验证方法

重启 Prometheus 后可参考以下示例验证从 Prometheus 向 TDengine 写入数据并能够正确读出。

使用 TDengine CLI 查询写入数据

复制代码
taos> show databases;
              name              |
=================================
 information_schema             |
 performance_schema             |
 prometheus_data                |
Query OK, 3 row(s) in set (0.000585s)

taos> use prometheus_data;
Database changed.

taos> show stables;
              name              |
=================================
 metrics                        |
Query OK, 1 row(s) in set (0.000487s)

taos> select * from metrics limit 10;
              ts               |           value           |             labels             |
=============================================================================================
 2022-04-20 07:21:09.193000000 |               0.000024996 | {"__name__":"go_gc_duration... |
 2022-04-20 07:21:14.193000000 |               0.000024996 | {"__name__":"go_gc_duration... |
 2022-04-20 07:21:19.193000000 |               0.000024996 | {"__name__":"go_gc_duration... |
 2022-04-20 07:21:24.193000000 |               0.000024996 | {"__name__":"go_gc_duration... |
 2022-04-20 07:21:29.193000000 |               0.000024996 | {"__name__":"go_gc_duration... |
 2022-04-20 07:21:09.193000000 |               0.000054249 | {"__name__":"go_gc_duration... |
 2022-04-20 07:21:14.193000000 |               0.000054249 | {"__name__":"go_gc_duration... |
 2022-04-20 07:21:19.193000000 |               0.000054249 | {"__name__":"go_gc_duration... |
 2022-04-20 07:21:24.193000000 |               0.000054249 | {"__name__":"go_gc_duration... |
 2022-04-20 07:21:29.193000000 |               0.000054249 | {"__name__":"go_gc_duration... |
Query OK, 10 row(s) in set (0.011146s)

使用 promql-cli 通过 remote_read 从 TDengine 读取数据

安装 promql-cli

复制代码
 go install github.com/nalbury/promql-cli@latest

在 TDengine 和 taosAdapter 服务运行状态对 Prometheus 数据进行查询

复制代码
ubuntu@shuduo-1804 ~ $ promql-cli --host "http://127.0.0.1:9090" "sum(up) by (job)"
JOB           VALUE    TIMESTAMP
prometheus    1        2022-04-20T08:05:26Z
node          1        2022-04-20T08:05:26Z

暂停 taosAdapter 服务后对 Prometheus 数据进行查询

复制代码
ubuntu@shuduo-1804 ~ $ sudo systemctl stop taosadapter.service
ubuntu@shuduo-1804 ~ $ promql-cli --host "http://127.0.0.1:9090" "sum(up) by (job)"
VALUE    TIMESTAMP

提示:

  • TDengine 默认生成的子表名是根据规则生成的唯一 ID 值。

访问官网

更多内容欢迎访问 TDengine 官网

相关推荐
nbsaas-boot17 分钟前
基于存储过程的MySQL自动化DDL同步系统设计
数据库·mysql·自动化
摇一摇小肉包的JAVA笔记24 分钟前
Redis如何解决缓存击穿,缓存雪崩,缓存穿透
数据库·redis·缓存
wsdchong之小马过河25 分钟前
2025虚幻引擎文件与文件夹命名规律
java·数据库·虚幻
金融小师妹1 小时前
基于LSTM-GARCH混合模型的“获利了结”量化解析:黄金单日1.27%跌幅的技术性归因
大数据·人工智能·算法
东方-教育技术博主1 小时前
spring boot数据库注解
数据库·spring boot·oracle
人大博士的交易之路2 小时前
龙虎榜——20250620
大数据·数学建模·数据挖掘·程序员创富·缠中说禅·龙虎榜
hwj运维之路2 小时前
大数据系统架构实践(一):Zookeeper集群部署
大数据·zookeeper·系统架构
全栈小53 小时前
【数据库】在线体验KingbaseES平台,零门槛学习,并快速体验Oracle增改查全基础功能
数据库·学习·oracle
189228048613 小时前
NY339NY341美光固态闪存NW841NW843
大数据·数据库
DavidSoCool3 小时前
Elasticsearch 中实现推荐搜索(方案设想)
大数据·elasticsearch·搜索引擎