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
  • 效果

  • 通过admin ui 创建table

  • 写入数据统计

  • 数据查询效果

说明

使用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 的后端存储的更多相关文章

  1. 使用 opendistro for elasticsearch 做为graylog的后端存储

    graylog 是一个很不错的日志分析.收集.报警平台,包好了丰富的插件,同时内部的架构设计很不错 input 组件很多,使用stream.pipeline可以方便的进行数据处理,可以同时3.0 对于 ...

  2. jaeger使用yugabyte作为后端存储的尝试以及几个问题

    前边写过使用scylladb 做为jaeger 的后端存储,还是一个不错选择的包括性能以及 兼容性,对于 yugabyte 当前存在兼容性的问题,需要版本的支持,或者尝试进行一些变动 create 语 ...

  3. Flocker 做为后端存储代理 docker volume-driver 支持

    docker Flocker https://github.com/ClusterHQ/flocker/ 文档: https://docs.clusterhq.com/en/latest/docker ...

  4. Openstack_后端存储平台Ceph

    框架图 介绍 一种为优秀的性能.可靠性和可扩展性而设计的统一的.分布式文件系统 特点 CRUSH算法 Crush算法是ceph的两大创新之一,简单来说,ceph摒弃了传统的集中式存储元数据寻址的方案, ...

  5. 9 云计算系列之Cinder的安装与NFS作为cinder后端存储

    preface 在前面我们知道了如何搭建Openstack的keystone,glance,nova,neutron,horizon这几个服务,然而在这几个服务中唯独缺少存储服务,那么下面我们就学习块 ...

  6. OpenStack Cinder 与各种后端存储技术的集成叙述与实践

    先说下下loop设备 loop设备及losetup命令介绍 1. loop设备介绍 在类 UNIX 系统里,loop 设备是一种伪设备(pseudo-device),或者也可以说是仿真设备.它能使我们 ...

  7. influxdb和boltDB简介——MVCC+B+树,Go写成,Bolt类似于LMDB,这个被认为是在现代kye/value存储中最好的,influxdb后端存储有LevelDB换成了BoltDB

    influxdb influxdb是最新的一个时间序列数据库,最新一两年才产生,但已经拥有极高的人气.influxdb 是用Go写的,0.9版本的influxdb对于之前会有很大的改变,后端存储有Le ...

  8. Openstack使用NFS作为后端存储

    续:Openstack块存储cinder安装配置 接上使用ISCSI作为后端存储,使用NFS作为后端存储配置 参考官方文档:https://wiki.openstack.org/wiki/How_to ...

  9. [转帖]influxdb和boltDB简介——MVCC+B+树,Go写成,Bolt类似于LMDB,这个被认为是在现代kye/value存储中最好的,influxdb后端存储有LevelDB换成了BoltDB

    influxdb和boltDB简介——MVCC+B+树,Go写成,Bolt类似于LMDB,这个被认为是在现代kye/value存储中最好的,influxdb后端存储有LevelDB换成了BoltDB ...

随机推荐

  1. Python格式化输出——format用法示例

    format OR % 提到Python中的格式化输出方法,一般来说有以下两种方式: print('hello %s' % 'world') # hello world print('hello {} ...

  2. 集合单列--Colletion

    集合 学习集合的目标: 会使用集合存储数据 会遍历集合,把数据取出来 掌握每种集合的特性 集合和数组的区别 数组的长度是固定的.集合的长度是可变的. 数组中存储的是同一类型的元素,可以存储基本数据类型 ...

  3. spark的存储系统--BlockManager源码分析

    spark的存储系统--BlockManager源码分析 根据之前的一系列分析,我们对spark作业从创建到调度分发,到执行,最后结果回传driver的过程有了一个大概的了解.但是在分析源码的过程中也 ...

  4. 【MySQL】MySQL高可用架构之MHA

    一.关于MHA MHA(Master HA)是一款开源的MySQL的高可用程序,它为MySQL主从复制架构提供了automating master failover 功能.MHA在监控到master节 ...

  5. 【转载】 C#中ArrayList集合类的使用

    在C#的集合操作过程中,我们一般常用的集合类为List集合,List集合是一种强类型的泛型集合,其实还有一个ArrayList集合类,ArrayList集合类则非泛型类的集合,并且ArrayList集 ...

  6. vue组件6 使用vue添加样式

    class绑定,内联样式 数组语法 :class="[stylename]"    js:data{stylename:classname} 对象语法:class={stylena ...

  7. js数组与字符串类型相同方法的比较

    数组和字符串有很多相似的对方,比如数组和字符串都有以下方法: concat indexOf lastIndexOf slice includes 鉴于toString及valueOf方法基本类型都有, ...

  8. HTML 结构标签(div+span)

    一.div 标签 div 就是 division 的缩写 分割, 分区的意思 常见的用途是文档布局. 二.span 标签 span, 跨度,跨距:范围 <span> 元素可用于为部分文本设 ...

  9. JCEF-tab形式展示浏览器

    当我们点击target值为_blank的链接时,JCEF默认以弹出窗口的形式打开新页面,要实现tab栏形式,可参考以下步骤 1.创建一个实现CefLifeSpanHandlerAdapter的类,重写 ...

  10. Could not get lock /var/lib/dpkg/lock-frontend解决

    在安装软件包时如果出现Could not get lock /var/lib/dpkg/lock-frontend,说明之前使用apt时出现异常,没有正常关闭,还在运行. lgj@lgj-Lenovo ...