Example usage for org.apache.commons.math3.random RandomDataImpl RandomDataImpl

List of usage examples for org.apache.commons.math3.random RandomDataImpl RandomDataImpl

Introduction

In this page you can find the example usage for org.apache.commons.math3.random RandomDataImpl RandomDataImpl.

Prototype

public RandomDataImpl() 

Source Link

Document

Construct a RandomDataImpl, using a default random generator as the source of randomness.

Usage

From source file:io.prometheus.client.examples.random.Main.java

public static void main(final String[] arguments) {
    Registry.defaultInitialize();
    final Server server = new Server(8181);
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);/*from w w w .j  a v a  2  s  .c om*/
    context.addServlet(new ServletHolder(new MetricsServlet()), "/");

    new Thread() {
        @Override
        public void run() {
            final RandomDataImpl randomData = new RandomDataImpl();

            try {
                while (true) {
                    rpcLatency.add(ImmutableMap.of("service", "foo"), randomData.nextLong(0, 200));
                    rpcLatency.add(ImmutableMap.of("service", "bar"), (float) randomData.nextGaussian(100, 20));
                    rpcLatency.add(ImmutableMap.of("service", "zed"), (float) randomData.nextExponential(100));
                    rpcCalls.increment(ImmutableMap.of("service", "foo"));
                    rpcCalls.increment(ImmutableMap.of("service", "bar"));
                    rpcCalls.increment(ImmutableMap.of("service", "zed"));
                    Thread.sleep(1000);
                }
            } catch (final InterruptedException e) {
            }
        }
    }.start();

    try {
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
}