博客 / 詳情

返回

【技術教程】如何部署統計 Kuscia 引擎指標監控?

打開鏈接即可點亮社區Star,照亮技術的前進之路。

Github 地址:https://github.com/secretflow/kuscia

在生產環境中,Kuscia 中運行的引擎(如 SecretFlow-Serving)可能需要統計引擎相關的指標,比如引擎成功調用次數,引擎錯誤率,引擎運行延時等。

本文描述如何配置 Kuscia monitor 監控引擎層透出的指標,包括引擎配置和集羣監控配置兩個部分。

1 引擎配置

假設你的引擎為一個 Node Exporter 服務,並註冊了 /metrics 接口,你希望將該接口用於 Prometheus 監控數據,可以通過以下例子來編寫 appimage

apiVersion: kuscia.secretflow/v1alpha1
kind: AppImage
metadata:
  name: node-exporter
spec:
  configTemplates:
    task-config.conf: |
      {{{.ALLOCATED_PORTS.ports[name=metric].port}}}
  deployTemplates:
  - name: secretflow
    replicas: 1
    spec:
      containers:
      - configVolumeMounts:
        - mountPath: /work/kuscia/task-config.conf
          subPath: task-config.conf
        name: secretflow
        command:
        - sh
        args:
        - -c
        - node_exporter --web.listen-address=:$(cat /work/kuscia/task-config.conf)
        ports:
        - name: metric
          protocol: HTTP
          scope: Domain
        workingDir: /work
        metricProbe:
          path: /metrics
          port: metric
      restartPolicy: Never
  image:
    name: docker.io/prom/node-exporter
    tag: latest

其中值得注意的是:

ports:
- name: metric
  protocol: HTTP
  scope: Domain
metricProbe:
  path: /metrics
  port: metric

ports[0] 為引擎定義了一個名為 metric 的 HTTP 端口,該端口的端口號會在引擎啓動時分配,在本示例中會將端口號渲染至 \{{.ALLOCATED_PORTS.ports[name=metric].port}} 的變量裏,具體渲染規則詳見如何在 Kuscia 中給自定義應用渲染配置文件

metricProbe 表示該引擎和外部交互的指標統計接口,metricProbe.path 定義了接口路徑(此處為 /metrics),metricProbe.port 定義了接口名稱(此處為 metric,和 port[0] 的端口名稱相互對應)。

2 集羣配置

前置準備

在部署 Kuscia monitor 前,您需要參考之前的兩篇文章 [Docker 多機部署 Kuscia] 和 [K8s 集羣部署 Kuscia]部署 Kuscia 節點,並確保 Kuscia 節點正常運行。

部署

引擎會在 Kuscia 集羣內運行,需要在 Kuscia 集羣內部署 Kuscia monitor。

假設你的 Kuscia 實例運行在 alice(bob 同理)domain 下, 可以分為 Center 和 P2P 兩種情況進行部署:

P2P 模式部署

  1. alice 節點導入 monitor 鏡像

    # Docker mode, K8s deployment does not require importing the image
    export KUSCIA_MONITOR_IMAGE=secretflow-registry.cn-hangzhou.cr.aliyuncs.com/secretflow/kuscia-monitor:latest
    docker cp <alice-container-id>:/home/kuscia/scripts/deploy/register_app_image.sh . && chmod u+x register_app_image.sh
    bash register_app_image.sh -c <alice-container-id> -i "${KUSCIA_MONITOR_IMAGE}" --import
  2. 登錄到安裝 alice 的容器裏部署 monitor

    # Docker mode
    docker exec -it <alice-container-id> bash -c "scripts/deploy/kuscia.sh monitor"
    
    # k8s mode
    kubectl exec -it <alice-pod-name> -n <alice-pod-namespace> -- bash -c "scripts/deploy/kuscia.sh monitor"

Center 模式部署

  1. alice 節點導入 monitor 鏡像

    # Docker mode, K8s deployment does not require importing the image
    export KUSCIA_MONITOR_IMAGE=secretflow-registry.cn-hangzhou.cr.aliyuncs.com/secretflow/kuscia-monitor:latest
    docker cp <alice-container-id>:/home/kuscia/scripts/deploy/register_app_image.sh . && chmod u+x register_app_image.sh
    bash register_app_image.sh -c <alice-container-id> -i "${KUSCIA_MONITOR_IMAGE}" --import
  2. 登錄到安裝 master 的容器裏部署 monitor

    # Unlike P2P mode, Center mode requires specifying the domain of the lite node inside the master container
    # Docker mode
    docker exec -it <master-container-id> bash -c "scripts/deploy/kuscia.sh monitor alice"
    
    # k8s mode
    # lite node is using runc/runp runtime
    kubectl exec -it <master-pod-name> -n <master-pod-namespace> -- bash -c "scripts/deploy/kuscia.sh monitor alice"
    
    # When the lite node is using the runk runtime, you need to add --runk and specify the namespace of the lite node pod
    kubectl exec -it <master-pod-name> -n <master-pod-namespace> -- bash -c "export LITE_NAMESPACE=<lite-pod-namespace>;scripts/deploy/kuscia.sh monitor alice --runk"
user avatar
0 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.