blob: 729c2488e2b0a052d239b93334e4d7b0cf09e334 (
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
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.application.v4.model;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SearchNodeMetrics {
private static final ObjectMapper jsonMapper = new ObjectMapper();
private static final Logger logger = Logger.getLogger(SearchNodeMetrics.class.getName());
public static final String DOCUMENTS_ACTIVE_COUNT = "documentsActiveCount";
public static final String DOCUMENTS_READY_COUNT = "documentsReadyCount";
public static final String DOCUMENTS_TOTAL_COUNT = "documentsTotalCount";
public static final String DOCUMENT_DISK_USAGE = "documentDiskUsage";
public static final String RESOURCE_DISK_USAGE_AVERAGE = "resourceDiskUsageAverage";
public static final String RESOURCE_MEMORY_USAGE_AVERAGE = "resourceMemoryUsageAverage";
private final String clusterId;
private final Map<String, Double> metrics;
public SearchNodeMetrics(String clusterId) {
this.clusterId = clusterId;
metrics = new HashMap<>();
}
public String getClusterId() { return clusterId; }
public double documentsActiveCount() { return metrics.get(DOCUMENTS_ACTIVE_COUNT); }
public double documentsReadyCount() { return metrics.get(DOCUMENTS_READY_COUNT); }
public double documentsTotalCount() { return metrics.get(DOCUMENTS_TOTAL_COUNT); }
public double documentDiskUsage() { return metrics.get(DOCUMENT_DISK_USAGE); }
public double resourceDiskUsageAverage() { return metrics.get(RESOURCE_DISK_USAGE_AVERAGE); }
public double resourceMemoryUsageAverage() { return metrics.get(RESOURCE_MEMORY_USAGE_AVERAGE); }
public SearchNodeMetrics addMetric(String name, double value) {
metrics.put(name, value);
return this;
}
public JsonNode toJson() {
try {
ObjectNode protonMetrics = jsonMapper.createObjectNode();
protonMetrics.put("clusterId", clusterId);
ObjectNode jsonMetrics = jsonMapper.createObjectNode();
for (Map.Entry<String, Double> entry : metrics.entrySet()) {
jsonMetrics.put(entry.getKey(), entry.getValue());
}
protonMetrics.set("metrics", jsonMetrics);
return protonMetrics;
} catch (Exception e) {
logger.log(Level.SEVERE, "Unable to convert Proton Metrics to JSON Object: " + e.getMessage(), e);
}
return jsonMapper.createObjectNode();
}
}
|