问题现象:
Loki导入数据源后日志实时展示出现“Live tailing was stopped due to following error: undefined”
原因:
默认情况下,并非所有代理都可以透明地代理 WebSocket 连接。例如,如果你在Grafana之前使用Nginx,你需要配置WebSocket代理
Not all proxies can transparently proxy WebSocket connections by default. For example, if you are using Nginx before Grafana you need to configure WebSocket proxy(官网原文 https://grafana.com/docs/grafana/latest/setup-grafana/set-up-grafana-live/)
解决方法一:
根据官网说明在nginx上添加
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
client_max_body_size 50m;
server_name localhost;
location ~ /grafana/ {
#设置主机头和客户端真实地址,以便服务器获取客户端真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 添加这部分,以及上面的map
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
#反向代理的地址
proxy_pass http://localhost:3000;
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
proxy_redirect off;
}
}
解决方法二:
若是方法一不生效或是其它原因导致问题仍然存在,可通过在grafana的DataSource上添加header进行处理。
原文地址:https://bytemeta.vip/repo/grafana/loki/issues/7153
添加值为:
Connection: Upgrade
Upgrade: websocket
总结
方法一与方法二两者二选一即可,不确定两者同时存在是否有其它影响。