Apache Phoenix(十九)新特性之指标

2020-03-04  本文已影响0人  我知他风雨兼程途径日暮不赏

Phoenix给出了各种指标,这些指标提供了对Phoenix客户机在执行各种SQL语句时发生的情况的洞察。这些指标在客户端JVM中以两种方式收集:

请求水平指标有助于以更细粒度的级别计算Phoenix执行的每条SQL语句的工作量。这些指标可以分为三类:

变异指标(Mutation Metrics)

扫描任务指标(Scan Task Metrics)

总体查询指标(Overall Query Metrics)

 Properties props = new Properties();
    props.setProperty(QueryServices.COLLECT_REQUEST_LEVEL_METRICS, “true”);
    try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
        .....
    }

一个典型的模式,一个如何可以获得的查询读取指标:

Map<String, Map<String, Long>> overAllQueryMetrics = null;
    Map<String, Map<String, Long>> requestReadMetrics = null;
    try (ResultSet rs = stmt.executeQuery()) {
          while(rs.next()) {
              .....
          }
          overAllQueryMetrics = PhoenixRuntime.getOverAllReadRequestMetrics(rs);
          requestReadMetrics = PhoenixRuntime.getRequestReadMetrics(rs);
          // log or report metrics as needed
          PhoenixRuntime.resetMetrics(rs);
    }

你也可以通过这样做来获得DML语句的写相关指标(每个表收集):

Map<String, Map<String, Long>> mutationWriteMetrics = null;
    Map<String, Map<String, Long>> mutationReadMetrics = null;
    try (Connection conn = DriverManager.getConnection(url)) {
          conn.createStatement.executeUpdate(dml1);
          ....
          conn.createStatement.executeUpdate(dml2);
          ...
          conn.createStatement.executeUpdate(dml3);
          ...
          conn.commit();
          mutationWriteMetrics = PhoenixRuntime.getWriteMetricsForMutationsSinceLastReset(conn);
          mutationReadMetrics = PhoenixRuntime.getReadMetricsForMutationsSinceLastReset(conn);
          PhoenixRuntime.resetMetrics(rs);
    }

另一方面,全局指标是在Phoenix客户机的JVM级别收集的。这些指标可以用来建立一个趋势,并从客户的角度来观察phoenix内部的发展趋势。除了上述报告的请求级指标外,全局指标还包括以下计数器:

   ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
    service.submit(new Runnable() {

        @Override
        public void run() {
            Collection<GlobalMetric> metrics = PhoenixRuntime.getGlobalPhoenixClientMetrics();
            for (GlobalMetric m : metrics) {
                ... // log or report for trending purposes
            }

        }
    });
上一篇下一篇

猜你喜欢

热点阅读