ShardingSphere 可观测 SQL 指标监控

ShardingSphere并不负责如何采集、存储以及展示应用性能监控的相关数据,而是将SQL解析与SQL执行这两块数据分片的最核心的相关信息发送至应用性能监控系统,并交由其处理。 换句话说,ShardingSphere仅负责产生具有价值的数据,并通过标准协议递交至相关系统。

现有问题

  1. 现有版本5.2.1不支持对于jdbc模式的直接监控
  2. 现有pd版本实现双写的重构对于 ShardingSphereStatement、ShardingSpherePreparedStatement是相关监控是否需要重构代码
  3. 连接池连接信息的监控

方案

针对sql执行情况的监控

  1. 针对当前的5.2.1,参考5.3.2进行agent相关代码的编写

unrealizable

  1. 升级版本5.3.2

    Apache ShardingSphere-JDBC 性能监控实战

  2. trace监控同上,现有metrics指标[1]

数据连接池监控

  1. HikariCP 自带

HikariCP 数据库连接池开启prometheus监控_hikaricp开启sql监控_croder的博客-CSDN博客

可观测性-Metrics-数据库连接池HikariCP监控_hikaricp 监控_lakernote的博客-CSDN博客

HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setJdbcUrl("jdbc:mysql://xxxxxxxx:3306/pegasus_data_demo_00?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=true&requireSSL=false");
        hikariConfig.setUsername("root");
        hikariConfig.setPassword("xxxxxxx.");
        hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
        hikariConfig.setAutoCommit(true);
        hikariConfig.setPoolName("demo-SSSSSS");
        hikariConfig.setMaximumPoolSize(10);
        hikariConfig.setMinimumIdle(3);
        // 创建HikariDataSource
        HikariDataSource dataSource = new HikariDataSource(hikariConfig);
        // 设置metric注册器 每10秒打印一次
        LoggingMeterRegistry loggingMeterRegistry = new LoggingMeterRegistry(new LoggingRegistryConfig() {
            @Override
            public String get(String key) {
                return null;
            }
            @Override
            public Duration step() {
                return Duration.ofSeconds(10);
            }
        }, Clock.SYSTEM);
        dataSource.setMetricRegistry(loggingMeterRegistry);

        // 测试 持有3秒连接后才释放
        Connection connection = dataSource.getConnection();
        TimeUnit.SECONDS.sleep(1000);
        connection.close();

通过注入 Metricslogs 暴露详细 metrics[2]

BUT:作者不希望在连接池层面进行日志的输出,虽然是一点点的性能

SQL logging · Issue #57 · brettwooldridge/HikariCP

  1. Druid

    自带监控,通过暴露相关的Metrics的数据进行监控

  2. ……

Metrics[1]

指标名称指标类型指标描述
build_infoGAUGE构建信息
parsed_sql_totalCOUNTER按类型(INSERT、UPDATE、DELETE、SELECT、DDL、DCL、DAL、TCL、RQL、RDL、RAL、RUL)分类的解析总数
routed_sql_totalCOUNTER按类型(INSERT、UPDATE、DELETE、SELECT)分类的路由总数
routed_result_totalCOUNTER路由结果总数(数据源路由结果、表路由结果)
jdbc_stateGAUGEShardingSphere-JDBC 状态信息。0 表示正常状态;1 表示熔断状态;2 锁定状态
jdbc_meta_data_infoGAUGEShardingSphere-JDBC 元数据信息
jdbc_statement_execute_totalCOUNTER语句执行总数
jdbc_statement_execute_errors_totalCOUNTER语句执行错误总数
jdbc_statement_execute_latency_millisHISTOGRAM语句执行耗时
jdbc_transactions_totalCOUNTER事务总数,按 commit,rollback 分类

Metrics[2]

指标含义详解
hikaricp.connections当前总连接数,包括空闲的连接和使用中的连接Connections = activeConnection + idleConnections,会随着连接使用情况变化。
hikaricp.connections.active正在使用中活跃连接数会随着连接使用情况变化。
hikaricp.connections.idle空闲连接数会随着连接使用情况变化。
hikaricp.connections.max最大连接数初始配置。
hikaricp.connections.min最小连接数初始配置。
hikaricp.connections.pending正在等待连接的线程数量一般来说,这里应该都是 0。如果存在这个数据并且时间较长要触发告警,视情况加大最大连接数。
hikaricp.connections.acquire获取每个连接需要时间,单位为 ns
hikaricp.connections.creation连接创建时间,单位为 ms
hikaricp.connections.timeout创建连接超时次数
hikaricp.connections.usage连接从池中取出到返回的时间,单位为 ms连接被业务占用时间,如果这个时间长的话,可能是慢 SQL 或者长事务导致连接被占用问题。
# HELP routed_sql_total Total count of routed SQL
# TYPE routed_sql_total counter
routed_sql_total{type="SELECT",} 28.0
routed_sql_total{type="INSERT",} 62.0
# HELP jdbc_statement_execute_total Total number of statement execute
# TYPE jdbc_statement_execute_total counter
jdbc_statement_execute_total{statement_type="prepared_statement",} 14.0
# HELP parsed_sql_total Total count of parsed SQL
# TYPE parsed_sql_total counter
parsed_sql_total{type="SELECT",} 28.0
parsed_sql_total{type="INSERT",} 62.0
# HELP jdbc_statement_execute_latency_millis Statement execute latency millis histogram
# TYPE jdbc_statement_execute_latency_millis histogram
jdbc_statement_execute_latency_millis_bucket{le="1.0",} 0.0
jdbc_statement_execute_latency_millis_bucket{le="2.0",} 0.0
jdbc_statement_execute_latency_millis_bucket{le="4.0",} 0.0
jdbc_statement_execute_latency_millis_bucket{le="8.0",} 0.0
jdbc_statement_execute_latency_millis_bucket{le="16.0",} 0.0
jdbc_statement_execute_latency_millis_bucket{le="32.0",} 0.0
jdbc_statement_execute_latency_millis_bucket{le="64.0",} 2.0
jdbc_statement_execute_latency_millis_bucket{le="128.0",} 8.0
jdbc_statement_execute_latency_millis_bucket{le="256.0",} 12.0
jdbc_statement_execute_latency_millis_bucket{le="512.0",} 13.0
jdbc_statement_execute_latency_millis_bucket{le="1024.0",} 14.0
jdbc_statement_execute_latency_millis_bucket{le="2048.0",} 14.0
jdbc_statement_execute_latency_millis_bucket{le="4096.0",} 14.0
jdbc_statement_execute_latency_millis_bucket{le="+Inf",} 14.0
jdbc_statement_execute_latency_millis_count 14.0
jdbc_statement_execute_latency_millis_sum 2491.0
# HELP routed_result_total Total count of routed result
# TYPE routed_result_total counter
routed_result_total{object="data_source",name="pegasus_data_demo_00",} 118.0
routed_result_total{object="data_source",name="pegasus_data_demo_01",} 56.0
routed_result_total{object="table",name="user_info_0000",} 28.0
routed_result_total{object="table",name="user_info_0001",} 90.0
routed_result_total{object="table",name="user_info_0002",} 28.0
routed_result_total{object="table",name="user_info_0003",} 28.0
# HELP build_info Build information
# TYPE build_info gauge
build_info{name="ShardingSphere",version="5.3.2",} 1.0
# HELP jdbc_statement_execute_created Total number of statement execute
# TYPE jdbc_statement_execute_created gauge
jdbc_statement_execute_created{statement_type="prepared_statement",} 1.691140932075E9
# HELP jdbc_statement_execute_latency_millis_created Statement execute latency millis histogram
# TYPE jdbc_statement_execute_latency_millis_created gauge
jdbc_statement_execute_latency_millis_created 1.691140932077E9
# HELP parsed_sql_created Total count of parsed SQL
# TYPE parsed_sql_created gauge
parsed_sql_created{type="SELECT",} 1.691140931048E9
parsed_sql_created{type="INSERT",} 1.691141080971E9
# HELP routed_result_created Total count of routed result
# TYPE routed_result_created gauge
routed_result_created{object="data_source",name="pegasus_data_demo_00",} 1.691140931237E9
routed_result_created{object="data_source",name="pegasus_data_demo_01",} 1.691140931237E9
routed_result_created{object="table",name="user_info_0000",} 1.691140931237E9
routed_result_created{object="table",name="user_info_0001",} 1.691140931237E9
routed_result_created{object="table",name="user_info_0002",} 1.691140931237E9
routed_result_created{object="table",name="user_info_0003",} 1.691140931237E9
# HELP routed_sql_created Total count of routed SQL
# TYPE routed_sql_created gauge
routed_sql_created{type="SELECT",} 1.691140931227E9
routed_sql_created{type="INSERT",} 1.691141080974E9
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值