Search in sources :

Example 1 with Dimensions

use of com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions 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 Dimensions

use of com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions in project vespa by vespa-engine.

the class DockerImpl method setMetrics.

void setMetrics(MetricReceiverWrapper metricReceiver) {
    Dimensions dimensions = new Dimensions.Builder().add("role", "docker").build();
    numberOfDockerDaemonFails = metricReceiver.declareCounter(MetricReceiverWrapper.APPLICATION_DOCKER, dimensions, "daemon.api_fails");
}
Also used : Dimensions(com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions)

Aggregations

Dimensions (com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions)2 Docker (com.yahoo.vespa.hosted.dockerapi.Docker)1 DimensionMetrics (com.yahoo.vespa.hosted.dockerapi.metrics.DimensionMetrics)1 ContainerNodeSpec (com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec)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