All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.engineblock.metrics.ChartReporter Maven / Gradle / Ivy

Go to download

The driver API for engineblock; Provides the interfaces needed to build drivers that can be loaded by engineblock core

There is a newer version: 2.12.65
Show newest version
package io.engineblock.metrics;

/*
 *
 * @author Sebastián Estévez on 10/25/18.
 *
 */


import com.codahale.metrics.*;
import com.codahale.metrics.Timer;
import com.mitchtalmadge.asciidata.graph.ASCIIGraph;

import java.util.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ChartReporter extends ScheduledReporter {

    Map> p99sOverTime = new HashMap<>();

    public ChartReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit) {
        super(registry, name, filter, rateUnit, durationUnit);
    }

    protected ChartReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, ScheduledExecutorService executor) {
        super(registry, name, filter, rateUnit, durationUnit, executor);
    }

    protected ChartReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, ScheduledExecutorService executor, boolean shutdownExecutorOnStop) {
        super(registry, name, filter, rateUnit, durationUnit, executor, shutdownExecutorOnStop);
    }

    protected ChartReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, ScheduledExecutorService executor, boolean shutdownExecutorOnStop, Set disabledMetricAttributes) {
        super(registry, name, filter, rateUnit, durationUnit, executor, shutdownExecutorOnStop, disabledMetricAttributes);
    }

    @Override
    public void report(SortedMap gauges, SortedMap counters, SortedMap histograms, SortedMap meters, SortedMap timers) {
        for (String timerKey : timers.keySet()) {
            Snapshot snapshot = timers.get(timerKey).getSnapshot();
            ArrayList p99s = p99sOverTime.get(timerKey);
            if (p99s == null){
                p99s = new ArrayList<>();
            }
            p99s.add(snapshot.get99thPercentile());
            p99sOverTime.put(timerKey,p99s);
        }
    }

    public void generateChart(){
        for (Map.Entry> p99KV : p99sOverTime.entrySet()) {
            System.out.println(String.format("Charting p99 Latencies (in microseconds) over time (one second intervals) for %s:",p99KV.getKey()));
            double[] p99s = p99KV.getValue().stream().mapToDouble(Double::doubleValue).toArray(); //via method reference
            System.out.println(ASCIIGraph
                    .fromSeries(p99s)
                    .withNumRows(8)
                    .plot());
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy