监控-clickhouse

集群监控

  • 集群各个节点的存活时间
  • http 连接数监控
  • tcp 连接数监控
  • 集群当前数据库的数目
  • 集群当前表的数目

集群各个节点的存活时间

select
         hostName, upDay
     from (
        select
           hostName() as hostName, intDiv(uptime(), 3600 * 24) as upDay  
        from  clusterAllReplicas('集群名', 'system.clusters')
        where cluster = '集群名'
     ) a
     group by  hostName,upDay

http 连接数监控

  select * from system.metrics where metric = 'HTTPConnection'

注意:system.metrics 表之中的指标是一个瞬时值。

tcp 连接数监控

 select * from system.metrics where metric = 'TCPConnection'

注意:system.metrics 表之中的指标是一个瞬时值。

集群当前数据库的数目

select count(*) from system.databases 

集群当前表的数目

select count(*) from system.tables 

表数据量监控

  • 查看集群之中各个表的数据量的大小
  • 查看具体某个表在各个节点上的数据分布

查看集群之中各个表的数据量的大小

  select
      database,
      name,
      sum(total_rows) as total_rows , // 表之中的行数
      sum(total_bytes) as total_bytes  // 表之中的数据量
  from
      clusterAllReplicas('集群名', 'system.tables')
  where
  group by 
     database,
     name 
  order by total_bytes desc 

查看具体某个表在各个节点上的数据量分布

  select
      hostName() as hostName,
      database,
      name,
      total_rows,
      total_bytes
  from
      clusterAllReplicas('集群名', 'system.tables')
  where
      database = '数据库名'
      and table = '表名'
  order by total_rows desc

表分区监控

  • 查看某个表的分区方式
  • 获取某个表的分区数目
  • 查看某个表的 分区数据量情况 分区之中part数目
  • 获取一个表的分区范围
  • 检查集群之中没有分区的表以及表的数据量
  • 检查集群之中存在分区不合理的表

查看某个表的分区方式

select table,partition_key from system.tables where database = '数据库名'  and table = '表名'

获取某个表的分区数目

 select count(*) as partition_num
       from (
          select partition_id from clusterAllReplicas('集群名', 'system.parts') 
          where database = '数据库名' and table = '表名'
          group by partition_id
       ) t

查看某个表的 分区数据量情况 分区之中part数目

select
   database,
   table,
   partition,
   count(*) as part_num, // 分区下的part 数目
   sum(rows) as rows, // 分区下的行数
   sum(data_compressed_bytes) as data_compress, // 压缩后的数据量大小 
   formatReadableSize(data_compress) r_data,
   divide(data_compress, rows) as row_rate -- 每行的大小
from
  clusterAllReplicas('集群名', 'system.parts')
where active = 1
    and database = '数据库名'
   and table = '表名'
group by
   database,
   table,
   partition
order by partition

获取一个表的分区范围

   select max(partition) as max_partition, min(partition) as min_partition
        from clusterAllReplicas('集群名', 'system.parts')
        where database = '数据库名' and table = '表名'

检查集群之中没有分区的表以及表的数据量

select
          database, 
          table, 
          sum(bytes_on_disk) as bytes_on_disk,  // 表之中的数据量大小 
          sum(rows) as rows
       from clusterAllReplicas('集群名', 'system.parts')
       where
          partition = 'tuple()'
          and active = 1
       group by 
           database, table
       order by
          bytes_on_disk desc,
        database, table

表注释监控

  • 集群之中表字段缺乏注释的表
  • 获取指定表的 字段未添加注释的有哪些字段

集群之中表字段缺乏注释的表

 select
       database, table
     from
       clusterAllReplicas('集群名', 'system.columns')
     where comment = ''
     and database <> 'system'
     group by database, table

获取指定表的 字段未添加注释的有哪些字段

       database, table,name 
     from
       clusterAllReplicas('集群名', 'system.columns')
     where comment = ''
     and database = '集群名'
     and table = '表名'
     group by database, table,name 

表压缩方式监控

  • 集群之中使用默认压缩方式的表

表TTL 监控

  • 查看集群之中合并树系列的表没有设置表级别TTL的表有哪些

查看集群之中合并树系列的表没有设置表级别TTL的表有哪些

   select 
    database, name, sum(total_rows) as total_rows,sum(total_bytes) as total_bytes 
 from 
  clusterAllReplicas('集群名', 'system.tables') 
where 
   engine like '%MergeTree%' 
   and engine_full not like '%TTL%' 
group by 
    database, name      

可复制表 监控

  • 检查集群之中 可复制合并树的 zookeeper的路径设置 不符合规则的表

检查集群之中 可复制合并树的 zookeeper的路径设置 不符合规则的表

注意:这里的规则 zookeeper 之中 clickhouse表存储路径以 数据库名/表名 这样的格式作为结尾

      select
          database,
          name,
          engine,
          engine_full,
          'database_name/table_name' as standard_form
      from
         clusterAllReplicas('集群名', 'system.tables')
      where
         engine like '%ReplicatedMergeTree%'
         and engine <> 'SystemReplicatedMergeTreeSettings'
         and endsWith(splitByString(',', engine_full)[1], concat(database, '/', name, '\'')) = 0
      group by
         database, name, engine, engine_full
      order by
         engine, database, name
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前言 我们往往需要关心数据库的查询执行情况,特别是慢查询。本文简述配置ClickHouse查询监控的一种傻瓜方法。...
    LittleMagic阅读 13,292评论 6 11
  • 合并是什么 只有合并树系列的表才有合并这个功能。通常合并都是后台任务。合并的对象是一个表的某个分区之中的part们...
    流砂月歌阅读 9,090评论 0 0
  • 写入的相关概念 block 表 分区 part block block 说明 clickhouse block的概...
    流砂月歌阅读 9,783评论 0 0
  • 关于Mongodb的全面总结 MongoDB的内部构造《MongoDB The Definitive Guide》...
    中v中阅读 32,124评论 2 89
  • 背景 在数据量日益增长的当下,传统数据库的查询性能已满足不了我们的业务需求。而Clickhouse在OLAP领域的...
    陌上闻笛阅读 14,250评论 5 42