linuxea:skywalking9.1基于nacos的动态告警配置二(5)

marksugar
2022-06-30 / 0 评论 / 1,323 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年07月01日,已超过157天没有更新,若内容或图片失效,请留言反馈。

接着上一篇skywalking9.1基于nacos的动态告警配置一(4),这本是在一起的,由于字数问题,分为两篇来写。
那接着skywalking的ES安装完成后,继续配置skywalking和nacos的动态配置部分

2.skywalking与nacos

准备了这么多,其实就是先把nacos配置i起来,而后在skywalking中来调用,那么现在,我们配置nacos到skywalking中。

但是在此之前,我们要配置一个configmpa清单来来列出配置而后传入到skywalking中。

2.1 准备configmap文件

skywalking在早在8版本已经支持了动态配置,这些在/skywalking/config下的application.yml文件中,默认为none,需要修改这个环境变量来应用不同的配置中心,比如为nacos

阅读官网了解更多动态配置内容

configuration:
  selector: ${SW_CONFIGURATION:none}

我们修改为nacos使用,提供的变量如下

  nacos:
    # Nacos Server Host
    serverAddr: ${SW_CONFIG_NACOS_SERVER_ADDR:127.0.0.1}
    # Nacos Server Port
    port: ${SW_CONFIG_NACOS_SERVER_PORT:8848}
    # Nacos Configuration Group
    group: ${SW_CONFIG_NACOS_SERVER_GROUP:skywalking}
    # Nacos Configuration namespace
    namespace: ${SW_CONFIG_NACOS_SERVER_NAMESPACE:}
    # Unit seconds, sync period. Default fetch every 60 seconds.
    period: ${SW_CONFIG_NACOS_PERIOD:60}
    # Nacos auth username
    username: ${SW_CONFIG_NACOS_USERNAME:""}
    password: ${SW_CONFIG_NACOS_PASSWORD:""}
    # Nacos auth accessKey
    accessKey: ${SW_CONFIG_NACOS_ACCESSKEY:""}
    secretKey: ${SW_CONFIG_NACOS_SECRETKEY:""}

因此,我们需要将配置注入到pod中
在k8s里面,使用configmap中的值传入到skwalking-oap中即可
创建configmap清单,调用nacos,如下:

如果你是外置的nacos或者es就需要修改配置的链接地址。我这里是集群

apiVersion: v1
kind: ConfigMap
metadata:
  name: skywalking-to-nacos
  namespace: skywalking  
data:
  nacos.name: "nacos"
  nacos.addr: "nacos-0.nacos-headless.nacos.svc.cluster.local,nacos-1.nacos-headless.nacos.svc.cluster.local,nacos-2.nacos-headless.nacos.svc.cluster.local"
  nacos.port: "8848"
  nacos.group: "skywalking"
  nacos.namespace: "skywalking"
  nacos.synctime: "60"
  nacos.username: "nacos"
  nacos.password: "nacos"

这些配配置在skywalk-oap中需要传入

        - name: SW_CONFIGURATION
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.name
        - name: SW_CONFIG_NACOS_SERVER_ADDR
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.addr
        - name: SW_CONFIG_NACOS_SERVER_PORT
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.port
        - name: SW_CONFIG_NACOS_SERVER_GROUP
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.group
        - name: SW_CONFIG_NACOS_SERVER_NAMESPACE
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.namespace
        - name: SW_CONFIG_NACOS_PERIOD
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.synctime
        - name: SW_CONFIG_NACOS_USERNAME
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.username
        - name: SW_CONFIG_NACOS_PASSWORD
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.password

2.2 安装skywalking

当准备完成上面的配置后,yaml如下

#ServiceAccount
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app: skywalking
  name: skywalking-oap
  namespace: skywalking
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: skywalking
  namespace: skywalking  
  labels:
    app: skywalking
rules:
  - apiGroups: [""]
    resources: ["pods", "endpoints", "services", "nodes"]
    verbs: ["get", "watch", "list"]
  - apiGroups: ["extensions"]
    resources: ["deployments", "replicasets"]
    verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: skywalking
  namespace: skywalking  
  labels:
    app: skywalking
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: skywalking
subjects:
  - kind: ServiceAccount
    name: skywalking-oap
    namespace: skywalking
---
# oap
apiVersion: v1
kind: Service
metadata:
  name: skywalking-oap
  namespace: skywalking  
  labels:
    app: skywalking-oap
spec:
  type: ClusterIP
  ports:
  - port: 11800
    name: grpc
  - port: 12800
    name: rest
  selector:
    app: skywalking-oap
    chart: skywalking-4.2.0
---
# connent to nacos
apiVersion: v1
kind: ConfigMap
metadata:
  name: skywalking-to-nacos
  namespace: skywalking  
data:
  nacos.name: "nacos"
  # nacos.addr: "nacos-0.nacos-headless.skywalking.svc.cluster.local:8848,nacos-1.nacos-headless.skywalking.svc.cluster.local:8848,nacos-2.nacos-headless.skywalking.svc.cluster.local:8848"
  nacos.addr: "nacos-0.nacos-headless.nacos.svc.cluster.local,nacos-1.nacos-headless.nacos.svc.cluster.local,nacos-2.nacos-headless.nacos.svc.cluster.local"
  nacos.port: "8848"
  nacos.group: "skywalking"
  nacos.namespace: "skywalking"
  nacos.synctime: "60"
  nacos.username: "nacos"
  nacos.password: "nacos"   
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: skywalking-oap
  name: skywalking-oap
  namespace: skywalking  
spec:
  replicas: 1
  selector:
    matchLabels:
      app: skywalking-oap
  template:
    metadata:
      labels:
        app: skywalking-oap
        chart: skywalking-4.2.0
    spec:
      serviceAccount: skywalking-oap
      serviceAccountName: skywalking-oap
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            podAffinityTerm:
              topologyKey: kubernetes.io/hostname
              labelSelector:
                matchLabels:
                  app: "skywalking"
                  release: "skywalking"
                  component: "oap"
      initContainers:
      - name: wait-for-elasticsearch
        image: registry.cn-hangzhou.aliyuncs.com/marksugar/busybox:1.30
        imagePullPolicy: IfNotPresent
        command: ['sh', '-c', 'for i in $(seq 1 60); do nc -z -w3 elasticsearch 9200 && exit 0 || sleep 5; done; exit 1']
      containers:
      - name: oap
        image: registry.cn-hangzhou.aliyuncs.com/marksugar/skywalking-oap-server:9.1.0
        # docker pull apache/skywalking-oap-server:8.8.1
        imagePullPolicy: IfNotPresent
        livenessProbe:
          tcpSocket:
            port: 12800
          initialDelaySeconds: 15
          periodSeconds: 20
        readinessProbe:
          tcpSocket:
            port: 12800
          initialDelaySeconds: 15
          periodSeconds: 20
        ports:
        - containerPort: 11800
          name: grpc
        - containerPort: 12800
          name: rest
        env:
        - name: JAVA_OPTS
          value: "-Dmode=no-init -Xmx2g -Xms2g"
        - name: SW_CLUSTER
          value: kubernetes
        - name: SW_CLUSTER_K8S_NAMESPACE
          value: "default"
        - name: SW_CLUSTER_K8S_LABEL
          value: "app=skywalking,release=skywalking,component=oap"
        # 记录数据。
        - name: SW_CORE_RECORD_DATA_TTL
          value: "2"
        # Metrics数据  
        - name: SW_CORE_METRICS_DATA_TTL
          value: "2"
        - name: SKYWALKING_COLLECTOR_UID
          valueFrom:
            fieldRef:
              fieldPath: metadata.uid
        - name: SW_STORAGE
          value: elasticsearch
        - name: SW_STORAGE_ES_CLUSTER_NODES
          value: "elasticsearch:9200"
        # nacos
        - name: SW_CONFIGURATION
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.name
        - name: SW_CONFIG_NACOS_SERVER_ADDR
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.addr
        - name: SW_CONFIG_NACOS_SERVER_PORT
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.port
        - name: SW_CONFIG_NACOS_SERVER_GROUP
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.group
        - name: SW_CONFIG_NACOS_SERVER_NAMESPACE
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.namespace
        - name: SW_CONFIG_NACOS_PERIOD
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.synctime
        - name: SW_CONFIG_NACOS_USERNAME
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.username
        - name: SW_CONFIG_NACOS_PASSWORD
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.password
        volumeMounts:
          - name: alarm-settings
            mountPath: /skywalking/config/alarm-settings.yml
            subPath: alarm-settings.yml
      volumes:
      - configMap:
          name: alarm-configmap
        name: alarm-settings
---
# ui
apiVersion: v1
kind: Service
metadata:
  labels:
    app: skywalking-ui
  name: skywalking-ui
  namespace: skywalking  
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP
  selector:
    app: skywalking-ui
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: skywalking-ui
  namespace: skywalking  
  labels:
    app: skywalking-ui
spec:
  replicas: 1
  selector:
    matchLabels:
        app: skywalking-ui
  template:
    metadata:
      labels:
        app: skywalking-ui
    spec:
      affinity:
      containers:
      - name: ui
        image: registry.cn-hangzhou.aliyuncs.com/marksugar/skywalking-ui:9.1.0
        # docker pull apache/skywalking-ui:9.0.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          name: page
        env:
        - name: SW_OAP_ADDRESS
          value: http://skywalking-oap:12800    
---
# job
apiVersion: batch/v1
kind: Job
metadata:
  name: "skywalking-es-init"
  namespace: skywalking  
  labels:
    app: skywalking-job
spec:
  template:
    metadata:
      name: "skywalking-es-init"
      labels:
        app: skywalking-job
    spec:
      serviceAccount: skywalking-oap    
      serviceAccountName: skywalking-oap
      restartPolicy: Never
      initContainers:
      - name: wait-for-elasticsearch
        image: registry.cn-hangzhou.aliyuncs.com/marksugar/busybox:1.30
        imagePullPolicy: IfNotPresent
        command: ['sh', '-c', 'for i in $(seq 1 60); do nc -z -w3 elasticsearch 9200 && exit 0 || sleep 5; done; exit 1']
      containers:
      - name: oap
        image: registry.cn-hangzhou.aliyuncs.com/marksugar/skywalking-oap-server:9.1.0
        imagePullPolicy: IfNotPresent
        env:
        - name: JAVA_OPTS
          value: "-Xmx2g -Xms2g -Dmode=init"
        - name: SW_STORAGE
          value: elasticsearch
        - name: SW_STORAGE_ES_CLUSTER_NODES
          value: "elasticsearch:9200"

而后应用配置

PS J:\k8s-1.23.1-latest\nacos\skywalking> kubectl.exe apply -f .\9.1.yaml
serviceaccount/skywalking-oap created
clusterrole.rbac.authorization.k8s.io/skywalking created
clusterrolebinding.rbac.authorization.k8s.io/skywalking created
service/skywalking-oap created
configmap/skywalking-to-nacos created
deployment.apps/skywalking-oap created
service/skywalking-ui created
deployment.apps/skywalking-ui created
job.batch/skywalking-es-init created

启动完成后如下

PS J:\k8s-1.23.1-latest\nacos\skywalking> kubectl.exe -n skywalking get pod -w
NAME                              READY   STATUS      RESTARTS   AGE
elasticsearch-64c9d98794-ndktz    1/1     Running     0          15m
skywalking-es-init-p8j4z          0/1     Completed   0          6m13s
skywalking-oap-64b87cf44c-cgb8w   1/1     Running     0          2m26s
skywalking-ui-6c6f789f9f-qxxqd    1/1     Running     0          6m13s

2.2.B 本地nacos配置

#ServiceAccount
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app: skywalking
  name: skywalking-oap
  namespace: skywalking
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: skywalking
  namespace: skywalking  
  labels:
    app: skywalking
rules:
  - apiGroups: [""]
    resources: ["pods", "endpoints", "services", "nodes"]
    verbs: ["get", "watch", "list"]
  - apiGroups: ["extensions"]
    resources: ["deployments", "replicasets"]
    verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: skywalking
  namespace: skywalking  
  labels:
    app: skywalking
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: skywalking
subjects:
  - kind: ServiceAccount
    name: skywalking-oap
    namespace: skywalking
---
# oap
apiVersion: v1
kind: Service
metadata:
  name: skywalking-oap
  namespace: skywalking  
  labels:
    app: skywalking-oap
spec:
  type: ClusterIP
  ports:
  - port: 11800
    name: grpc
  - port: 12800
    name: rest
  selector:
    app: skywalking-oap
    chart: skywalking-4.2.0
---
# connent to nacos
apiVersion: v1
kind: ConfigMap
metadata:
  name: skywalking-to-nacos
  namespace: skywalking  
data:
  nacos.name: "nacos"
  nacos.addr: "172.16.15.136"
  nacos.port: "8848"
  nacos.group: "skywalking"
  nacos.namespace: "skywalking"
  nacos.synctime: "60"
  nacos.username: "nacos"
  nacos.password: "nacos"   
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: skywalking-oap
  name: skywalking-oap
  namespace: skywalking  
spec:
  replicas: 1
  selector:
    matchLabels:
      app: skywalking-oap
  template:
    metadata:
      labels:
        app: skywalking-oap
        chart: skywalking-4.2.0
    spec:
      serviceAccount: skywalking-oap
      serviceAccountName: skywalking-oap
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            podAffinityTerm:
              topologyKey: kubernetes.io/hostname
              labelSelector:
                matchLabels:
                  app: "skywalking"
                  release: "skywalking"
                  component: "oap"
      initContainers:
      - name: wait-for-elasticsearch
        image: registry.cn-hangzhou.aliyuncs.com/marksugar/busybox:1.30
        imagePullPolicy: IfNotPresent
        command: ['sh', '-c', 'for i in $(seq 1 60); do nc -z -w3 elasticsearch 9200 && exit 0 || sleep 5; done; exit 1']
      containers:
      - name: oap
        image: registry.cn-hangzhou.aliyuncs.com/marksugar/skywalking-oap-server:9.1.0
        # docker pull apache/skywalking-oap-server:8.8.1
        imagePullPolicy: IfNotPresent
        livenessProbe:
          tcpSocket:
            port: 12800
          initialDelaySeconds: 15
          periodSeconds: 20
        readinessProbe:
          tcpSocket:
            port: 12800
          initialDelaySeconds: 15
          periodSeconds: 20
        ports:
        - containerPort: 11800
          name: grpc
        - containerPort: 12800
          name: rest
        env:
        - name: JAVA_OPTS
          value: "-Dmode=no-init -Xmx2g -Xms2g"
        - name: SW_CLUSTER
          value: kubernetes
        - name: SW_CLUSTER_K8S_NAMESPACE
          value: "default"
        - name: SW_CLUSTER_K8S_LABEL
          value: "app=skywalking,release=skywalking,component=oap"
        # 记录数据。
        - name: SW_CORE_RECORD_DATA_TTL
          value: "2"
        # Metrics数据  
        - name: SW_CORE_METRICS_DATA_TTL
          value: "2"
        - name: SKYWALKING_COLLECTOR_UID
          valueFrom:
            fieldRef:
              fieldPath: metadata.uid
        - name: SW_STORAGE
          value: elasticsearch
        - name: SW_STORAGE_ES_CLUSTER_NODES
          value: "elasticsearch:9200"
        # nacos
        - name: SW_CONFIGURATION
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.name
        - name: SW_CONFIG_NACOS_SERVER_ADDR
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.addr
        - name: SW_CONFIG_NACOS_SERVER_PORT
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.port
        - name: SW_CONFIG_NACOS_SERVER_GROUP
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.group
        - name: SW_CONFIG_NACOS_SERVER_NAMESPACE
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.namespace
        - name: SW_CONFIG_NACOS_PERIOD
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.synctime
        - name: SW_CONFIG_NACOS_USERNAME
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.username
        - name: SW_CONFIG_NACOS_PASSWORD
          valueFrom:
            configMapKeyRef:
              name: skywalking-to-nacos
              key: nacos.password
        volumeMounts:
          - name: alarm-settings
            mountPath: /skywalking/config/alarm-settings.yml
            subPath: alarm-settings.yml
      volumes:
      - configMap:
          name: alarm-configmap
        name: alarm-settings
---
# ui
apiVersion: v1
kind: Service
metadata:
  labels:
    app: skywalking-ui
  name: skywalking-ui
  namespace: skywalking  
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP
  selector:
    app: skywalking-ui
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: skywalking-ui
  namespace: skywalking  
  labels:
    app: skywalking-ui
spec:
  replicas: 1
  selector:
    matchLabels:
        app: skywalking-ui
  template:
    metadata:
      labels:
        app: skywalking-ui
    spec:
      affinity:
      containers:
      - name: ui
        image: registry.cn-hangzhou.aliyuncs.com/marksugar/skywalking-ui:9.1.0
        # docker pull apache/skywalking-ui:9.0.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          name: page
        env:
        - name: SW_OAP_ADDRESS
          value: http://skywalking-oap:12800    
---
# job
apiVersion: batch/v1
kind: Job
metadata:
  name: "skywalking-es-init"
  namespace: skywalking  
  labels:
    app: skywalking-job
spec:
  template:
    metadata:
      name: "skywalking-es-init"
      labels:
        app: skywalking-job
    spec:
      serviceAccount: skywalking-oap    
      serviceAccountName: skywalking-oap
      restartPolicy: Never
      initContainers:
      - name: wait-for-elasticsearch
        image: registry.cn-hangzhou.aliyuncs.com/marksugar/busybox:1.30
        imagePullPolicy: IfNotPresent
        command: ['sh', '-c', 'for i in $(seq 1 60); do nc -z -w3 172.16.15.136 9200 && exit 0 || sleep 5; done; exit 1']
      containers:
      - name: oap
        image: registry.cn-hangzhou.aliyuncs.com/marksugar/skywalking-oap-server:9.1.0
        imagePullPolicy: IfNotPresent
        env:
        - name: JAVA_OPTS
          value: "-Xmx2g -Xms2g -Dmode=init"
        - name: SW_STORAGE
          value: 172.16.15.136
        - name: SW_STORAGE_ES_CLUSTER_NODES
          value: "172.16.15.136:9200"

2.3 配置ingress

skywalking的ui没有用户名密码认证,于是我们通过Ingress来配置一个简单的nginx auth认证即可

用户名: linuxea

密码: OpSOQKs,qDJ1dSvzs

apiVersion: v1
data:
  auth: bGludXhlYTokYXByMSRidG1naTc0cyRKRUtJcThkVEUzT0k4bzVhMXFRdnEwCg==
kind: Secret
metadata:
  name: basic-auth
  namespace: skywalking
type: Opaque

ingress配置如下

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: skywalking-ui
  namespace: skywalking
  annotations:
    nginx.ingress.kubernetes.io/auth-type: basic
    nginx.ingress.kubernetes.io/auth-secret: basic-auth
    nginx.ingress.kubernetes.io/auth-realm: "Authentication Required - input: Trump "  
spec:
  ingressClassName: nginx
  rules:
  - host: skywalking.linuxea.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: skywalking-ui
            port:
              number: 80

分别创建他们

PS J:\k8s-1.23.1-latest\nacos\skywalking> kubectl.exe apply -f .\secret.yaml
secret/basic-auth created
PS J:\k8s-1.23.1-latest\nacos\skywalking> kubectl.exe apply -f .\ingress.yaml
ingress.networking.k8s.io/skywalking-ui created

查看创建情况

PS J:\k8s-1.23.1-latest\nacos\skywalking> kubectl.exe -n skywalking get ingress
NAME            CLASS   HOSTS                    ADDRESS                       PORTS   AGE
skywalking-ui   nginx   skywalking.linuxea.com   172.16.100.11,172.16.100.43   80      22s

修改本地hosts文件解析后,进行访问

172.16.100.11  nacos.linuxea.com skywalking.linuxea.com

image-20220626235429475.png

输入用户名: linuxea

输入密码: OpSOQKs,qDJ1dSvzs

image-20220626235545890.png

2.3 日志信息

查看ops的日志信息,如果应用后nacos没有配置,在日志中将会看到变动

参阅官方文档获取更多信息

key:core.default.log4j-xml    module:core    provider:default    value(current):null
key:agent-analyzer.default.uninstrumentedGateways    module:agent-analyzer    provider:default    value(current):null
key:configuration-discovery.default.agentConfigurations    module:configuration-discovery    provider:default    value(current):null
key:agent-analyzer.default.traceSamplingPolicy    module:agent-analyzer    provider:default    value(current):null
key:core.default.endpoint-name-grouping    module:core    provider:default    value(current):SkyWalking endpoint rule
key:core.default.apdexThreshold    module:core    provider:default    value(current):null
key:agent-analyzer.default.slowDBAccessThreshold    module:agent-analyzer    provider:default    value(current):null
key:alarm.default.alarm-settings    module:alarm    provider:default    value(current):null  

没有配置全是null

Following dynamic config items are available.
---------------------------------------------
key:core.default.log4j-xml    module:core    provider:default    value(current):null
key:agent-analyzer.default.uninstrumentedGateways    module:agent-analyzer    provider:default    value(current):null
key:configuration-discovery.default.agentConfigurations    module:configuration-discovery    provider:default    value(current):null
key:agent-analyzer.default.traceSamplingPolicy    module:agent-analyzer    provider:default    value(current):null
key:core.default.endpoint-name-grouping    module:core    provider:default    value(current):SkyWalking endpoint rule
key:core.default.apdexThreshold    module:core    provider:default    value(current):null
key:agent-analyzer.default.slowDBAccessThreshold    module:agent-analyzer    provider:default    value(current):null
key:alarm.default.alarm-settings    module:alarm    provider:default    value(current):null

2022-06-26 16:18:27,691 com.linecorp.armeria.common.util.SystemInfo 237 [main] INFO  [] - hostname: skywalking-oap-64b87cf44c-d5l6n (from /proc/sys/kernel/hostname)
2022-06-26 16:18:27,692 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: core.default.log4j-xml: null
2022-06-26 16:18:27,694 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: agent-analyzer.default.uninstrumentedGateways: null
2022-06-26 16:18:27,695 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: configuration-discovery.default.agentConfigurations: null
2022-06-26 16:18:27,699 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: agent-analyzer.default.traceSamplingPolicy: null
2022-06-26 16:18:27,701 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: core.default.endpoint-name-grouping: null
2022-06-26 16:18:27,703 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: core.default.apdexThreshold: null
2022-06-26 16:18:27,704 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: agent-analyzer.default.slowDBAccessThreshold: null
2022-06-26 16:18:27,705 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: alarm.default.alarm-settings: null
2022-06-26 16:18:28,006 com.linecorp.armeria.server.Server 755 [armeria-boss-http-*:12800] INFO  [] - Serving HTTP at /0.0.0.0:12800 - http://127.0.0.1:12800/
2022-06-26 16:18:28,007 org.apache.skywalking.oap.server.core.storage.PersistenceTimer 58 [main] INFO  [] - persistence timer start
2022-06-26 16:18:28,008 org.apache.skywalking.oap.server.core.cache.CacheUpdateTimer 46 [main] INFO  [] - Cache updateServiceInventory timer start
2022-06-26 16:18:28,369 org.apache.skywalking.oap.server.starter.OAPServerBootstrap 53 [main] INFO  [] - Version of OAP: 9.1.0-f1f519c

2.4 nacos配置管理

我们配置一个示例,比如告警

在nacos页面中-》名称空间-》新建名称空间-》创建skywalking的名称空间
image-20220627000544528.png

在nacos页面中-》配置列表-》选中skywalking -》+号

也就是说在skywaling名称空间内创建这个配置

image-20220526094314112.png

在nacos页面中-》配置列表-》+号-》输入id和组

回到日志信息中,配置是以key:value的形式

key:alarm.default.alarm-settings

配置信息如下

rules:
  # Rule unique name, must be ended with `_rule`.
  service_resp_time_rule:
  # 以_rule结尾的规则名称,必须唯一
    metrics-name: service_resp_time # 名称
    op: ">" # 运算符
    threshold: 1000 # 阈值
    period: 5  #周期
    count: 3 # 次数
    silence-period: 15 # 沉默时间  
    message: Response time of service {name} is more than 1000ms in 3 minutes of last 10 minutes.
  service_sla_rule:
    # Metrics value need to be long, double or int
    metrics-name: service_sla
    op: "<"
    threshold: 8000
    # The length of time to evaluate the metrics
    period: 10
    # How many times after the metrics match the condition, will trigger alarm
    count: 2
    # How many times of checks, the alarm keeps silence after alarm triggered, default as same as period.
    silence-period: 3
    message: Successful rate of service {name} is lower than 80% in 2 minutes of last 10 minutes
  service_resp_time_percentile_rule:
    # Metrics value need to be long, double or int
    metrics-name: service_percentile
    op: ">"
    threshold: 1000,1000,1000,1000,1000
    period: 10
    count: 3
    silence-period: 5
    message: Percentile response time of service {name} alarm in 3 minutes of last 10 minutes, due to more than one condition of p50 > 1000, p75 > 1000, p90 > 1000, p95 > 1000, p99 > 1000
  service_instance_resp_time_rule:
    metrics-name: service_instance_resp_time
    op: ">"
    threshold: 1000
    period: 10
    count: 2
    silence-period: 5
    message: Response time of service instance {name} is more than 1000ms in 2 minutes of last 10 minutes
  database_access_resp_time_rule:
    metrics-name: database_access_resp_time
    threshold: 1000
    op: ">"
    period: 10
    count: 2
    message: Response time of database access {name} is more than 1000ms in 2 minutes of last 10 minutes
  endpoint_relation_resp_time_rule:
    metrics-name: endpoint_relation_resp_time
    threshold: 1000
    op: ">"
    period: 10
    count: 2
    message: Response time of endpoint relation {name} is more than 1000ms in 2 minutes of last 10 minutes
dingtalkHooks:
  textTemplate: |-
    {
      "msgtype": "text",
      "text": {
        "content": "Apache SkyWalking Alarm: \n %s."
      }
    }
  webhooks:
    - url: https://oapi.dingtalk.com/robot/send?access_token=322a01560303e2e96e8e1261d491ffc918c686bbfd2f7e846
      secret: SEC71126603dfcf6594e96ffad825ac3e32d2a3fde0e643bbd80a7a473208fc5706

填写到nacos中

image-20220627000105537.png

点击发布

一旦创建完成,nacos中配置管理的skywalking名称空间下就有了alarm.default.alarm-settings配置信息

image-20220627000713879.png

而后回到oap中查看日志信息

kubectl -n skywalking logs -f skywalking-oap-74b59b897c-2slvn
2022-06-26 16:41:20,965 com.linecorp.armeria.common.util.SystemInfo 237 [main] INFO  [] - hostname: skywalking-oap-6f58cbc9d8-hmfw9 (from /proc/sys/kernel/hostname)
2022-06-26 16:41:20,978 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: core.default.log4j-xml: null
2022-06-26 16:41:20,987 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: agent-analyzer.default.uninstrumentedGateways: null
2022-06-26 16:41:20,995 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: configuration-discovery.default.agentConfigurations: null
2022-06-26 16:41:20,998 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: agent-analyzer.default.traceSamplingPolicy: null
2022-06-26 16:41:21,005 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: core.default.endpoint-name-grouping: null
2022-06-26 16:41:21,008 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: core.default.apdexThreshold: null
2022-06-26 16:41:21,011 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: agent-analyzer.default.slowDBAccessThreshold: null
2022-06-26 16:41:21,034 org.apache.skywalking.oap.server.configuration.nacos.NacosConfigWatcherRegister 168 [pool-7-thread-1] INFO  [] - Nacos config changed: alarm.default.alarm-settings: rules:
  # Rule unique name, must be ended with `_rule`.
  service_resp_time_rule:
  # 以_rule结尾的规则名称,必须唯一
    metrics-name: service_resp_time # 名称
    op: ">" # 运算符
    threshold: 1000 # 阈值
    period: 5  #周期
    count: 3 # 次数
    silence-period: 15 # 沉默时间 
    message: Response time of service {name} is more than 1000ms in 3 minutes of last 10 minutes.
  service_sla_rule:
    # Metrics value need to be long, double or int
    metrics-name: service_sla
    op: "<"
    threshold: 8000
    # The length of time to evaluate the metrics
    period: 10
    # How many times after the metrics match the condition, will trigger alarm
    count: 2
    # How many times of checks, the alarm keeps silence after alarm triggered, default as same as period.
    silence-period: 3
    message: Successful rate of service {name} is lower than 80% in 2 minutes of last 10 minutes
  service_resp_time_percentile_rule:
    # Metrics value need to be long, double or int
    metrics-name: service_percentile
    op: ">"
    threshold: 1000,1000,1000,1000,1000
    period: 10
    count: 3
    silence-period: 5
    message: Percentile response time of service {name} alarm in 3 minutes of last 10 minutes, due to more than one condition of p50 > 1000, p75 > 1000, p90 > 1000, p95 > 1000, p99 > 1000
  service_instance_resp_time_rule:
    metrics-name: service_instance_resp_time
    op: ">"
    threshold: 1000
    period: 10
    count: 2
    silence-period: 5
    message: Response time of service instance {name} is more than 1000ms in 2 minutes of last 10 minutes
  database_access_resp_time_rule:
    metrics-name: database_access_resp_time
    threshold: 1000
    op: ">"
    period: 10
    count: 2
    message: Response time of database access {name} is more than 1000ms in 2 minutes of last 10 minutes
  endpoint_relation_resp_time_rule:
    metrics-name: endpoint_relation_resp_time
    threshold: 1000
    op: ">"
    period: 10
    count: 2
    message: Response time of endpoint relation {name} is more than 1000ms in 2 minutes of last 10 minutes
dingtalkHooks:
  textTemplate: |-
    {
      "msgtype": "text",
      "text": {
        "content": "Apache SkyWalking Alarm: \n %s."
      }
    }
  webhooks:
    - url: https://oapi.dingtalk.com/robot/send?access_token=322a01560303e2ed491ffc918c686bbfd2f7e8420de36301a5d9536
      secret: SEC71126603dfcf6594e96ffad825ac3e32d2a3fde0e643b208fc5706

而一旦配置发生改变将会在日志中看到进度

image-20220627004415768.png

使用一个不断触发的阈值,大于1毫秒的都被触发

rules:
  # Rule unique name, must be ended with `_rule`.
  service_resp_time_rule:
    metrics-name: service_resp_time
    op: "<"
    threshold: 1
    period: 1
    count: 1
    silence-period: 2
    #message: 服务:{name}\n  指标:响应时间\n  详情:至少1次超过1毫秒(最近2分钟内)   
    message: 服务:{name}的响应时间至少1次超过1毫秒(最近2分钟内)    
dingtalkHooks:
  textTemplate: |-
    {
      "msgtype": "text",
      "text": {
        "content": "Apache SkyWalking Alarm: \n%s."
      }
    }
  webhooks:
    - url: https://oapi.dingtalk.com/robot/send?access_token=18d15996fa24e3eabe8
      secret: SEC65d0a92e985fa0dc5df11ec88d89763a178102

nacos和skywalking配置完成。

参考

观测语句参考
参考2
参考3

到底要配置什么oal,需要关注/skywalking/config/oal下的文件,这些是oal-runner,oal运行时
关注聚合函数:aggregation-function

oal参考如下:
https://github.com/apache/skywalking/blob/master/docs/en/concepts-and-designs/oal.md
https://github.com/apache/skywalking/blob/master/docs/en/guides/backend-oal-scripts.md
https://skywalking.apache.org/docs/skywalking-java/latest/en/setup/service-agent/java-agent/java-plugin-development-guide/#extension-logic-endpoint-tag-key-x-le
https://www.cnblogs.com/heihaozi/p/14958368.html

0

评论

博主关闭了当前页面的评论