.net - 连接到 Grafana 时出现错误 502
问题描述
我使用SimpleJson 插件进行连接。但我收到错误 502(照片)
我在启动文件中添加了 CORS:
app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
我为 GET (/) 和 POSTS (/query, /annotations, /search) 创建端点,如GitHub docs中的文档所述:
using System.Net.Http;
using System.Text;
using Microsoft.AspNetCore.Mvc;
namespace Grafana
{
[ApiController]
public class BugsMonitoringController : ControllerBase
{
[HttpGet]
[Route("/")]
public void Empty()
{
}
[HttpPost]
[Route("query")]
public HttpResponseMessage Query()
{
return new HttpResponseMessage()
{
Content = new StringContent("[{\"columns\":[{\"text\":\"Time\",\"type\":\"time\"},{\"text\":\"Country\",\"type\":\"string\"},{\"text\":\"Number\",\"type\":\"number\"}],\"rows\":[[1234567,\"SE\",182],[1234567,\"DE\",282],[1234567,\"US\",382]],\"type\":\"table\"}]", Encoding.UTF8, "application/json")
};
}
[HttpPost]
[Route("search")]
public HttpResponseMessage Search()
{
return new HttpResponseMessage()
{
Content = new StringContent("[ { \"text\" :\"upper_25\", \"value\": 1}, { \"text\" :\"upper_75\", \"value\": 2} ]", Encoding.UTF8, "application/json")
};
}
[HttpPost]
[Route("annotations")]
public HttpResponseMessage Annotation()
{
return new HttpResponseMessage()
{
Content = new StringContent("[{\"text\":\"text shown in body\",\"title\":\"Annotation Title\",\"isRegion\":true,\"time\":\"timestamp\",\"timeEnd\":\"timestamp\",\"tags\":[\"tag1\"]}]", Encoding.UTF8, "application/json")
};
}
}
数据源中指定的服务器地址 ( PHOTO )
解决方案
我解决了这个问题当我在 JSON 插件中编写 URL 时,我使用了 localhost:5000。需要使用您的本地地址,例如:192.168.1.10。并在 launchSettings.json 中更改“applicationUrl”
推荐阅读
- android - 我正在使用带有 WebView 的 LinearProgressIndicator 来显示网页渲染进度,当进度动画达到 100 时如何隐藏它?
- asp.net - 将生成的位图图像保存为磁盘中的 jpg/png 图像
- c - OpenMP并行的两种方法之间的区别
- google-cloud-shell - .customize_environment 之前在云外壳中工作的 apt-get update 失败
- postgresql - 窗口函数上的Postgresql数值精度错误
- animation - SwiftUI 循环动画
- c# - Kotlin 中是否有相当于 C# 的 DebuggerStepThrough 的功能?
- python - 使用 python 脚本和 csv 文件更新数据库
- javascript - Cheerio 在嵌套表中查找所有链接
- spring - 将值传递给函数而不直接作为参数传递的好方法