use of com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics in project vespa by vespa-engine.
the class NodeAgentImpl method updateContainerNodeMetrics.
@SuppressWarnings("unchecked")
public void updateContainerNodeMetrics() {
final ContainerNodeSpec nodeSpec = lastNodeSpec;
if (nodeSpec == null || containerState != UNKNOWN)
return;
Optional<Docker.ContainerStats> containerStats = dockerOperations.getContainerStats(containerName);
if (!containerStats.isPresent())
return;
Dimensions.Builder dimensionsBuilder = new Dimensions.Builder().add("host", hostname).add("role", "tenants").add("state", nodeSpec.nodeState.toString()).add("parentHostname", environment.getParentHostHostname());
nodeSpec.allowedToBeDown.ifPresent(allowed -> dimensionsBuilder.add("orchestratorState", allowed ? "ALLOWED_TO_BE_DOWN" : "NO_REMARKS"));
Dimensions dimensions = dimensionsBuilder.build();
Docker.ContainerStats stats = containerStats.get();
final String APP = MetricReceiverWrapper.APPLICATION_NODE;
final int totalNumCpuCores = ((List<Number>) ((Map) stats.getCpuStats().get("cpu_usage")).get("percpu_usage")).size();
final long cpuContainerKernelTime = ((Number) ((Map) stats.getCpuStats().get("cpu_usage")).get("usage_in_kernelmode")).longValue();
final long cpuContainerTotalTime = ((Number) ((Map) stats.getCpuStats().get("cpu_usage")).get("total_usage")).longValue();
final long cpuSystemTotalTime = ((Number) stats.getCpuStats().get("system_cpu_usage")).longValue();
final long memoryTotalBytes = ((Number) stats.getMemoryStats().get("limit")).longValue();
final long memoryTotalBytesUsage = ((Number) stats.getMemoryStats().get("usage")).longValue();
final long memoryTotalBytesCache = ((Number) ((Map) stats.getMemoryStats().get("stats")).get("cache")).longValue();
final long diskTotalBytes = (long) (nodeSpec.minDiskAvailableGb * BYTES_IN_GB);
final Optional<Long> diskTotalBytesUsed = storageMaintainer.getDiskUsageFor(containerName);
lastCpuMetric.updateCpuDeltas(cpuSystemTotalTime, cpuContainerTotalTime, cpuContainerKernelTime);
// Ratio of CPU cores allocated to this container to total number of CPU cores on this host
final double allocatedCpuRatio = nodeSpec.minCpuCores / totalNumCpuCores;
double cpuUsageRatioOfAllocated = lastCpuMetric.getCpuUsageRatio() / allocatedCpuRatio;
double cpuKernelUsageRatioOfAllocated = lastCpuMetric.getCpuKernelUsageRatio() / allocatedCpuRatio;
long memoryTotalBytesUsed = memoryTotalBytesUsage - memoryTotalBytesCache;
double memoryUsageRatio = (double) memoryTotalBytesUsed / memoryTotalBytes;
Optional<Double> diskUsageRatio = diskTotalBytesUsed.map(used -> (double) used / diskTotalBytes);
List<DimensionMetrics> metrics = new ArrayList<>();
DimensionMetrics.Builder systemMetricsBuilder = new DimensionMetrics.Builder(APP, dimensions).withMetric("mem.limit", memoryTotalBytes).withMetric("mem.used", memoryTotalBytesUsed).withMetric("mem.util", 100 * memoryUsageRatio).withMetric("cpu.util", 100 * cpuUsageRatioOfAllocated).withMetric("cpu.sys.util", 100 * cpuKernelUsageRatioOfAllocated).withMetric("disk.limit", diskTotalBytes);
diskTotalBytesUsed.ifPresent(diskUsed -> systemMetricsBuilder.withMetric("disk.used", diskUsed));
diskUsageRatio.ifPresent(diskRatio -> systemMetricsBuilder.withMetric("disk.util", 100 * diskRatio));
metrics.add(systemMetricsBuilder.build());
stats.getNetworks().forEach((interfaceName, interfaceStats) -> {
Dimensions netDims = dimensionsBuilder.add("interface", interfaceName).build();
Map<String, Number> infStats = (Map<String, Number>) interfaceStats;
DimensionMetrics networkMetrics = new DimensionMetrics.Builder(APP, netDims).withMetric("net.in.bytes", infStats.get("rx_bytes").longValue()).withMetric("net.in.errors", infStats.get("rx_errors").longValue()).withMetric("net.in.dropped", infStats.get("rx_dropped").longValue()).withMetric("net.out.bytes", infStats.get("tx_bytes").longValue()).withMetric("net.out.errors", infStats.get("tx_errors").longValue()).withMetric("net.out.dropped", infStats.get("tx_dropped").longValue()).build();
metrics.add(networkMetrics);
});
pushMetricsToContainer(metrics);
}
use of com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics in project vespa by vespa-engine.
the class RestApiHandler method handleGet.
private HttpResponse handleGet(HttpRequest request) {
String path = request.getUri().getPath();
if (path.endsWith("/info")) {
return new SimpleObjectResponse(200, refresher.getDebugPage());
}
if (path.endsWith("/metrics")) {
return new HttpResponse(200) {
@Override
public String getContentType() {
return MediaType.APPLICATION_JSON;
}
@Override
public void render(OutputStream outputStream) throws IOException {
try (PrintStream printStream = new PrintStream(outputStream)) {
for (DimensionMetrics dimensionMetrics : metricReceiverWrapper.getAllMetrics()) {
String secretAgentJsonReport = dimensionMetrics.toSecretAgentReport() + "\n";
printStream.write(secretAgentJsonReport.getBytes(StandardCharsets.UTF_8.name()));
}
}
}
};
}
return new SimpleResponse(400, "unknown path " + path);
}
use of com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics in project vespa by vespa-engine.
the class NodeAgentImpl method pushMetricsToContainer.
private void pushMetricsToContainer(List<DimensionMetrics> metrics) {
StringBuilder params = new StringBuilder();
try {
for (DimensionMetrics dimensionMetrics : metrics) {
params.append(dimensionMetrics.toSecretAgentReport());
}
String wrappedMetrics = "s:" + params.toString();
// Push metrics to the metrics proxy in each container - give it maximum 1 seconds to complete
String[] command = { "vespa-rpc-invoke", "-t", "2", "tcp/localhost:19091", "setExtraMetrics", wrappedMetrics };
dockerOperations.executeCommandInContainerAsRoot(containerName, 5L, command);
} catch (DockerExecTimeoutException | JsonProcessingException e) {
logger.warning("Unable to push metrics to container: " + containerName, e);
}
}
Aggregations