打开浏览器的开发者工具,网络处可以看到 grafana 的 /api/live/ws 的状态是 finished
展开看请求体如下,甚至没有请求方法类型,也没有状态码
继续看grafana的日志。发现有以下内容
msg="Request Completed" method=GET path=/api/live/ws status=403
看到了状态码。那就是 grafana 拒绝了这个请求。要解决这个问题。我就看这行日志
logger=live t=2023-04-19T17:35:21.403497049+08:00 level=warn msg="Request Origin is not authorized" origin=http://www.youdomain.com:1480 host=www.youdomain.com appUrl=http://www.youdomain.com:3000/ allowedOrigins=
里面 allowedOrigins 为空,那么把 origin的值填写到 allowedOrigins 里面就好了。
打开 grafana的配置文件 grafana.ini 。修改里面的 live/allowed_origins
#################################### Grafana Live ##########################################
[live]
# max_connections to Grafana Live WebSocket endpoint per Grafana server instance. See Grafana Live docs
# if you are planning to make it higher than default 100 since this can require some OS and infrastructure
# tuning. 0 disables Live, -1 means unlimited connections.
;max_connections = 100
# allowed_origins is a comma-separated list of origins that can establish connection with Grafana Live.
# If not set then origin will be matched over root_url. Supports wildcard symbol "*".
;allowed_origins =
;最暴力的方式就是允许所有 origin 只需填 *
allowed_origins = "http://www.youdomain.com:1480"
保存后重启grafana。就好了。