应用性能管理 APM-Deployment应用接入APM:步骤四:开启应用监控

时间:2024-09-18 17:25:39

步骤四:开启应用监控

  1. 在E CS 或CCE上,配置Deployment应用的启动脚本:在yaml描述文件中增加如下示例中加粗配置。

    执行如下命令编辑yaml文件:

    vi xxx.yaml
    其中xxx为文件名称,是您在创建Deployment应用时自定义的应用描述文件。如下为示例,Deployment的详细说明请参见kubernetes官方文档
    kind: Deployment 
    apiVersion: apps/v1 
    metadata: 
      name: user-service 
      namespace: default 
      selfLink: /apis/apps/v1/namespaces/default/deployments/user-service 
      uid: b231788d-9abd-11e8-80a5-fa163e3a2cc7 
      resourceVersion: '50972062' 
      generation: 13 
      creationTimestamp: '2018-08-08T03:46:56Z' 
      labels: 
        app: user-service 
        stack-name: auto-test 
      annotations: 
        deployment.kubernetes.io/revision: '5' 
        description: '' 
      enable: true 
    spec: 
      replicas: 1 
      selector: 
        matchLabels: 
          app: user-service 
      template: 
        metadata: 
          creationTimestamp: null 
          labels: 
            app: user-service 
          enable: true 
        spec: 
          #容器外主机上的挂载目录,包括数据输出路径、Java探针包路径 
          volumes: 
            - name: paas-apm 
              hostPath:  
                path: /opt/apm-container 
            - name: pinpoint-pkg 
              hostPath:  
                path: /opt/oss/servicemgr/ICAgent/pinpoint 
          containers: 
            - name: user-service 
              image: '100.125.0.198:20202/zhyyy/user-service:v1' 
              ports: 
                - containerPort: 8080 
                  protocol: TCP 
              env: 
                - name: PAAS_APP_NAME 
                  #工作负载名称(服务名称) 
                  value: user-service 
                - name: PAAS_NAMESPACE 
                  #CCE集群namespace,如果非CCE集群则不填该环境变量 
                  value: default 
                - name: PAAS_PROJECT_ID 
                  #租户项目projectId 
                  value: d698369a975645bfb35f8437d11c5a12 
                - name: PAAS_CLUSTER_ID 
                  #CCE集群ID,可以在CCE界面通过f12查看,如果非CCE集群则不填该环境变量 
                  value: 89b49857-5433-11e8-941c-0255ac101f3e 
                 - name: PAAS_POD_ID
                               valueFrom:
                                 fieldRef:
                                   fieldPath: metadata.uid
                - name: PAAS_MONITORING_GROUP 
                  #应用名称(监控组),建议完成一个功能的多个服务填写相同应用名称 
                  value: shoppingmall 
                - name: JAVA_TOOL_OPTIONS 
                  value: -javaagent:/opt/oss/servicemgr/ICAgent/pinpoint/pinpoint-bootstrap.jar -Dapm_container=true 
              resources: {} 
              #挂载进容器内数据输出路径、Java探针包路径 
              volumeMounts: 
                - name: paas-apm 
                  mountPath: /paas-apm/collectors/pinpoint 
                - name: pinpoint-pkg 
                  mountPath: /opt/oss/servicemgr/ICAgent/pinpoint 
    
              terminationMessagePath: /dev/termination-log 
              terminationMessagePolicy: File 
              imagePullPolicy: Always 
          restartPolicy: Always 
          terminationGracePeriodSeconds: 30 
          dnsPolicy: ClusterFirst 
          securityContext: {} 
          schedulerName: default-scheduler 
      strategy: 
        type: RollingUpdate 
        rollingUpdate: 
          maxUnavailable: 0 
          maxSurge: 1 
      revisionHistoryLimit: 10 
      progressDeadlineSeconds: 600 
    status: 
      observedGeneration: 13 
      replicas: 1 
      updatedReplicas: 1 
      readyReplicas: 1 
      availableReplicas: 1 
      conditions: 
        - type: Progressing 
          status: 'True' 
          lastUpdateTime: '2018-09-02T13:25:46Z' 
          lastTransitionTime: '2018-08-08T03:46:56Z' 
          reason: NewReplicaSetAvailable 
          message: ReplicaSet "user-service-f584f46b7" has successfully progressed. 
        - type: Available 
          status: 'True' 
          lastUpdateTime: '2018-12-21T11:01:33Z' 
          lastTransitionTime: '2018-12-21T11:01:33Z' 
          reason: MinimumReplicasAvailable 
          message: Deployment has minimum availability.
  2. 使用修改后的Deployment重启应用,开启应用性能监控。
support.huaweicloud.com/qs-apm/apm_00_0007.html