Search in sources :

Example 46 with Counter

use of com.codahale.metrics.Counter in project camel by apache.

the class CounterProducer method doProcess.

@Override
protected void doProcess(Exchange exchange, MetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
    Message in = exchange.getIn();
    Counter counter = registry.counter(metricsName);
    Long increment = endpoint.getIncrement();
    Long decrement = endpoint.getDecrement();
    Long finalIncrement = getLongHeader(in, HEADER_COUNTER_INCREMENT, increment);
    Long finalDecrement = getLongHeader(in, HEADER_COUNTER_DECREMENT, decrement);
    if (finalIncrement != null) {
        counter.inc(finalIncrement);
    } else if (finalDecrement != null) {
        counter.dec(finalDecrement);
    } else {
        counter.inc();
    }
}
Also used : Counter(com.codahale.metrics.Counter) Message(org.apache.camel.Message)

Example 47 with Counter

use of com.codahale.metrics.Counter in project hadoop by apache.

the class ResourceSchedulerWrapper method updateQueueWithAllocateRequest.

private void updateQueueWithAllocateRequest(Allocation allocation, ApplicationAttemptId attemptId, List<ResourceRequest> resourceRequests, List<ContainerId> containerIds) throws IOException {
    // update queue information
    Resource pendingResource = Resources.createResource(0, 0);
    Resource allocatedResource = Resources.createResource(0, 0);
    String queueName = appQueueMap.get(attemptId.getApplicationId());
    // container requested
    for (ResourceRequest request : resourceRequests) {
        if (request.getResourceName().equals(ResourceRequest.ANY)) {
            Resources.addTo(pendingResource, Resources.multiply(request.getCapability(), request.getNumContainers()));
        }
    }
    // container allocated
    for (Container container : allocation.getContainers()) {
        Resources.addTo(allocatedResource, container.getResource());
        Resources.subtractFrom(pendingResource, container.getResource());
    }
    // container released from AM
    SchedulerAppReport report = scheduler.getSchedulerAppInfo(attemptId);
    for (ContainerId containerId : containerIds) {
        Container container = null;
        for (RMContainer c : report.getLiveContainers()) {
            if (c.getContainerId().equals(containerId)) {
                container = c.getContainer();
                break;
            }
        }
        if (container != null) {
            // released allocated containers
            Resources.subtractFrom(allocatedResource, container.getResource());
        } else {
            for (RMContainer c : report.getReservedContainers()) {
                if (c.getContainerId().equals(containerId)) {
                    container = c.getContainer();
                    break;
                }
            }
            if (container != null) {
                // released reserved containers
                Resources.subtractFrom(pendingResource, container.getResource());
            }
        }
    }
    // containers released/preemption from scheduler
    Set<ContainerId> preemptionContainers = new HashSet<ContainerId>();
    if (allocation.getContainerPreemptions() != null) {
        preemptionContainers.addAll(allocation.getContainerPreemptions());
    }
    if (allocation.getStrictContainerPreemptions() != null) {
        preemptionContainers.addAll(allocation.getStrictContainerPreemptions());
    }
    if (!preemptionContainers.isEmpty()) {
        for (ContainerId containerId : preemptionContainers) {
            if (!preemptionContainerMap.containsKey(containerId)) {
                Container container = null;
                for (RMContainer c : report.getLiveContainers()) {
                    if (c.getContainerId().equals(containerId)) {
                        container = c.getContainer();
                        break;
                    }
                }
                if (container != null) {
                    preemptionContainerMap.put(containerId, container.getResource());
                }
            }
        }
    }
    // update metrics
    SortedMap<String, Counter> counterMap = metrics.getCounters();
    String[] names = new String[] { "counter.queue." + queueName + ".pending.memory", "counter.queue." + queueName + ".pending.cores", "counter.queue." + queueName + ".allocated.memory", "counter.queue." + queueName + ".allocated.cores" };
    long[] values = new long[] { pendingResource.getMemorySize(), pendingResource.getVirtualCores(), allocatedResource.getMemorySize(), allocatedResource.getVirtualCores() };
    for (int i = names.length - 1; i >= 0; i--) {
        if (!counterMap.containsKey(names[i])) {
            metrics.counter(names[i]);
            counterMap = metrics.getCounters();
        }
        counterMap.get(names[i]).inc(values[i]);
    }
    queueLock.lock();
    try {
        if (!schedulerMetrics.isTracked(queueName)) {
            schedulerMetrics.trackQueue(queueName);
        }
    } finally {
        queueLock.unlock();
    }
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) Container(org.apache.hadoop.yarn.api.records.Container) Counter(com.codahale.metrics.Counter) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest) SchedulerAppReport(org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerAppReport) HashSet(java.util.HashSet)

Example 48 with Counter

use of com.codahale.metrics.Counter in project hadoop by apache.

the class SLSCapacityScheduler method initQueueMetrics.

private void initQueueMetrics(CSQueue queue) {
    if (queue instanceof LeafQueue) {
        SortedMap<String, Counter> counterMap = metrics.getCounters();
        String queueName = queue.getQueueName();
        String[] names = new String[] { QUEUE_COUNTER_PREFIX + queueName + ".pending.memory", QUEUE_COUNTER_PREFIX + queueName + ".pending.cores", QUEUE_COUNTER_PREFIX + queueName + ".allocated.memory", QUEUE_COUNTER_PREFIX + queueName + ".allocated.cores" };
        for (int i = names.length - 1; i >= 0; i--) {
            if (!counterMap.containsKey(names[i])) {
                metrics.counter(names[i]);
                counterMap = metrics.getCounters();
            }
        }
        queueLock.lock();
        try {
            if (!schedulerMetrics.isTracked(queueName)) {
                schedulerMetrics.trackQueue(queueName);
            }
        } finally {
            queueLock.unlock();
        }
        return;
    }
    for (CSQueue child : queue.getChildQueues()) {
        initQueueMetrics(child);
    }
}
Also used : Counter(com.codahale.metrics.Counter) LeafQueue(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.LeafQueue) CSQueue(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CSQueue)

Example 49 with Counter

use of com.codahale.metrics.Counter in project hadoop by apache.

the class SLSCapacityScheduler method updateQueueWithAllocateRequest.

private void updateQueueWithAllocateRequest(Allocation allocation, ApplicationAttemptId attemptId, List<ResourceRequest> resourceRequests, List<ContainerId> containerIds) throws IOException {
    // update queue information
    Resource pendingResource = Resources.createResource(0, 0);
    Resource allocatedResource = Resources.createResource(0, 0);
    String queueName = appQueueMap.get(attemptId);
    // container requested
    for (ResourceRequest request : resourceRequests) {
        if (request.getResourceName().equals(ResourceRequest.ANY)) {
            Resources.addTo(pendingResource, Resources.multiply(request.getCapability(), request.getNumContainers()));
        }
    }
    // container allocated
    for (Container container : allocation.getContainers()) {
        Resources.addTo(allocatedResource, container.getResource());
        Resources.subtractFrom(pendingResource, container.getResource());
    }
    // container released from AM
    SchedulerAppReport report = super.getSchedulerAppInfo(attemptId);
    for (ContainerId containerId : containerIds) {
        Container container = null;
        for (RMContainer c : report.getLiveContainers()) {
            if (c.getContainerId().equals(containerId)) {
                container = c.getContainer();
                break;
            }
        }
        if (container != null) {
            // released allocated containers
            Resources.subtractFrom(allocatedResource, container.getResource());
        } else {
            for (RMContainer c : report.getReservedContainers()) {
                if (c.getContainerId().equals(containerId)) {
                    container = c.getContainer();
                    break;
                }
            }
            if (container != null) {
                // released reserved containers
                Resources.subtractFrom(pendingResource, container.getResource());
            }
        }
    }
    // containers released/preemption from scheduler
    Set<ContainerId> preemptionContainers = new HashSet<ContainerId>();
    if (allocation.getContainerPreemptions() != null) {
        preemptionContainers.addAll(allocation.getContainerPreemptions());
    }
    if (allocation.getStrictContainerPreemptions() != null) {
        preemptionContainers.addAll(allocation.getStrictContainerPreemptions());
    }
    if (!preemptionContainers.isEmpty()) {
        for (ContainerId containerId : preemptionContainers) {
            if (!preemptionContainerMap.containsKey(containerId)) {
                Container container = null;
                for (RMContainer c : report.getLiveContainers()) {
                    if (c.getContainerId().equals(containerId)) {
                        container = c.getContainer();
                        break;
                    }
                }
                if (container != null) {
                    preemptionContainerMap.put(containerId, container.getResource());
                }
            }
        }
    }
    // update metrics
    SortedMap<String, Counter> counterMap = metrics.getCounters();
    String[] names = new String[] { "counter.queue." + queueName + ".pending.memory", "counter.queue." + queueName + ".pending.cores", "counter.queue." + queueName + ".allocated.memory", "counter.queue." + queueName + ".allocated.cores" };
    long[] values = new long[] { pendingResource.getMemorySize(), pendingResource.getVirtualCores(), allocatedResource.getMemorySize(), allocatedResource.getVirtualCores() };
    for (int i = names.length - 1; i >= 0; i--) {
        if (!counterMap.containsKey(names[i])) {
            metrics.counter(names[i]);
            counterMap = metrics.getCounters();
        }
        counterMap.get(names[i]).inc(values[i]);
    }
    queueLock.lock();
    try {
        if (!schedulerMetrics.isTracked(queueName)) {
            schedulerMetrics.trackQueue(queueName);
        }
    } finally {
        queueLock.unlock();
    }
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) Container(org.apache.hadoop.yarn.api.records.Container) Counter(com.codahale.metrics.Counter) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest) SchedulerAppReport(org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerAppReport) HashSet(java.util.HashSet)

Example 50 with Counter

use of com.codahale.metrics.Counter in project oxCore by GluuFederation.

the class MetricService method incCounter.

public void incCounter(MetricType metricType) {
    Counter counter = getCounter(metricType);
    counter.inc();
}
Also used : Counter(com.codahale.metrics.Counter)

Aggregations

Counter (com.codahale.metrics.Counter)66 Test (org.junit.Test)31 Map (java.util.Map)15 MetricRegistry (com.codahale.metrics.MetricRegistry)14 Timer (com.codahale.metrics.Timer)14 Histogram (com.codahale.metrics.Histogram)11 HashMap (java.util.HashMap)11 Gauge (com.codahale.metrics.Gauge)10 Meter (com.codahale.metrics.Meter)9 Metric (com.codahale.metrics.Metric)9 Random (java.util.Random)8 SolrInfoBean (org.apache.solr.core.SolrInfoBean)6 SortedMap (java.util.SortedMap)5 IOException (java.io.IOException)4 TreeMap (java.util.TreeMap)4 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)4 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)4 Description (com.google.gerrit.metrics.Description)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3