SkyWalking 前端监控

配置

引入依赖

yaml 复制代码
pnpm install skywalking-client-js --save

创建skywalking.js

yaml 复制代码
import ClientMonitor from 'skywalking-client-js';

let initialized = false;

/**
 * 初始化 SkyWalking 前端性能监控
 *
 */
export function setupSkyWalking() {
  if (typeof window === 'undefined' || initialized) {
    return;
  }

  ClientMonitor.register({
    // 采集服务地址
    collector: 'http://ip:12800', //修改为skywalking oap的ip
    // 服务名称
    service: '服务名称',
    // 服务版本
    serviceVersion: '1.0.0',
    pagePath: window.location.href, // 加上页面路径

    // 错误追踪
    jsErrors: true,
    apiErrors: true,
    resourceErrors: true,
    vue: true,

    // 性能追踪
    autoTracePerf: true,
    useFmp: true,
    enableSPA: true,

    // 网络追踪
    traceSDKInternal: false,
    detailMode: false,
    noTraceOrigins: [],
    traceTimeInterval: 60000,
  });

  initialized = true;
}

main.js

yaml 复制代码
  // 初始化 SkyWalking 前端性能监控
  setupSkyWalking();

验证

访问页面触发几个接口后等待一分钟,可以看到请求skywalking的请求。

在skywalking ui中找到对应服务的trace 根据traceId可以查到对应的链路。

SkyWalking-oap在内网的情况

oap在内网,用户访问业务系统无法直接发送trace到oap,需要通过nginx转发。 0. 修改地址

arduino 复制代码
collector: '<http://127.0.0.1:12800>',改为 http://域名/skywalking
  1. 修改nginx.conf配置,在对应域名的server模块下添加
bash 复制代码
        location /skywalking/ {
        ##内网下skywalking-oap服务的ip
            proxy_pass http://ip:12800/; 
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
​
            # 允许大一点的请求体
            client_max_body_size 10m;
       }
    
  1. 重启nginx
相关推荐
苏渡苇10 小时前
Spring Insight 里如何把 Span 画成瀑布时间线
后端·spring·spring cloud·springboot·监控·apm
行百里er14 小时前
轻量级 Spring 监测工具——Spring Insight 发布了
spring boot·后端·监控
宋均浩2 天前
告警规则 243 砍到 27:Prometheus 降噪实战,日均打扰 47 次 → 3 次
云原生·监控·devops
小小ken2 天前
水星摄像头(MIPC552W)双摄版和乔安摄像头(JA-A12,JA-w1)接入easynvr具体步骤
监控·摄像头·nvr·easynvr·水星·乔安
行百里er3 天前
Spring Insight 里如何把 Span 画成瀑布时间线
spring boot·后端·监控
行百里er3 天前
Spring Insight 里如何把 Span 收成一条链路
spring boot·spring cloud·监控
北京盛世宏博5 天前
老旧档案库房环境恒温恒湿自动化改造:不破坏原有库房结构的轻量化集成方案
监控·档案温湿度
行百里er5 天前
Spring Insight 里如何画出服务拓扑
spring boot·spring cloud·监控
行百里er7 天前
Spring Insight 里如何对 Span 进行清洗
spring boot·spring cloud·监控
盛世宏博智慧档案7 天前
户外配电柜为什么要装POE供电以太网温湿度传感器?
服务器·网络·人工智能·监控·温湿度·配电柜