下一篇【第72篇】SkyWalking指标基线与异常检测——超越静态阈值告警的智能监控
上一篇【第74篇】SkyWalking 9.x新特性——K8s原生集成、Continuous Profiling与Layer概念


一、8.x —— SkyWalking的"成年礼"

如果SkyWalking 7.x是"功能完备的APM工具",那8.x就是"全栈可观测性平台"。

7.x时代,SkyWalking主要关注后端微服务的追踪和指标。而8.x开始,它的视野扩展到了:

  • 前端:浏览器端的监控
  • 内核:eBPF探针(操作系统级别)
  • 语言:MAL(更灵活的指标定义)
  • 边缘:Satellite(数据收集网关)
+------------------------------------------------------------------+
|          SkyWalking 8.x 架构全景                                    |
+------------------------------------------------------------------+
|                                                                    |
|  ┌───────────────────────────────────────────────────────────┐    │
|  │                    前端可观测                               │    │
|  │  ┌─────────────┐  ┌─────────────────────────────────┐    │    │
|  │  │ Browser App │  │ 浏览器端监控 (JavaScript Agent) │    │    │
|  │  │ + JS Agent  │  │ - 页面加载时间                    │    │    │
|  │  │             │  │ - AJAX请求追踪                    │    │    │
|  │  │             │  │ - 错误收集                        │    │    │
|  │  └──────┬──────┘  │ - 用户行为                         │    │    │
|  │         │         └─────────────────────────────────┘    │    │
|  └─────────┼───────────────────────────────────────────────┘    │
|            │                                                      │
|  ┌─────────▼───────────────────────────────────────────────┐    │
|  │                    后端可观测                               │    │
|  │  ┌───────────┐ ┌───────────┐ ┌───────────────────────┐  │    │
|  │  │Java Agent │ │Go Agent   │ │ eBPF Agent (新!)      │  │    │
|  │  │.NET Agent │ │Python     │ │ - 网络层监控           │  │    │
|  │  │Node Agent │ │Rust Agent │ │ - 系统调用追踪         │  │    │
|  │  │           │ │           │ │ - 零侵入!              │  │    │
|  │  └───────────┘ └───────────┘ └───────────────────────┘  │    │
|  └───────────────┬─────────────────────────────────────────┘    │
|                  │                                                │
|          ┌───────┼───────┐                                       │
|          │       │       │                                        │
|          ↓       ↓       ↓                                        │
|  ┌───────────────────────────────────────────────────────────┐    │
|  │              Satellite (新!)                               │    │
|  │  - 数据收集网关                                            │    │
|  │  - 协议转换                                                │    │
|  │  - 边缘计算                                                │    │
|  └───────────────────────┬───────────────────────────────────┘    │
|                          │                                         │
|                          ↓                                         │
|  ┌───────────────────────────────────────────────────────────┐    │
|  │                  OAP Server                                │    │
|  │  ┌──────────────┐ ┌──────────────┐ ┌──────────────┐      │    │
|  │  │ Trace分析     │ │ MAL引擎(新!)│ │ 告警引擎      │      │    │
|  │  │ (传统)       │ │ - 灵活指标  │ │              │      │    │
|  │  │              │ │ - 直方图    │ │              │      │    │
|  │  │              │ │ - 百分位    │ │              │      │    │
|  │  └──────────────┘ └──────────────┘ └──────────────┘      │    │
|  └───────────────────────────────────────────────────────────┘    │
|                                                                    |
+------------------------------------------------------------------+

二、浏览器端监控(Browser Monitoring)

2.1 为什么需要监控前端

+------------------------------------------------------------------+
|          全链路视角的重要性                                         |
+------------------------------------------------------------------+
|                                                                    |
|  没有前端监控:                                                      |
|  ┌──────────────────────────────────────────────┐                 │
|  │ 用户说"页面加载慢"                            │                 │
|  │     ↓                                        │                 │
|  │ 后端监控: 后端处理只用了50ms                  │                 │
|  │     ↓                                        │                 │
|  │ 问题在哪?不知道!                            │                 │
|  │  → 可能是网络慢                               │                 │
|  │  → 可能是前端渲染慢                           │                 │
|  │  → 可能是CDN挂了一个节点                       │                 │
|  └──────────────────────────────────────────────┘                 │
|                                                                    |
|  有了前端监控:                                                      |
|  ┌──────────────────────────────────────────────┐                 │
|  │ 用户 → DNS(10ms) → TCP(5ms) → SSL(20ms)     │                 │
|  │  → 首字节(200ms!!) ← 发现问题!               │                 │
|  │  → DOM解析(300ms) → 资源加载(500ms)          │                 │
|  │     ↓                                        │                 │
|  │ 后端: 50ms ✓                                 │                 │
|  │ 问题: CDN节点挂了, 静态资源走了源站            │                 │
|  └──────────────────────────────────────────────┘                 │
|                                                                    |
+------------------------------------------------------------------+

2.2 接入方式

<!-- 在HTML中引入SkyWalking JS Agent -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>My App</title>
    
    <!-- SkyWalking Browser Agent -->
    <script src="https://skywalking-oap.example.com/browser/skywalking-js-client.js">
    </script>
</head>
<body>
    <div id="app"></div>
    
    <script>
        // 注册并配置Agent
        ClientMonitor.register({
            // OAP Server 地址
            collector: 'https://skywalking-oap.example.com',
            
            // 服务名称
            service: 'my-frontend-app',
            serviceVersion: '1.0.0',
            
            // 页面路径
            pagePath: '/dashboard',
            
            // AJAX监控
            autoTracePerf: true,         // 自动追踪AJAX请求性能
            traceSDKInternal: false,      // 是否追踪SDK内部请求
            
            // 错误监控
            jsErrors: true,               // 收集JS错误
            apiErrors: true,              // 收集API错误
            resourceErrors: true,         // 收集资源加载错误
            
            // 用户行为
            traceUserInteraction: true,    // 追踪用户交互
            enableSPA: true,              // SPA应用支持
            
            // 采样
            sampleRate: 1.0,              // 100%采样
            
            // 关联后端Trace
            traceHeaders: {
                'sw8': true               // 自动传播sw8 header
            }
        });
    </script>
</body>
</html>

2.3 监控指标

浏览器端监控的核心指标:

页面性能:
- FCP (First Contentful Paint)     ← 首次内容绘制
- LCP (Largest Contentful Paint)    ← 最大内容绘制
- FID (First Input Delay)           ← 首次输入延迟
- TTFB (Time to First Byte)        ← 首字节时间
- CLS (Cumulative Layout Shift)     ← 累计布局偏移

API请求 (AJAX):
- 每个AJAX请求的响应时间
- 请求成功率
- 错误详情

错误追踪:
- JS运行时错误
- 资源加载错误(404等)
- Promise未处理异常

用户行为:
- 页面访问量(PV)
- 独立访客(UV)
- 页面停留时间

三、eBPF探针 —— 零侵入的操作系统级监控

3.1 eBPF是什么

eBPF (extended Berkeley Packet Filter) 是Linux内核中的一项技术,允许在不修改内核源代码的情况下,在内核中运行沙盒程序。

+------------------------------------------------------------------+
|          eBPF探针的工作原理                                         |
+------------------------------------------------------------------+
|                                                                    |
|  ┌─────────────────────────────────────────────────────────────┐  │
|  │                         Application                         │  │
|  │  ┌──────────┐ ┌──────────┐ ┌──────────┐                   │  │
|  │  │ Process1 │ │ Process2 │ │ Process3 │                   │  │
|  │  └────┬─────┘ └────┬─────┘ └────┬─────┘                   │  │
|  │       │             │             │                          │  │
|  └───────┼─────────────┼─────────────┼──────────────────────────┘  │
|          │             │             │                              │
|  ┌───────▼─────────────▼─────────────▼──────────────────────────┐  │
|  │                    System Call Interface                     │  │
|  │  ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐          │  │
|  │  │ read()  │ │ write() │ │sendto() │ │recvfrom()│          │  │
|  │  └────┬────┘ └────┬────┘ └────┬────┘ └────┬────┘          │  │
|  │       │           │           │           │                  │  │
|  └───────┼───────────┼───────────┼───────────┼──────────────────┘  │
|          │           │           │           │                      │
|          │    ┌──────┴──────┐    │    ┌──────┴──────┐              │
|          │    │ eBPF Program│    │    │ eBPF Program│              │
|          │    │ (监控write) │    │    │ (监控sendto)│              │
|          │    └──────┬──────┘    │    └──────┬──────┘              │
|          │           │           │           │                      │
|          │    ┌──────▼───────────▼───────────▼──────┐              │
|          │    │         eBPF Maps (数据存储)         │              │
|          │    └──────────────┬───────────────────────┘              │
|          │                   │                                      │
|  ┌───────▼───────────────────▼──────────────────────────────────┐  │
|  │                     Linux Kernel                             │  │
|  │  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐      │  │
|  │  │ Network  │ │   Disk   │ │  Memory  │ │ Scheduler│      │  │
|  │  │ Stack    │ │   I/O    │ │   Mgmt   │ │          │      │  │
|  │  └──────────┘ └──────────┘ └──────────┘ └──────────┘      │  │
|  └──────────────────────────────────────────────────────────────┘  │
|                                                                    |
+------------------------------------------------------------------+

3.2 SkyWalking eBPF的能力

# SkyWalking Rover (eBPF探针管理器)
# Rover通过eBPF程序监控以下维度:

# 1. 网络层监控
# - 每个TCP连接的数据量
# - 每个进程的网络延迟
# - TLS握手时间

# 2. 系统调用监控
# - 磁盘I/O延迟
# - 文件操作频率

# 3. 进程监控
# - 进程级CPU使用率
# - 内存分配追踪

# Rover部署
docker run -d --name rover \
  --privileged \
  -e SW_ROVER_BACKEND=oap-server:11800 \
  -e SW_ROVER_PROCESS_DISCOVERY_ENABLED=true \
  apache/skywalking-rover:0.5.0

四、MAL —— Meter Analysis Language

4.1 为什么需要MAL

传统的OAL只能处理Trace数据生成的指标。但现代运维中,很多数据源无法通过Trace体现:

  • Prometheus格式的指标
  • OpenTelemetry的Metrics
  • 自定义上报的数值指标

MAL就是为了解决这个问题而设计的——它让你可以用类似SQL的语法定义指标聚合规则。

4.2 MAL语法示例

// ==========================================
// MAL基本语法
// ==========================================

// 1. 从Meter中定义指标
http_request_count = from(HttpRequest.count)
    .filter(service == "order-service")
    .sum();

// 2. 创建直方图(支持百分位计算)
http_request_latency = from(HttpRequest.latency)
    .filter(status == "200")
    .histogram("http_request_latency_histogram", 
        10, 50, 100, 200, 500, 1000, 2000
    );

// 3. 百分位计算
http_p99 = http_request_latency.percentile(99);
http_p95 = http_request_latency.percentile(95);
http_p50 = http_request_latency.percentile(50);

// 4. 速率计算
http_qps = http_request_count.rate("PT1M");  // 每分钟请求数

// 5. 多条件过滤
error_rate = from(HttpRequest.count)
    .filter(service == "order-service")
    .filter(status == "500")
    .rate("PT1M");

// 6. 表达式计算
error_percentage = (error_rate / http_qps) * 100;

4.3 配置Prometheus指标接入

# application.yml
prometheus-fetcher:
  selector: ${SW_PROMETHEUS_FETCHER:default}
  default:
    enabledRules: ${SW_PROMETHEUS_FETCHER_ENABLED_RULES:"default"}
    active: true
    
    # Prometheus采集规则
    rules:
      - name: default
        # 采集的端点
        url: http://prometheus:9090
        
        # 指标过滤规则
        metric-prefix: skywalking_custom_
        
        # 采集间隔
        interval: ${SW_PROMETHEUS_FETCHER_INTERVAL:PT1M}

五、Satellite —— 边缘数据收集网关

5.1 Satellite解决什么问题

+------------------------------------------------------------------+
+          Satellite的架构定位                                        +
+------------------------------------------------------------------+
|                                                                    |
|  问题:                                                             |
|                                                                    |
|  多云/多集群环境:                                                   |
|  ┌─────────────┐   ┌─────────────┐   ┌─────────────┐              │
|  │   Cluster A │   │   Cluster B │   │   Cluster C │              │
|  │  (AWS)      │   │  (阿里云)   │   │  (自建机房)  │              │
|  │ ┌─────────┐ │   │ ┌─────────┐ │   │ ┌─────────┐ │              │
|  │ │  Agent  │ │   │ │  Agent  │ │   │ │  Agent  │ │              │
|  │ │  Agent  │ │   │ │  Agent  │ │   │ │  Agent  │ │              │
|  │ └────┬────┘ │   │ └────┬────┘ │   │ └────┬────┘ │              │
|  └──────┼──────┘   └──────┼──────┘   └──────┼──────┘              │
|         │                  │                  │                     │
|         │  跨公网上报?    │  跨公网上报?    │                     │
|         │  → 延迟高       │  → 带宽贵        │                     │
|         │  → 不可靠       │  → 不稳定        │                     │
|         │                  │                  │                     │
|         └──────────────────┼──────────────────┘                     │
|                            │                                        │
|                            ↓                                        │
|                    ┌──────────────┐                                 │
|                    │ OAP Cluster  │                                 │
|                    └──────────────┘                                 │
|                                                                    |
|  解决方案: 在每个集群部署Satellite                                  |
|                                                                    |
|  ┌─────────────┐   ┌─────────────┐   ┌─────────────┐              │
|  │   Cluster A │   │   Cluster B │   │   Cluster C │              │
|  │   ┌───────┐ │   │   ┌───────┐ │   │   ┌───────┐ │              │
|  │   │Satellite│ │   │Satellite│ │   │Satellite│ │              │
|  │   │         │ │   │         │ │   │         │ │              │
|  │   │ 缓冲    │ │   │ 聚合    │ │   │ 过滤    │ │              │
|  │   │ 压缩    │ │   │ 加密    │ │   │ 路由    │ │              │
|  │   └───┬───┘ │   │   └───┬───┘ │   │   └───┬───┘ │              │
|  └───────┼──────┘   └───────┼──────┘   └───────┼──────┘              │
|          │                   │                   │                    │
|          └───────────────────┼───────────────────┘                    │
|                              │                                        │
|                              ↓                                        │
|                      ┌──────────────┐                                │
|                      │ OAP Cluster  │                                │
|                      └──────────────┘                                │
|                                                                    |
+------------------------------------------------------------------+

5.2 Satellite配置示例

# satellite-config.yaml
satellite:
  # Satellite自身配置
  name: satellite-cluster-a
  namespace: production
  
  # 管道配置
  pipes:
    # 输入管道:接收Agent数据
    - name: grpc-input
      type: grpc-receiver
      config:
        host: 0.0.0.0
        port: 11800
    
    # 处理管道:数据预处理
    - name: preprocessor
      type: processor
      config:
        # 采样(在边缘做,减少传输量)
        sampling:
          rate: 0.1  # 只保留10%
        
        # 压缩
        compression: gzip
        
        # 过滤(排除不需要的指标)
        filters:
          - type: exclude
            metrics:
              - jvm_thread_live_count
              - instance_heatmap
    
    # 输出管道:上报到OAP
    - name: grpc-output
      type: grpc-sender
      config:
        target: oap-central.example.com:11800
        tls:
          enabled: true
          cert: /certs/client.crt
          key: /certs/client.key
        retry:
          max_retries: 3
          backoff: 5s
        
        # 缓冲区(OAP不可达时暂存)
        buffer:
          type: disk
          path: /data/satellite/buffer
          max_size: 10GB

六、8.x版本升级注意事项

# ==========================================
# 升级检查清单
# ==========================================

# 1. 存储兼容性
# - 7.x → 8.x: 需要重建ES索引(数据结构有变化)
# - 建议:升级时使用新的ES集群

# 2. Agent兼容性
# - 8.x OAP兼容7.x Agent(向后兼容)
# - 但建议同时升级Agent以获得新特性

# 3. 配置变更
# - OAL语法有调整(MAL部分)
# - UI配置路径有变更

# 4. 数据迁移
# 7.x 数据不能直接迁移到 8.x
# 建议:保留7.x环境一段时间,8.x新集群并行运行

# 5. 推荐升级路径
# 7.x → 8.1.0 → 8.5.0 → 8.9.0 → 9.x
# (逐步升级,避免跨大版本)

七、总结

SkyWalking 8.x是SkyWalking演进中的关键里程碑:

新特性 解决的问题 适用场景
浏览器监控 前端不可见 Web应用
eBPF探针 非Java应用监控 多语言/遗留系统
MAL 非Trace指标处理 Prometheus集成
Satellite 多云/边缘数据收集 大规模/跨云部署

下一篇【第72篇】SkyWalking指标基线与异常检测——超越静态阈值告警的智能监控
上一篇【第74篇】SkyWalking 9.x新特性——K8s原生集成、Continuous Profiling与Layer概念


Logo

openEuler 是由开放原子开源基金会孵化的全场景开源操作系统项目,面向数字基础设施四大核心场景(服务器、云计算、边缘计算、嵌入式),全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构

更多推荐