Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未指定获取目标主机_Java_Http_Prometheus_Grafana - Fatal编程技术网

Java 未指定获取目标主机

Java 未指定获取目标主机,java,http,prometheus,grafana,Java,Http,Prometheus,Grafana,我通过Grafana调用prometheus服务器,我可以使用postman发出以下请求,但当我尝试相同的uri时,java代码出现以下异常 原因:org.apache.http.ProtocolException:未指定目标主机 位于org.apache.http.impl.conn.DefaultRoutePlanner.determineRoute(DefaultRoutePlanner.java:71) 位于org.apache.http.impl.client.InternalHttp

我通过Grafana调用prometheus服务器,我可以使用postman发出以下请求,但当我尝试相同的uri时,java代码出现以下异常

原因:org.apache.http.ProtocolException:未指定目标主机 位于org.apache.http.impl.conn.DefaultRoutePlanner.determineRoute(DefaultRoutePlanner.java:71) 位于org.apache.http.impl.client.InternalHttpClient.determineRoute(InternalHttpClient.java:125) 位于org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ... 省略31个公共框架

我的代码如下所示

CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    String PM_UI_SERVER_URI = "http://" + PM_SERVER_HOST + ":" + getPMUiServerPort();
    String uriStr= PM_UI_SERVER_URI + PM_SERVER_BASE_URI + queryString +"&start="+String.valueOf(startTime)+"&end="+String.valueOf(endTime)+"&step=150";
    //logger.info("Execute Query uri string: "+uriStr);
    String str="http://10.61.244.58:31000/api/datasources/proxy/1/api/v1/query_range?query=em_core_used_heap_mem_mb{job=\"eric-em-om-server\"}&start=1592981880&end=1592982180&step=15";
    String encodedurl = URLEncoder.encode(str,"UTF-8");
    //URI uri = new URI(encodedurl);
    //HttpGet httpget = new HttpGet("http://10.61.244.58:31000/api/datasources/1");
    HttpGet httpget = new HttpGet(encodedurl);
    httpget.addHeader("Authorization", token);
    httpget.addHeader("Content-Type", "application/json");
    CloseableHttpResponse response = httpClient.execute(httpget);

有人能帮我一下吗,因为我在这里被绊住了。

试着一块一块地构建URL,而不是直接获取完整的URL。您可以使用intelliJ IDE中的表达式生成器在调试会话中执行此操作

  • …=httpClient.execute(httpget)
    并通过在调试模式下测试/运行应用程序来练习此代码
  • 突出显示httpClient.execute(httpget)
  • 右键单击此选择并单击“表达式生成器”,或使用
    Alt
    +
    F8
  • 现在尝试执行
    http://10.61.244.58:31000/
  • 确保您获得200响应状态或同等状态
  • 接下来,您应该能够添加下一位,如
    http://10.61.244.58:31000/api/datasources/proxy/1/api/v1/query_range
    (注意,我也会尝试不使用
    代理,因为URL可能有问题,因为您的请求是根据此处的文档进行代理的:

  • 我会尝试分别添加查询参数和组合查询参数。这不一定能解决您的问题……但如果您能同时跟踪grafana服务器/代理服务器上的任何日志,您可能会得到一些更详细的信息,这将有助于引导您的调查。

    logger.info的输出是什么(“执行查询uri字符串:”+uriStr);
    (注释掉行)。假设其正确,您是否能够从运行此代码的框中
    ping
    主机?是@robvans,我能够ping。如果您可以ping主机,则问题在于url,而不是与主机通信的问题。测试
    telnet 10.61.244.58 31000
    是否有效?