Search in sources :

Example 1 with DimensionMetrics

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);
}
Also used : ArrayList(java.util.ArrayList) Dimensions(com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions) DimensionMetrics(com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics) Docker(com.yahoo.vespa.hosted.dockerapi.Docker) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec)

Example 2 with DimensionMetrics

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);
}
Also used : DimensionMetrics(com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics) PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) HttpResponse(com.yahoo.container.jdisc.HttpResponse)

Example 3 with DimensionMetrics

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);
    }
}
Also used : DimensionMetrics(com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics) DockerExecTimeoutException(com.yahoo.vespa.hosted.dockerapi.DockerExecTimeoutException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

DimensionMetrics (com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HttpResponse (com.yahoo.container.jdisc.HttpResponse)1 Docker (com.yahoo.vespa.hosted.dockerapi.Docker)1 DockerExecTimeoutException (com.yahoo.vespa.hosted.dockerapi.DockerExecTimeoutException)1 Dimensions (com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions)1 ContainerNodeSpec (com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1