AzureDatabricksの監視
最終更新日: 26 年 2023 月 XNUMX 日LogicMonitorを使用してAzureDatabricksを監視するには:監視ライブラリを構築し、Azure Log Analyticsワークスペースを作成し、initスクリプトを更新して、Databricksクラスターを構成します。
要件
- インストールまたはアップデート Azure Databricks の LogicModules.
- Databricksクラスター。 作成する必要がある場合は、を参照してください。 クラスターを作成する.
- クラスターのバージョン(Databricksランタイムバージョン)。
- アクティブなAzureDatabricksワークスペース。 詳細については、を参照してください。 AzureDatabricksワークスペースを作成する.
- データブリックスCLI。 詳細については、を参照してください。 データブリックスCLI。
- JavaIDE。
モニタリングライブラリの構築
ライブラリを構築するには、DatabricksクラスターのDatabricksランタイムバージョンが必要です。 表示するには、Databricksコンソールに移動して次の場所に移動します 計算 > クラスターを選択 > Databricksランタイムバージョン。 詳細については、を参照してください。 クラスターを作成する.
- 次のGitHubリポジトリのクローンを作成します。 https://github.com/mspnp/spark-monitoring.git
注: このライブラリは、11.0 より前の Databricks バージョンで使用できます。 現時点では、バージョン 11.0 以降の監視はサポートされていません。
- Databricksランタイムバージョンに対応するMavenプロファイルを選択します。
- ランタイム5.5(Scala 2.11、Spark 2.4.3)
- ランタイム6.4(Scala 2.11、Spark 2.4.5)
- ランタイム7.3– 7.6(Scala 2.12、Spark 3.0.1)
- ランタイム8.0– 8.3(Scala 2.12、Spark 3.1.1)
- ランタイム8.4– 9.1(Scala 2.12、Spark 3.1.2)
- Mavenパッケージを実行して、XNUMXつのJARファイルを抽出します。
spark-listeners_<Spark Version>_<Scala Version>-<Version>.jar
spark-listeners-loganalytics_<Spark Version>_<Scala Version>-<Version>.jar
AzureLogAnalyticsワークスペースの作成
- Microsoft Azureで、 Azureサービス > LogAnalyticsワークスペース をクリックし 創造する。 詳細については、を参照してください。 LogAnalyticsワークスペースを作成する.
- 作成した新しいワークスペースを選択して、 エージェント管理.
注: ワークスペース ID と主キーが表示されます。 init スクリプトを更新するには、この情報が必要になります。
Initスクリプトの更新
使い方 ワークスペースID や 主キー Azure Log Analyticsワークスペースから、スクリプトを更新します。
[path to spark-monitoring]/src/spark-listeners/scripts/spark-monitoring.sh
LOG_ANALYTICS_WORKSPACE_ID
LOG_ANALYTICS_WORKSPACE_KEY
#!/bin/bash
set -e
set -o pipefail
# These environment variables would normally be set by Spark scripts
# However, for a Databricks init script, they have not been set yet.
# We will keep the names the same here, but not export them.
# These must be changed if the associated Spark environment variables
# are changed.
DB_HOME=/databricks
SPARK_HOME=$DB_HOME/spark
SPARK_CONF_DIR=$SPARK_HOME/conf
# Add your Log Analytics Workspace information below so all clusters use the same
# Log Analytics Workspace
# Also if it is available use AZ_* variables to include x-ms-AzureResourceId
# header as part of the request
tee -a "$SPARK_CONF_DIR/spark-env.sh" << EOF
export DB_CLUSTER_ID=$DB_CLUSTER_ID
export DB_CLUSTER_NAME=$DB_CLUSTER_NAME
export LOG_ANALYTICS_WORKSPACE_ID=
export LOG_ANALYTICS_WORKSPACE_KEY=
export AZ_SUBSCRIPTION_ID=
export AZ_RSRC_GRP_NAME=
export AZ_RSRC_PROV_NAMESPACE=
export AZ_RSRC_TYPE=
export AZ_RSRC_NAME=
# Note: All REGEX filters below are implemented with java.lang.String.matches(...). This implementation essentially appends ^...$ around
# the regular expression, so the entire string must match the regex. If you need to allow for other values you should include .* before and/or
# after your expression.
# Add a quoted regex value to filter the events for SparkListenerEvent_CL, the log will only include events where Event_s matches the regex.
# Commented example below will only log events for SparkListenerJobStart, SparkListenerJobEnd, or where "org.apache.spark.sql.execution.ui."
# is is the start of the event name.
# export LA_SPARKLISTENEREVENT_REGEX="SparkListenerJobStart|SparkListenerJobEnd|org\.apache\.spark\.sql\.execution\.ui\..*"
# Add a quoted regex value to filter the events for SparkMetric_CL, the log will only include events where name_s matches the regex.
# Commented example below will only log metrics where the name begins with app and ends in .jvmCpuTime or .heap.max.
# export LA_SPARKMETRIC_REGEX="app.*\.jvmCpuTime|app.*\.heap.max"
# Add a quoted regex value to filter the events for SparkLoggingEvent_CL, the log will only include events where logger_name_s matches the name regex
# or where the Message matches the message regex. If both are specified, then both must be matched for the log to be sent.
# Commented examples below will only log messages where the logger name is com.microsoft.pnp.samplejob.StreamingQueryListenerSampleJob or begins with
# org.apache.spark.util.Utils, or where the Message ends with the string 'StreamingQueryListenerSampleJob' or begins with the string 'FS_CONF_COMPAT'.
# export LA_SPARKLOGGINGEVENT_NAME_REGEX="com\.microsoft\.pnp\.samplejob\.StreamingQueryListenerSampleJob|org\.apache\.spark\.util\.Utils.*"
# export LA_SPARKLOGGINGEVENT_MESSAGE_REGEX=".*StreamingQueryListenerSampleJob|FS_CONF_COMPAT.*"
# Uncomment the following line to enable local logging to stderr of buffer contents when an exception is hit when sending a buffer to Log Analytics
# export LA_LOGFAILEDBUFFERSEND=TRUE
EOF
STAGE_DIR=/dbfs/databricks/spark-monitoring
SPARK_LISTENERS_VERSION=${SPARK_LISTENERS_VERSION:-1.0.0}
SPARK_LISTENERS_LOG_ANALYTICS_VERSION=${SPARK_LISTENERS_LOG_ANALYTICS_VERSION:-1.0.0}
SPARK_VERSION=$(cat /databricks/spark/VERSION 2> /dev/null || echo "")
SPARK_VERSION=${SPARK_VERSION:-3.2.1}
SPARK_SCALA_VERSION=$(ls /databricks/spark/assembly/target | cut -d '-' -f2 2> /dev/null || echo "")
SPARK_SCALA_VERSION=${SPARK_SCALA_VERSION:-2.12}
# This variable configures the spark-monitoring library metrics sink.
# Any valid Spark metric.properties entry can be added here as well.
# It will get merged with the metrics.properties on the cluster.
METRICS_PROPERTIES=$(cat << EOF
# This will enable the sink for all of the instances.
*.sink.loganalytics.class=org.apache.spark.metrics.sink.loganalytics.LogAnalyticsMetricsSink
*.sink.loganalytics.period=5
*.sink.loganalytics.unit=seconds
# Enable application status metrics
spark.metrics.appStatusSource.enabled=true
# Enable JvmSource for instance master, worker, driver and executor
master.source.jvm.class=org.apache.spark.metrics.source.JvmSource
worker.source.jvm.class=org.apache.spark.metrics.source.JvmSource
driver.source.jvm.class=org.apache.spark.metrics.source.JvmSource
executor.source.jvm.class=org.apache.spark.metrics.source.JvmSource
EOF
)
echo "Copying Spark Monitoring jars"
JAR_FILENAME="spark-listeners_${SPARK_VERSION}_${SPARK_SCALA_VERSION}-${SPARK_LISTENERS_VERSION}.jar"
echo "Copying $JAR_FILENAME"
cp -f "$STAGE_DIR/$JAR_FILENAME" /mnt/driver-daemon/jars
JAR_FILENAME="spark-listeners-loganalytics_${SPARK_VERSION}_${SPARK_SCALA_VERSION}-${SPARK_LISTENERS_LOG_ANALYTICS_VERSION}.jar"
echo "Copying $JAR_FILENAME"
cp -f "$STAGE_DIR/$JAR_FILENAME" /mnt/driver-daemon/jars
echo "Copied Spark Monitoring jars successfully"
echo "Merging metrics.properties"
echo "$(echo "$METRICS_PROPERTIES"; cat "$SPARK_CONF_DIR/metrics.properties")" > "$SPARK_CONF_DIR/metrics.properties" || { echo "Error writing metrics.properties"; exit 1; }
echo "Merged metrics.properties successfully"
# This will enable master/worker metrics
cat << EOF >> "$SPARK_CONF_DIR/spark-defaults.conf"
spark.metrics.conf ${SPARK_CONF_DIR}/metrics.properties
EOF
log4jDirectories=( "executor" "driver" "master-worker" )
for log4jDirectory in "${log4jDirectories[@]}"
do
LOG4J_CONFIG_FILE="$SPARK_HOME/dbconf/log4j/$log4jDirectory/log4j.properties"
echo "BEGIN: Updating $LOG4J_CONFIG_FILE with Log Analytics appender"
sed -i 's/log4j.rootCategory=.*/&, logAnalyticsAppender/g' ${LOG4J_CONFIG_FILE}
tee -a ${LOG4J_CONFIG_FILE} << EOF
# logAnalytics
log4j.appender.logAnalyticsAppender=com.microsoft.pnp.logging.loganalytics.LogAnalyticsAppender
log4j.appender.logAnalyticsAppender.filter.spark=com.microsoft.pnp.logging.SparkPropertyEnricher
# Commented line below shows how to set the threshhold for logging to only capture events that are
# level ERROR or more severe.
# log4j.appender.logAnalyticsAppender.Threshold=ERROR
EOF
echo "END: Updating $LOG4J_CONFIG_FILE with Log Analytics appender"
done
# The spark.extraListeners property has an entry from Databricks by default.
# We have to readd it here because we did not find a way to get this setting when the init script is running.
# If Databricks changes the default value of this property, it needs to be changed here.
cat << EOF > "$DB_HOME/driver/conf/00-custom-spark-driver-defaults.conf"
[driver] {
"spark.extraListeners" = "com.databricks.backend.daemon.driver.DBCEventLoggingListener,org.apache.spark.listeners.UnifiedSparkListener"
"spark.unifiedListener.sink" = "org.apache.spark.listeners.sink.loganalytics.LogAnalyticsListenerSink"
}
EOF
Databricksクラスターの構成
- Databricks CLIを使用して、次のコマンドを使用してディレクトリを作成します。
dbfs mkdirs dbfs:/databricks/spark-monitoring
- XNUMXつのJARファイルを追加します。
cd [path to spark-monitoring]
dbfs cp --overwrite src/spark-listeners/scripts/spark-monitoring.sh
dbfs:/databricks/spark-monitoring/spark-monitoring.sh
dbfs cp --overwrite --recursive src/target/ dbfs:/databricks/spark-monitoring/
- Microsoft Azureで、 Azureサービス > AzureDatabricks AzureDatabricksワークスペースを選択します。 作成する必要がある場合は、を参照してください。 AzureDatabricksワークスペースを作成する.
- [Azure Databricks Service]ページで、[ ローンチサービス。 Databricksコンソールが新しいウィンドウで開きます。
- Databricksコンソールから、をクリックします 計算します。
- 構成するクラスターを選択し、をクリックします 編集.
- 高度なオプション > Initスクリプト.
- 提供する 開催場所 や スクリプトパスの初期化 更新したinitスクリプトの場合は、 Add.
Azure Databricks の LogicModules
次の LogicModules をインストールまたは更新します。 詳細については、次を参照してください。 モジュールのインストールと更新.
モジュール | 説明 | |
Microsoft_Azure_Databrick_App | データソース | クラスター アプリケーション レベルでメトリックを表示します。 これには、特定のクラスター アプリケーションのアプリケーション ドライバー ノードのメトリックが含まれます。 |
Microsoft_Azure_Databrick_AppExecutor | データソース | クラスター アプリケーションのエグゼキューター レベルでメトリックを表示します。 これには、特定のクラスター アプリケーションのアプリケーション実行ノードのメトリックが含まれます。 |
Microsoft_Azure_Databrick_Cluster | データソース | クラスター レベルでメトリックを表示します。 これには、クラスター ノード自体のメトリックに加えて、クラスターに関連するワーカー、エグゼキューター、およびドライバーが含まれます。 |
Microsoft_Azure_DatabrickAppStatus | データソース | 次のようなリソースを見つけます。 clusterName applicationName |