Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.metrics.internal.cloudwatch;
 
 import static com.amazonaws.metrics.internal.cloudwatch.MachineMetric.DaemonThreadCount;
 import static com.amazonaws.metrics.internal.cloudwatch.MachineMetric.DeadLockThreadCount;
 import static com.amazonaws.metrics.internal.cloudwatch.MachineMetric.FreeMemory;
 import static com.amazonaws.metrics.internal.cloudwatch.MachineMetric.OpenFileDescriptorCount;
 import static com.amazonaws.metrics.internal.cloudwatch.MachineMetric.PeakThreadCount;
 import static com.amazonaws.metrics.internal.cloudwatch.MachineMetric.SpareFileDescriptorCount;
 import static com.amazonaws.metrics.internal.cloudwatch.MachineMetric.SpareMemory;
 import static com.amazonaws.metrics.internal.cloudwatch.MachineMetric.ThreadCount;
 import static com.amazonaws.metrics.internal.cloudwatch.MachineMetric.TotalMemory;
 import static com.amazonaws.metrics.internal.cloudwatch.MachineMetric.TotalStartedThreadCount;
 import static com.amazonaws.metrics.internal.cloudwatch.MachineMetric.UsedMemory;
 
 import java.util.List;
 import java.util.Set;
 
 
 
     private static final List<MachineMetricmemoryMetrics = Arrays.asList(
             );
     private static final List<MachineMetricthreadMetrics = Arrays.asList(
             ,
             );
     private static final List<MachineMetricfdMetrics = Arrays.asList(
     private final JmxInfoProvider jmxInfoProvider = JmxInfoProvider.Factory.getJmxInfoProvider();

    
Add the given list of metrics and corresponding values specified in "metricValues" to the given list of metric datum.

Parameters:
list list of metric data
metricValues list of metrics and their corresponding values
 
     private void addMetrics(List<MetricDatumlist,
             MetricValues metricValues,
             StandardUnit unit) {
         List<MachineMetricmachineMetrics = metricValues.getMetrics();
         List<Longvalues = metricValues.getValues();
         for (int i=0; i < machineMetrics.size(); i++) {
             MachineMetric metric = machineMetrics.get(i);
             long val = values.get(i).longValue();
             // skip zero values in some cases
             if (val != 0 || metric.includeZeroValue()) {
                 MetricDatum datum = new MetricDatum()
                     .withMetricName(metric.getMetricName())
                     .withDimensions(
                         new Dimension()
                         .withName(metric.getDimensionName())
                         .withValue(metric.name()))
                     .withUnit(unit)
                     .withValue((doubleval)
                     ;
                 list.add(datum);
             }
         }
     }

    
Returns the set of custom machine metrics specified in the SDK metrics registry; or an empty set if there is none. Note any machine metrics found in the registry must have been custom specified, as the default behavior is to include all machine metrics when enabled.

Returns:
a non-null set of machine metrics. An empty set means no custom machine metrics have been specified.
 
     private Set<MachineMetriccustomMachineMetrics() {
         Set<MachineMetriccustomized = new HashSet<MachineMetric>();
         for (MetricType m: AwsSdkMetrics.getPredefinedMetrics()) {
            if (m instanceof MachineMetric)
                customized.add((MachineMetric)m);
        }
        return customized;
    }

    
Returns a subset of the given list of metrics in "defaults" and the corresponding value of each returned metric in the subset. Note if the custom set is empty, the full set of default machine metrics and values will be returned. (In particular, as in set theory, a set is a subset of itself.)

Parameters:
customSet custom machine metrics specified in the SDK metrics registry
defaults the given default list of metrics
values corresponding values of each metric in "defaults"
    private MetricValues metricValues(Set<MachineMetriccustomSet,
            List<MachineMetricdefaultsList<Longvalues) {
        List<MachineMetricactualMetrics = defaults;
        List<LongactualValues = values;
        if (customSet.size() > 0) {
            // custom set of machine metrics specified
            actualMetrics = new ArrayList<MachineMetric>();
            actualValues = new ArrayList<Long>();
            for (int i=0; i < defaults.size(); i++) {
                MachineMetric mm = defaults.get(i);
                if (customSet.contains(mm)) {
                    actualMetrics.add(mm);
                    actualValues.add(values.get(i));
                }
            }
        }
        return new MetricValues(actualMetricsactualValues);
    }
        if (AwsSdkMetrics.isMachineMetricExcluded())
            return Collections.emptyList();
        Set<MachineMetriccustomSet = customMachineMetrics();
        List<MetricDatumtargetList = new ArrayList<MetricDatum>(
                MachineMetric.values().length);
        // Memory usage
        addMemoryMetrics(targetListcustomSet);
        // Thread related counts
        try {
            addThreadMetrics(targetListcustomSet);
        } catch (Throwable t) {
            LogFactory.getLog(getClass()).debug("Ignoring thread metrics"t);
        }
        // File descriptor usage
        try {
            addFileDescriptorMetrics(targetListcustomSet);
        } catch (Throwable t) {
            LogFactory.getLog(getClass()).debug("Ignoring file descriptor metrics"t);
        }
        return targetList;
    }
    private void addMemoryMetrics(List<MetricDatumtargetList,
            Set<MachineMetriccustomSet) {
        Runtime rt = Runtime.getRuntime();
        long totalMem = rt.totalMemory();
        long freeMem = rt.freeMemory();
        long usedMem = totalMem - freeMem;
        long spareMem = rt.maxMemory() - usedMem;
        List<Longvalues = Arrays.asList(totalMemfreeMemusedMemspareMem);
        MetricValues metricValues = memoryMetricValues(customSetvalues);
        addMetrics(targetListmetricValues.);
    }
    private void addFileDescriptorMetrics(List<MetricDatumtargetList,
            Set<MachineMetriccustomSet) {
        JmxInfoProvider provider = JmxInfoProvider.Factory.getJmxInfoProvider();
        long[] fdInfo = provider.getFileDecriptorInfo();
        if (fdInfo != null) {
            long openFdCount = fdInfo[0];
            long maxFdCount = fdInfo[1];
            List<Longvalues = Arrays.asList(openFdCountmaxFdCount - openFdCount);
            MetricValues metricValues = fdMetricValues(customSetvalues); 
            addMetrics(targetListmetricValues.);
        }
    }
    private void addThreadMetrics(List<MetricDatumtargetList,
            Set<MachineMetriccustomSet) {
        long threadCount = .getThreadCount();
        long[] ids = .findDeadlockedThreads();
        long deadLockThreadCount = ids == null ? 0 : ids.length;
        long daemonThreadCount = .getDaemonThreadCount();
        long peakThreadCount = .getPeakThreadCount();
        long totalStartedThreadCount = .getTotalStartedThreadCount();
        List<Longvalues = Arrays.asList(threadCount,
            deadLockThreadCount,
            daemonThreadCount,
            peakThreadCount,
            totalStartedThreadCount);
        MetricValues metricValues = threadMetricValues(customSetvalues); 
        addMetrics(targetListmetricValues.);
    }

    
Returns the set of memory metrics and the corresponding values based on the default and the customized set of metrics, if any.

Parameters:
customSet a non-null customized set of metrics
values a non-null list of values corresponding to the list of default memory metrics
    private MetricValues memoryMetricValues(Set<MachineMetriccustomSet,
            List<Longvalues) {
        return metricValues(customSet.,
                values);
    }

    
Returns the set of file-descriptor metrics and the corresponding values based on the default and the customized set of metrics, if any.

Parameters:
customSet a non-null customized set of metrics
values a non-null list of values corresponding to the list of default file-descriptor metrics
    private MetricValues fdMetricValues(Set<MachineMetriccustomSet,
            List<Longvalues) {
        return metricValues(customSet.values);
    }

    
Returns the set of thread metrics and the corresponding values based on the default and the customized set of metrics, if any.

Parameters:
customSet a non-null customized set of metrics
values a non-null list of values corresponding to the list of default thread metrics
    private MetricValues threadMetricValues(Set<MachineMetriccustomSet,
            List<Longvalues) {
        return metricValues(customSet.,
                values);
    }
    // Used to get around the limitation of Java returning at most a single value
    private static class MetricValues {
        private final List<MachineMetricmetrics;
        private final List<Longvalues;
        MetricValues(List<MachineMetricmetricsList<Longvalues) {
            this. = metrics;
            this. = values;
        }
        List<MachineMetricgetMetrics() { return ; }
        List<LonggetValues() { return ; }
    }
New to GrepCode? Check out our FAQ X