blob: 88971433a0116c9f33dafad43b9bf11d611eed8e (
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
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.http.v2;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.slime.Cursor;
import com.yahoo.slime.JsonFormat;
import com.yahoo.slime.Slime;
import com.yahoo.vespa.config.server.http.HttpConfigResponse;
import com.yahoo.vespa.config.server.metrics.ClusterInfo;
import com.yahoo.vespa.config.server.metrics.MetricsAggregator;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
/**
* @author olaa
*/
public class MetricsResponse extends HttpResponse {
private final Slime slime = new Slime();
public MetricsResponse(int status, ApplicationId applicationId, Map<ClusterInfo, MetricsAggregator> aggregatedMetrics) {
super(status);
Cursor application = slime.setObject();
application.setString("applicationId", applicationId.serializedForm());
Cursor clusters = application.setArray("clusters");
for (var entry : aggregatedMetrics.entrySet()) {
Cursor cluster = clusters.addObject();
cluster.setString("clusterId", entry.getKey().getClusterId());
cluster.setString("clusterType", entry.getKey().getClusterType().name());
MetricsAggregator aggregator = entry.getValue();
Cursor metrics = cluster.setObject("metrics");
aggregator.aggregateQueryRate().ifPresent(queryrate -> metrics.setDouble("queriesPerSecond", queryrate));
aggregator.aggregateFeedRate().ifPresent(feedRate -> metrics.setDouble("feedPerSecond", feedRate));
aggregator.aggregateDocumentCount().ifPresent(documentCount -> metrics.setDouble("documentCount", documentCount));
aggregator.aggregateQueryLatency().ifPresent(queryLatency -> metrics.setDouble("queryLatency",queryLatency));
aggregator.aggregateFeedLatency().ifPresent(feedLatency -> metrics.setDouble("feedLatency", feedLatency));
}
}
@Override
public void render(OutputStream outputStream) throws IOException {
new JsonFormat(false).encode(outputStream, slime);
}
@Override
public String getContentType() {
return HttpConfigResponse.JSON_CONTENT_TYPE;
}
}
|