首页 > 解决方案 > 连接到 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 )

标签: .netgrafana

解决方案


我解决了这个问题当我在 JSON 插件中编写 URL 时,我使用了 localhost:5000。需要使用您的本地地址,例如:192.168.1.10。并在 launchSettings.json 中更改“applicationUrl”


推荐阅读