[英]How to push Reactjs logs and metrics to Grafana
Background:背景:
I am working on a project where we have a server setup in Java and for front-end we are using ReactJs.我正在做一个项目,我们在 Java 中有一个服务器设置,对于前端,我们使用的是 ReactJs。 Our server ships all logs to Loki endpoint via their push API and all metrics to a prometheus push-gateway.
我们的服务器通过他们的推送 API 将所有日志发送到 Loki 端点,并将所有指标发送到 prometheus 推送网关。 Grafana then pulls those logs and metrics from Loki and push-gateway for display.
然后,Grafana 从 Loki 和推送网关中提取这些日志和指标进行显示。
Requirement:要求:
I want to persist and place the ReactJs application logs and metrics so they are visible on grafana .我想保留并放置ReactJs应用程序日志和指标,以便它们在grafana上可见。 This will help us see both frontend and backend application logs & metrics in the same place.
这将帮助我们在同一个地方查看前端和后端应用程序日志和指标。 Is there a free , opensource Javascript library or framework that can help me with that.
是否有免费的、开源的 Javascript 库或框架可以帮助我。 The less code I need to write the better.
我需要编写的代码越少越好。
I was opting for sentry before but it's not completely free anymore.我之前选择了哨兵,但它不再完全免费了。 And we cannot use console logging as it disappears on browser refresh and not really helpful in production
而且我们不能使用控制台日志,因为它会在浏览器刷新时消失,并且对生产没有帮助
So I didn't find a good library at that time but I was eventually able to ship logs to loki push endpoint.所以当时我没有找到一个好的库,但我最终能够将日志发送到 loki push 端点。
I tried to push logs directly from frontend to loki push endpoint.我尝试将日志直接从前端推送到 loki 推送端点。 This gave me a cors error.
这给了我一个 cors 错误。 So I came up with the following steps to get around cors with Loki.
所以我想出了以下步骤来绕过 cors 和 Loki。
My workaround:我的解决方法:
I took alot of reading and hit and trys but I got the setup working.我花了很多时间阅读和尝试,但我得到了设置工作。 We are now using this setup to push frontend logs to grafana
我们现在正在使用此设置将前端日志推送到 grafana
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.