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
44
45
|
// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metricsproxy.service;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ExecutionException;
/**
* 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 (InputStream stream = getJson()) {
createMetrics(stream, consumer, fetchCount);
} catch (IOException | InterruptedException | ExecutionException e) {
}
}
void createMetrics(String data, MetricsParser.Consumer consumer, int fetchCount) {
try {
MetricsParser.parse(data, consumer);
} catch (Exception e) {
handleException(e, data, fetchCount);
}
}
private void createMetrics(InputStream data, MetricsParser.Consumer consumer, int fetchCount) {
try {
MetricsParser.parse(data, consumer);
} catch (Exception e) {
handleException(e, data, fetchCount);
}
}
}
|