cratedb 做为prometheus 的后端存储

摘要:
普罗米修斯提供了远程写和远程读数据存储方法,可以帮助我们长时间存储数据并方便查询。板条箱b提供了相应的适配器,可以直接进行调整。

prometheus 提供了remote_write 以及remote_read 的数据存储方式,可以帮助我们进行数据的长时间存储、方便查询
cratedb 提供了对应的adapter,可以直接进行适配。
以下演示一个简单的cratedb 集群以及通过write 以及read 存储通过grok exporter 暴露的日记prometheus metrics

环境准备

  • 数据请求流程
    inputlog->grok exporter -> prometheus->cratedb adpater->cratedb cluster
  • docker-compose 文件
 
version: "3"
services:
  grafana:
    image: grafana/grafana
    ports:
    - "3000:3000"
  prometheus:
    image: prom/prometheus
    volumes:
    - "./prometheus.yml:/etc/prometheus/prometheus.yml"
    ports:
    - "9090:9090" 
  cratedb-adapter:
    image: crate/crate_adapter
    command: -config.file /opt/config/config.yml
    ports: 
    - "9268:9268"
    volumes: 
    - "./cratedb-adapter:/opt/config"
  grok:
    image: dalongrong/grok-exporter
    volumes: 
    - "./grok/example:/opt/example"
    - "./grok/grok.yaml:/grok/config.yml"
    ports: 
    - "9144:9144"
  crate1:
    image: crate
    volumes:
    - "./cratedb/data1:/data"
    - "./cratedb/1.yaml:/crate/config/crate.yml"
    ports:
    - "4200:4200"
    - "4300:4300"
    - "5432:5432"
  crate2:
    image: crate
    volumes:
    - "./cratedb/data2:/data"
    - "./cratedb/2.yaml:/crate/config/crate.yml"
    ports:
    - "4201:4200"
    - "4301:4300"
    - "5433:5432"
  crate3:
    image: crate
    volumes:
    - "./cratedb/data3:/data"
    - "./cratedb/3.yaml:/crate/config/crate.yml"
    ports:
    - "4202:4200"
    - "4302:4300"
    - "5434:5432"
 
  • prometheus 配置

    通过静态配置的方式添加target,统计配置了remote_write 以及remote_read

scrape_configs:
  - job_name: grok
    metrics_path: /metrics
    scrape_interval: 10s
    scrape_timeout: 10s
    static_configs:
      - targets: ['grok:9144']
  - job_name: cratedb-adapter
    metrics_path: /metrics
    scrape_interval: 10s
    scrape_timeout: 10s
    static_configs:
      - targets: ['cratedb-adapter:9268']
remote_write:
   - url: http://cratedb-adapter:9268/write
remote_read:
   - url: http://cratedb-adapter:9268/read
 
  • cratedb 集群配置

    当前使用的是社区版本,对于集群模式,最大支持的是3个节点的,但是一般场景也够用了

     -  node1 配置
    
cluster.name: cratecluster
node.name: crate1
node.master: true
node.data: true
http.port: 4200
psql.port: 5432
transport.tcp.port: 4300
discovery.seed_hosts: ["crate1"]
cluster.initial_master_nodes: ["crate1"]
http.cors.enabled: true
http.cors.allow-origin: "*"
gateway.expected_nodes: 3
gateway.recover_after_nodes: 2
gateway.recover_after_time: 5m
network.host: _local_,_site_
path.logs: /data/log
path.data: /data/data
blobs.path: /data/blobs
  -   node2  配置
cluster.name: cratecluster
node.name: crate2
node.master: false
node.data: true
http.port: 4200
psql.port: 5432
transport.tcp.port: 4300
discovery.seed_hosts: ["crate1"]
cluster.initial_master_nodes: ["crate1"]
http.cors.enabled: true
http.cors.allow-origin: "*"
gateway.expected_nodes: 3
gateway.recover_after_nodes: 2
gateway.recover_after_time: 5m
network.host: _local_,_site_
path.logs: /data/log
path.data: /data/data
blobs.path: /data/blobs
 - node3 配置
cluster.name: cratecluster
node.name: crate3
node.master: false
node.data: true
http.port: 4200
psql.port: 5432
transport.tcp.port: 4300
discovery.seed_hosts: ["crate1"]
cluster.initial_master_nodes: ["crate1"]
http.cors.enabled: true
http.cors.allow-origin: "*"
network.host: _local_,_site_
gateway.expected_nodes: 3
gateway.recover_after_nodes: 2
gateway.recover_after_time: 5m
path.logs: /data/log
path.data: /data/data
blobs.path: /data/blobs
  • grok exporter配置

    定义的日志匹配模式

global:
    config_version: 2
input:
    type: file
    path: /opt/example/examples.log
    readall: true
grok:
    patterns_dir: ./patterns
metrics:
    - type: counter
      name: grok_example_lines_total
      help: Counter metric example with labels.
      match: '%{DATE} %{TIME} %{USER:user} %{NUMBER}'
      labels:
          user: '{{.user}}'
server:
    port: 9144
  • cratedb adapter 配置

    暴露write 以及read 服务,因为使用集群模式,所以我 配置了多个节点

crate_endpoints:
- host: "crate1" # Host to connect to (default: "localhost").
  port: 5432 # Port to connect to (default: 5432).
  user: "crate" # Username to use (default: "crate")
  password: "" # Password to use (default: "").
  schema: "" # Schema to use (default: "").
  max_connections: 5 # The maximum number of concurrent connections (default: 5).
  enable_tls: false # Whether to connect using TLS (default: false).
  allow_insecure_tls: false # Whether to allow insecure / invalid TLS certificates (default: false).
- host: "crate2" # Host to connect to (default: "localhost").
  port: 5432 # Port to connect to (default: 5432).
  user: "crate" # Username to use (default: "crate")
  password: "" # Password to use (default: "").
  schema: "" # Schema to use (default: "").
  max_connections: 5 # The maximum number of concurrent connections (default: 5).
  enable_tls: false # Whether to connect using TLS (default: false).
  allow_insecure_tls: false # Whether to allow insecure / invalid TLS certificates (default: false).
- host: "crate3" # Host to connect to (default: "localhost").
  port: 5432 # Port to connect to (default: 5432).
  user: "crate" # Username to use (default: "crate")
  password: "" # Password to use (default: "").
  schema: "" # Schema to use (default: "").
  max_connections: 5 # The maximum number of concurrent connections (default: 5).
  enable_tls: false # Whether to connect using TLS (default: false).
  allow_insecure_tls: false # Whether to allow insecure / invalid TLS certificates (default: false).
  • metrics 的table

    使用cratedb 我们需要先定义table,table 的schema 定义官方提供了模版

CREATE TABLE "metrics" (
    "timestamp" TIMESTAMP,
    "labels_hash" STRING,
    "labels" OBJECT(DYNAMIC),
    "value" DOUBLE,
    "valueRaw" LONG,
    "day__generated" TIMESTAMP GENERATED ALWAYS AS date_trunc('day', "timestamp"),
    PRIMARY KEY ("timestamp", "labels_hash", "day__generated")
  ) PARTITIONED BY ("day__generated");

启动&&测试

  • 启动集群
docker-compose up -d
  • 效果

cratedb 做为prometheus 的后端存储第1张


cratedb 做为prometheus 的后端存储第2张

  • 通过admin ui 创建table

cratedb 做为prometheus 的后端存储第3张

  • 写入数据统计

cratedb 做为prometheus 的后端存储第4张

  • 数据查询效果

cratedb 做为prometheus 的后端存储第5张

说明

使用crate adapter 进行mtrics 数据的持久化存储也是一个不错的选择,以上演示没有包含关于grafana与prometheus 的集成,可以参考github
的完整配置自己添加下,这样就相对完整了,同时因为暴露了pg 协议的数据,我们可以直接通过grafanna 进行数据查看,展示。

参考资料

https://github.com/crate/crate_adapter
https://github.com/crate/crate
https://crate.io/docs/crate/reference/en/latest/config/cluster.html
https://github.com/fstab/grok_exporter
https://github.com/rongfengliang/prometheus-cratedb-cluster-docker-compose

免责声明:文章转载自《cratedb 做为prometheus 的后端存储》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇openstack计算节点的zone划分数据库系统中文件附件保存的最佳办法下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

自定义Prometheus告警规则

自定义Prometheus告警规则 Prometheus中的告警规则允许你基于PromQL表达式定义告警触发条件,Prometheus后端对这些触发规则进行周期性计算,当满足触发条件后则会触发告警通知。默认情况下,用户可以通过Prometheus的Web界面查看这些告警规则以及告警的触发状态。当Promthues与Alertmanager关联之后,可以将告...

设计模式学习笔记十一:适配器模式(Adapter Pattern)

    1.概述    在软件开发中,我们经常会遇到系统间集成,在系统集成时,最常见的问题就是系统间的接口不一致。很多能够满足功能的系统模块,由于接口不一致,导致无法使用。例如,常用的媒体播放器是MS Media player和RealPlayer,他们的文件结构和软件接口完全不同,前者支持WMF格式的音频和视频,后者支持RM格式的音频和视频。如果我们希望自...

使用orapki生成证书,配置Oracle数据使用SSL和TLS进行数据库连接的TCP/IP配置==TCPS

内容参考Oracle官方文档:   https://oracle-base.com/articles/misc/configure-tcpip-with-ssl-and-tls-for-database-connections   https://docs.oracle.com/cd/E11882_01/network.112/e40393/asoappf...

基于canal的client-adapter数据同步必读指南

本文将介绍canal项目中client-adapter的使用,以及落地生产中需要考虑的可靠性、高可用与监控报警。(基于canal 1.1.4版本)   canal作为mysql的实时数据订阅组件,实现了对mysql binlog数据的抓取。 虽然阿里也开源了一个纯粹从mysql同步数据到mysql的项目otter(github.com/alibaba/ot...

kudu 监控

监控信息 (作为存储引擎,主要关注I/O,和使用内存) 从tmaster、tserver两个metrics接口获取: IP:8051/metrics?include_schema=1&metrics=serverIP:8050/metrics?include_schema=1&metrics=server 0、接口说明 接口有几个重要参数:...

如何在Ubuntu 20.04 LTS Focal Fossa上安装Prometheus

步骤1.首先,通过apt在终端中运行以下以下命令,确保所有系统软件包都是最新的。sudo apt updatesudo apt upgrade第2步。安装Nginx Web服务器。Nginx在默认的Ubuntu存储库中可用。要安装它,请运行以下命令:sudo apt install nginx安装完成后,运行以下命令以使Nginx在服务器启动时自动启动:s...