Example usage for org.apache.commons.math.stat.descriptive SynchronizedDescriptiveStatistics SynchronizedDescriptiveStatistics

List of usage examples for org.apache.commons.math.stat.descriptive SynchronizedDescriptiveStatistics SynchronizedDescriptiveStatistics

Introduction

In this page you can find the example usage for org.apache.commons.math.stat.descriptive SynchronizedDescriptiveStatistics SynchronizedDescriptiveStatistics.

Prototype

public SynchronizedDescriptiveStatistics(SynchronizedDescriptiveStatistics original) 

Source Link

Document

A copy constructor.

Usage

From source file:com.proofpoint.stats.TimedStat.java

public TimedStat(int windowSize) {
    timedStatistics = new SynchronizedDescriptiveStatistics(windowSize);
}

From source file:org.a3badran.platform.logging.writer.MetricsWriter.java

private void updateMetrics(RequestScope scope, String prefixName, long tt, long count, boolean updateCounters) {
    String name = Strings.isNullOrEmpty(prefixName) ? scope.getName() : prefixName + "." + scope.getName();

    String metricTotalCount = name + ".totalCount";
    scopeTotalMetrics.putIfAbsent(metricTotalCount, new AtomicLong(0));
    scopeTotalMetrics.get(metricTotalCount).addAndGet(count);

    String serviceTotalCount = appName + ".totalCount";
    appTotalMetrics.putIfAbsent(serviceTotalCount, new AtomicLong(0));
    appTotalMetrics.get(serviceTotalCount).addAndGet(count);

    if (!Strings.isNullOrEmpty(scope.getError())) {
        String metricErrorCount = name + ".errorCount";
        scopeTotalMetrics.putIfAbsent(metricErrorCount, new AtomicLong(0));
        scopeTotalMetrics.get(metricErrorCount).addAndGet(1);

        String serviceErrorCount = appName + ".errorCount";
        appTotalMetrics.putIfAbsent(serviceErrorCount, new AtomicLong(0));
        appTotalMetrics.get(serviceErrorCount).addAndGet(1);
    } else if (!Strings.isNullOrEmpty(scope.getWarninge())) {
        String metricWarningCount = name + ".warningCount";
        scopeTotalMetrics.putIfAbsent(metricWarningCount, new AtomicLong(0));
        scopeTotalMetrics.get(metricWarningCount).addAndGet(1);

        String serviceWarningCount = appName + ".warningCount";
        appTotalMetrics.putIfAbsent(serviceWarningCount, new AtomicLong(0));
        appTotalMetrics.get(serviceWarningCount).addAndGet(1);
    }// w  w  w. j  a va  2 s. c om

    String metricTotalTime = name + ".totalTime";
    scopeTotalMetrics.putIfAbsent(metricTotalTime, new AtomicLong(0));
    scopeTotalMetrics.get(metricTotalTime).addAndGet(tt);

    // sample data
    if (random.nextFloat() <= sampleRate) {
        sampleMetrics.putIfAbsent(name, new SynchronizedDescriptiveStatistics(sampleWindow));
        sampleMetrics.get(name).addValue(tt);

        // sample counters
        if (updateCounters == true && scope.getCounters() != null) {
            for (Map.Entry<String, AtomicLong> entry : scope.getCounters().entrySet()) {
                String counterName = String.format("%s.%s", name, entry.getKey());
                sampleCounterMetrics.putIfAbsent(counterName,
                        new SynchronizedDescriptiveStatistics(sampleWindow));
                sampleCounterMetrics.get(counterName).addValue(entry.getValue().doubleValue());
            }
        }
    }

}