23.4. Node Observability Operator スクリプト
スクリプトを作成すると、現在の Node Observability Operator および Node Observability Agent を使用して、事前設定された bash スクリプトを実行できます。
これらのスクリプトは、CPU 負荷、メモリーの逼迫、ワーカーノードの問題などの主要なメトリクスを監視します。sar レポートとカスタムパフォーマンスメトリクスも収集します。
23.4.1. スクリプト用のノード監視カスタムリソースを作成する リンクのコピーリンクがクリップボードにコピーされました!
スクリプトを実行する前に、NodeObservability カスタムリソース (CR) を作成して実行する必要があります。NodeObservability CR を実行すると、nodeSelector ラベルに一致するコンピュートノード上でエージェントがスクリプトモードで有効になります。
前提条件
- Node Observability Operator をインストールしました。
-
OpenShift CLI (
oc) がインストールされている。 -
cluster-admin権限でクラスターにアクセスできる。
手順
以下のコマンドを実行して、OpenShift Container Platform クラスターにログインします。
$ oc login -u kubeadmin https://<host_name>:6443次のコマンドを実行して、
node-observability-operatornamespace に切り替えます。$ oc project node-observability-operator次の内容を含む
nodeobservability.yamlという名前のファイルを作成します。apiVersion: nodeobservability.olm.openshift.io/v1alpha2 kind: NodeObservability metadata: name: cluster1 spec: nodeSelector: kubernetes.io/hostname: <node_hostname>2 type: scripting3 次のコマンドを実行して、
NodeObservabilityCR を作成します。$ oc apply -f nodeobservability.yaml出力例
nodeobservability.olm.openshift.io/cluster created次のコマンドを実行して、
NodeObservabilityCR のステータスを確認します。$ oc get nob/cluster -o yaml | yq '.status.conditions'出力例
conditions: conditions: - lastTransitionTime: "2022-07-05T07:33:54Z" message: 'DaemonSet node-observability-ds ready: true NodeObservabilityScripting ready: true' reason: Ready status: "True" type: ReadyNodeObservabilityCR の実行は、reasonがReady、statusが"True". の場合に完了します。
23.4.2. Node Observability Operator スクリプトの設定 リンクのコピーリンクがクリップボードにコピーされました!
前提条件
- Node Observability Operator をインストールしました。
-
NodeObservabilityカスタムリソース (CR) を作成しました。 -
cluster-admin権限でクラスターにアクセスできる。
手順
次の内容を含む、
nodeobservabilityrun-script.yamlという名前のファイルを作成します。apiVersion: nodeobservability.olm.openshift.io/v1alpha2 kind: NodeObservabilityRun metadata: name: nodeobservabilityrun-script namespace: node-observability-operator spec: nodeObservabilityRef: name: cluster type: scripting重要次のスクリプトのみをリクエストできます。
-
metrics.sh -
network-metrics.sh(monitor.shを使用)
-
次のコマンドを使用して
NodeObservabilityRunリソースを作成することで、スクリプトをトリガーします。$ oc apply -f nodeobservabilityrun-script.yaml次のコマンドを実行して、
NodeObservabilityRunスクリプトのステータスを確認します。$ oc get nodeobservabilityrun nodeobservabilityrun-script -o yaml | yq '.status.conditions'出力例
Status: Agents: Ip: 10.128.2.252 Name: node-observability-agent-n2fpm Port: 8443 Ip: 10.131.0.186 Name: node-observability-agent-wcc8p Port: 8443 Conditions: Conditions: Last Transition Time: 2023-12-19T15:10:51Z Message: Ready to start profiling Reason: Ready Status: True Type: Ready Last Transition Time: 2023-12-19T15:11:01Z Message: Profiling query done Reason: Finished Status: True Type: Finished Finished Timestamp: 2023-12-19T15:11:01Z Start Timestamp: 2023-12-19T15:10:51ZStatusがTrue、TypeがFinishedになると、スクリプトの作成は完了です。次の bash スクリプトを実行して、コンテナーのルートパスからスクリプトデータを取得します。
#!/bin/bash RUN=$(oc get nodeobservabilityrun --no-headers | awk '{print $1}') for a in $(oc get nodeobservabilityruns.nodeobservability.olm.openshift.io/${RUN} -o json | jq .status.agents[].name); do echo "agent ${a}" agent=$(echo ${a} | tr -d "\"\'\`") base_dir=$(oc exec "${agent}" -c node-observability-agent -- bash -c "ls -t | grep node-observability-agent" | head -1) echo "${base_dir}" mkdir -p "/tmp/${agent}" for p in $(oc exec "${agent}" -c node-observability-agent -- bash -c "ls ${base_dir}"); do f="/${base_dir}/${p}" echo "copying ${f} to /tmp/${agent}/${p}" oc exec "${agent}" -c node-observability-agent -- cat ${f} > "/tmp/${agent}/${p}" done done