使用处理程序代码发送指标数据
若要使您的过程或 UDF 发送指标数据,您不需要向处理程序添加任何代码。Snowflake 会在事件表中生成所收集的数据。
如何衡量指标
Due to the way the Java and Python execution environments differ, the metrics data collected also differs. For reference information about the data collected, see RECORD column reference.
下面介绍了捕获的数据如何与执行环境相对应。
- Java:
报告每个查询 ID 的 JVM(Java 虚拟机)CPU 和内存指标。
每个存储过程都分配有自己的 JVM。下面介绍了收集的指标数据:
process.memory.usage: Amount of memory, in bytes, consumed by the JVM executing the stored procedure handler.process.cpu.utilization: Total CPU time divided by the wall-clock time per logical CPU, measured as a percentage where 1.0 indicates 100 percent utilization. Total CPU time is the total time spent on non-idle tasks.
Each Java and Scala UDF called in a query shares a single JVM. Metric values are aggregated across each Java or Scala function in the query. The following describes the metric data collected:
process.memory.usage: Memory use, shown as the sum of all the associated Java functions called in the query.process.cpu.utilization: CPU use, shown as the average of all the Java and Scala functions called in the query.
- Python:
报告每个 Python 函数或过程的 CPU 和内存指标。
每个存储过程仅在一个 Python 过程上执行。下面介绍了收集的指标数据:
process.memory.usage: Amount of memory, in bytes, consumed by the Python process executing the stored procedure handler.process.cpu.utilization: Total CPU time divided by the wall-clock time per logical CPU, measured as a percentage where 1.0 indicates 100 percent use. Total CPU time is the total time spent on non-idle tasks.
每个 UDF 可以在多个 Python 执行过程上执行。值在多个流程之间进行汇总。下面介绍了收集的指标数据:
process.memory.usage: Memory use, shown as the sum of all the associated Python processes of that UDF.process.cpu.utilization: Reported CPU, shown as the average of all the associated Python processes of that UDF.
Python 示例¶
使用以下步骤生成指标示例数据。
-
Set the metrics level of your session. The
METRIC_LEVELparameter controls whether to emit auto-instrumented resource metrics data points to the event table. You can set the parameter toNONEorALL, and set it on the object and session level. For more information, see Setting levels for logging, metrics, and tracing. -
创建存储过程。
-
运行存储过程
-
When the query is completed, view metrics data as described in Viewing metrics data.