blob: cd05945f4f15b18177ea7caa0e8041a91863db78 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metricsproxy.service;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import java.io.BufferedInputStream;
import java.io.IOException;
/**
* Fetch metrics for a given vespa service
*
* @author Jo Kristian Bergum
*/
public class RemoteMetricsFetcher extends HttpMetricFetcher {
final static String METRICS_PATH = STATE_PATH + "metrics";
RemoteMetricsFetcher(VespaService service, int port) {
super(service, port, METRICS_PATH);
}
/**
* Connect to remote service over http and fetch metrics
*/
public void getMetrics(MetricsParser.Consumer consumer, int fetchCount) {
try (CloseableHttpResponse response = getResponse()) {
HttpEntity entity = response.getEntity();
try {
MetricsParser.parse(new BufferedInputStream(entity.getContent(), HttpMetricFetcher.BUFFER_SIZE), consumer);
} catch (Exception e) {
handleException(e, entity.getContentType(), fetchCount);
} finally {
EntityUtils.consumeQuietly(entity);
}
} catch (IOException ignored) {}
}
void createMetrics(String data, MetricsParser.Consumer consumer, int fetchCount) throws IOException {
MetricsParser.parse(data, consumer);
}
}
|